2 more try-with-resources (buffered + close)

Signed-off-by: Alex Black <blacka101@gmail.com>
master
Alex Black 2020-03-31 11:38:12 +11:00
parent 3f49d646fc
commit e3a8629214
1 changed files with 5 additions and 5 deletions

View File

@ -415,7 +415,9 @@ public class ModelSerializer {
*/ */
public static Pair<MultiLayerNetwork, Normalizer> restoreMultiLayerNetworkAndNormalizer(@NonNull File file, boolean loadUpdater) public static Pair<MultiLayerNetwork, Normalizer> restoreMultiLayerNetworkAndNormalizer(@NonNull File file, boolean loadUpdater)
throws IOException { throws IOException {
return restoreMultiLayerNetworkAndNormalizer(new FileInputStream(file), loadUpdater); try(InputStream is = new BufferedInputStream(new FileInputStream(file))){
return restoreMultiLayerNetworkAndNormalizer(is, loadUpdater);
}
} }
/** /**
@ -876,8 +878,8 @@ public class ModelSerializer {
* @return * @return
*/ */
public static <T extends Normalizer> T restoreNormalizerFromFile(File file) throws IOException { public static <T extends Normalizer> T restoreNormalizerFromFile(File file) throws IOException {
try { try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
return restoreNormalizerFromInputStream(new FileInputStream(file)); return restoreNormalizerFromInputStream(is);
} catch (Exception e) { } catch (Exception e) {
log.warn("Error while restoring normalizer, trying to restore assuming deprecated format..."); log.warn("Error while restoring normalizer, trying to restore assuming deprecated format...");
DataNormalization restoredDeprecated = restoreNormalizerFromInputStreamDeprecated(new FileInputStream(file)); DataNormalization restoredDeprecated = restoreNormalizerFromInputStreamDeprecated(new FileInputStream(file));
@ -918,8 +920,6 @@ public class ModelSerializer {
* *
* This method restores normalizer from a given persisted model file serialized with Java object serialization * This method restores normalizer from a given persisted model file serialized with Java object serialization
* *
* @param file
* @return
*/ */
private static DataNormalization restoreNormalizerFromInputStreamDeprecated(InputStream stream) { private static DataNormalization restoreNormalizerFromInputStreamDeprecated(InputStream stream) {
try { try {