diff --git a/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedByteIndexedStorage.java b/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedByteIndexedStorage.java index 1ecc466e..b86b671f 100644 --- a/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedByteIndexedStorage.java +++ b/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedByteIndexedStorage.java @@ -50,22 +50,29 @@ public void put(K key, V value) { index.put(key, recordIndex); } - public void load(Iterable values, Function mapper) throws IOException { + public void load(Iterable values, Function mapper) { //make sure we start fresh if(this.storageFile.exists()) { this.storageFile.delete(); } - this.storage = new RandomAccessFile(storageFile, "rw"); - for(V value : values) { - put(mapper.apply(value), value); - } - this.storage.close(); - complete(); - } + try (RandomAccessFile storage = new RandomAccessFile(storageFile, "rw");) { + this.storage = storage; + for(V value : values) { + put(mapper.apply(value), value); + } + complete(); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } - public void open() throws FileNotFoundException { - this.storage = new RandomAccessFile(this.storageFile, "rwd"); - } + public void open() { + try { + this.storage = new RandomAccessFile(this.storageFile, "rwd"); + } catch (FileNotFoundException e) { + throw new UncheckedIOException(e); + } + } public void complete() { this.completed = true; diff --git a/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedJavaIndexedStorage.java b/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedJavaIndexedStorage.java index 26968729..d70c65a2 100644 --- a/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedJavaIndexedStorage.java +++ b/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedJavaIndexedStorage.java @@ -11,10 +11,11 @@ public FileBackedJavaIndexedStorage(Class keyClass, Class valueClass, File protected ByteArrayOutputStream writeObject(V value) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(out)); - oos.writeObject(value); - oos.flush(); - oos.close(); + try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(out); + ObjectOutputStream oos = new ObjectOutputStream(gzipOutputStream)) { + oos.writeObject(value); + oos.flush(); + } return out; } diff --git a/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedJsonIndexStorage.java b/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedJsonIndexStorage.java index affcf8fb..f93a206f 100644 --- a/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedJsonIndexStorage.java +++ b/common/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/storage/FileBackedJsonIndexStorage.java @@ -23,8 +23,8 @@ protected ByteArrayOutputStream writeObject(V value) throws IOException { } protected V readObject(byte[] buffer) { - try { - return objectMapper.readValue(new GZIPInputStream(new ByteArrayInputStream(buffer)), getTypeReference()); + try (GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(buffer))) { + return objectMapper.readValue(gzipInputStream, getTypeReference()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/FileBackedByteIndexedInfoStore.java b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/FileBackedByteIndexedInfoStore.java index 4fd4ae37..1fa62142 100644 --- a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/FileBackedByteIndexedInfoStore.java +++ b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/FileBackedByteIndexedInfoStore.java @@ -36,8 +36,8 @@ public List search(String term) { return new ArrayList(); }else { return allValues.keys().stream().filter((value)->{ - String lowerTerm = term.toLowerCase(); - return value.toLowerCase().contains(lowerTerm); + String lowerTerm = term.toLowerCase(Locale.ENGLISH); + return value.toLowerCase(Locale.ENGLISH).contains(lowerTerm); }).collect(Collectors.toList()); } } diff --git a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/InfoStore.java b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/InfoStore.java index a62e0591..46a11b88 100644 --- a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/InfoStore.java +++ b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/InfoStore.java @@ -3,6 +3,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap.KeySetView; import java.util.concurrent.ConcurrentSkipListSet; @@ -22,8 +23,8 @@ public List search(String term) { return new ArrayList(); }else { return allValues.keySet().stream().filter((value)->{ - String lowerTerm = term.toLowerCase(); - return value.toLowerCase().contains(lowerTerm); + String lowerTerm = term.toLowerCase(Locale.ENGLISH); + return value.toLowerCase(Locale.ENGLISH).contains(lowerTerm); }).collect(Collectors.toList()); } } diff --git a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantStore.java b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantStore.java index b62dd496..7ddd9a79 100644 --- a/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantStore.java +++ b/data/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/genotype/VariantStore.java @@ -44,15 +44,17 @@ public void setVariantSpecIndex(String[] variantSpecIndex) { } public static VariantStore readInstance(String genomicDataDirectory) throws IOException, ClassNotFoundException { - ObjectInputStream ois = new ObjectInputStream(new GZIPInputStream(new FileInputStream(genomicDataDirectory + VARIANT_STORE_JAVABIN_FILENAME))); - VariantStore variantStore = (VariantStore) ois.readObject(); - ois.close(); - variantStore.getVariantMaskStorage().values().forEach(store -> { - store.updateStorageDirectory(new File(genomicDataDirectory)); - }); - variantStore.open(); - variantStore.setVariantSpecIndex(loadVariantIndexFromFile(genomicDataDirectory)); - return variantStore; + try (GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(genomicDataDirectory + VARIANT_STORE_JAVABIN_FILENAME)); + ObjectInputStream ois = new ObjectInputStream(gzipInputStream)) { + VariantStore variantStore = (VariantStore) ois.readObject(); + ois.close(); + variantStore.getVariantMaskStorage().values().forEach(store -> { + store.updateStorageDirectory(new File(genomicDataDirectory)); + }); + variantStore.open(); + variantStore.setVariantSpecIndex(loadVariantIndexFromFile(genomicDataDirectory)); + return variantStore; + } } public void writeInstance(String genomicDirectory) { @@ -125,11 +127,7 @@ public List getMasksForDbSnpSpec(String variant) { public void open() { variantMaskStorage.values().stream().forEach((fbbis -> { if (fbbis != null) { - try { - fbbis.open(); - } catch (FileNotFoundException e) { - throw new UncheckedIOException(e); - } + fbbis.open(); } })); } diff --git a/etl/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/etl/phenotype/SequentialLoader.java b/etl/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/etl/phenotype/SequentialLoader.java index 8fbf5fc6..a2e970e9 100644 --- a/etl/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/etl/phenotype/SequentialLoader.java +++ b/etl/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/etl/phenotype/SequentialLoader.java @@ -75,9 +75,9 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio //load each into observation store for(String filename : inputFiles) { log.info("Loading file " + filename); - if(filename.toLowerCase().endsWith("sql")) { + if(filename.toLowerCase(Locale.ENGLISH).endsWith("sql")) { loadSqlFile(filename); - } else if(filename.toLowerCase().endsWith("csv")){ + } else if(filename.toLowerCase(Locale.ENGLISH).endsWith("csv")){ loadCsvFile(filename); } } diff --git a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/AbstractProcessor.java b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/AbstractProcessor.java index 88e80165..814d7caf 100644 --- a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/AbstractProcessor.java +++ b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/AbstractProcessor.java @@ -336,10 +336,9 @@ public PhenoCube load(String key) throws Exception { byte[] buffer = new byte[length]; allObservationsStore.read(buffer); allObservationsStore.close(); - ObjectInputStream inStream = new ObjectInputStream(new ByteArrayInputStream(Crypto.decryptData(buffer))); - PhenoCube ret = (PhenoCube)inStream.readObject(); - inStream.close(); - return ret; + try (ObjectInputStream inStream = new ObjectInputStream(new ByteArrayInputStream(Crypto.decryptData(buffer)))) { + return (PhenoCube)inStream.readObject(); + } }else { log.warn("ColumnMeta not found for : [{}]", key); return null; diff --git a/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java b/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java index c58705f3..ce0f2fdc 100644 --- a/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java +++ b/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java @@ -143,8 +143,8 @@ public SearchResults search(@RequestBody QueryRequest searchJson) { // Phenotype Values Object phenotypeResults = searchJson.getQuery() != null ? allColumns.stream().filter((entry) -> { - String lowerCaseSearchTerm = searchJson.getQuery().toString().toLowerCase(); - return entry.getKey().toLowerCase().contains(lowerCaseSearchTerm) + String lowerCaseSearchTerm = searchJson.getQuery().toString().toLowerCase(Locale.ENGLISH); + return entry.getKey().toLowerCase(Locale.ENGLISH).contains(lowerCaseSearchTerm) || (entry.getValue().isCategorical() && entry.getValue().getCategoryValues().stream() .map(String::toLowerCase).collect(Collectors.toList()).contains(lowerCaseSearchTerm)); }).collect(Collectors.toMap(Entry::getKey, Entry::getValue)) : allColumns; @@ -154,10 +154,10 @@ public SearchResults search(@RequestBody QueryRequest searchJson) { abstractProcessor.getInfoStoreMeta().stream().forEach(infoColumnMeta -> { //FileBackedByteIndexedInfoStore store = abstractProcessor.getInfoStore(infoColumn); String query = searchJson.getQuery().toString(); - String lowerCase = query.toLowerCase(); + String lowerCase = query.toLowerCase(Locale.ENGLISH); boolean storeIsNumeric = infoColumnMeta.continuous(); - if (infoColumnMeta.description().toLowerCase().contains(lowerCase) - || infoColumnMeta.key().toLowerCase().contains(lowerCase)) { + if (infoColumnMeta.description().toLowerCase(Locale.ENGLISH).contains(lowerCase) + || infoColumnMeta.key().toLowerCase(Locale.ENGLISH).contains(lowerCase)) { infoResults.put(infoColumnMeta.key(), ImmutableMap.of("description", infoColumnMeta.description(), "values", storeIsNumeric ? new ArrayList() : abstractProcessor.searchInfoConceptValues(infoColumnMeta.key(), ""), "continuous", diff --git a/service/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/test/util/BuildIntegrationTestEnvironment.java b/service/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/test/util/BuildIntegrationTestEnvironment.java index f713ec0a..4b91cece 100644 --- a/service/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/test/util/BuildIntegrationTestEnvironment.java +++ b/service/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/test/util/BuildIntegrationTestEnvironment.java @@ -25,9 +25,7 @@ public enum BuildIntegrationTestEnvironment { VariantMetadataLoader.main(new String[] {"./src/test/resources/test_vcfIndex.tsv", binFile, "target/VariantMetadataStorage.bin"}); VariantStore variantStore = VariantStore.readInstance(STORAGE_DIR); BucketIndexBySample bucketIndexBySample = new BucketIndexBySample(variantStore, STORAGE_DIR); - } catch (IOException e) { - throw new RuntimeException(e); - } catch (ClassNotFoundException e) { + } catch (IOException | ClassNotFoundException e) { throw new RuntimeException(e); }