Skip to content

Commit 338f269

Browse files
close resources
1 parent 13edaf4 commit 338f269

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/main/java/ru/r2cloud/satellite/ObservationDao.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ private List<Observation> loadFromDisk(String satelliteId) {
111111
return Collections.emptyList();
112112
}
113113
List<Path> observations;
114-
try {
115-
observations = Util.toList(Files.newDirectoryStream(dataRoot));
114+
try (DirectoryStream<Path> ds = Files.newDirectoryStream(dataRoot)) {
115+
observations = Util.toList(ds);
116116
} catch (IOException e) {
117117
LOG.error("unable to load observations", e);
118118
return Collections.emptyList();
@@ -230,7 +230,7 @@ private static List<Path> resolveMultipleByPrefix(Path baseDir, String prefix) {
230230
result.add(cur.toPath());
231231
}
232232
}
233-
//FIXME sort by name
233+
// FIXME sort by name
234234
return result;
235235
}
236236

src/test/java/ru/r2cloud/satellite/TimeSizeRetentionTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.File;
88
import java.io.FileOutputStream;
99
import java.io.IOException;
10+
import java.nio.file.DirectoryStream;
1011
import java.nio.file.Files;
1112
import java.nio.file.Path;
1213
import java.util.List;
@@ -113,7 +114,10 @@ public void testUpdateFolderContents() throws Exception {
113114
}
114115

115116
private static Path getObservationFolder(Path satelliteFolder) throws Exception {
116-
List<Path> observations = Util.toList(Files.newDirectoryStream(satelliteFolder.resolve("data")));
117+
List<Path> observations;
118+
try (DirectoryStream<Path> ds = Files.newDirectoryStream(satelliteFolder.resolve("data"))) {
119+
observations = Util.toList(ds);
120+
}
117121
assertEquals(1, observations.size());
118122
return observations.get(0);
119123
}
@@ -124,8 +128,8 @@ private static void assertFolder(boolean expectedFolder, Path folder) {
124128

125129
private static void assertFolder(boolean expectedFolder, boolean expectedRaw, boolean expectedData, Path folder) {
126130
List<Path> observations;
127-
try {
128-
observations = Util.toList(Files.newDirectoryStream(folder.resolve("data")));
131+
try (DirectoryStream<Path> ds = Files.newDirectoryStream(folder.resolve("data"))) {
132+
observations = Util.toList(ds);
129133
} catch (IOException e) {
130134
e.printStackTrace();
131135
fail("unable to get list of directories " + e.getMessage());

0 commit comments

Comments
 (0)