Skip to content

Commit ed17059

Browse files
committed
BufferedZipStore auto closable
1 parent 52de5f4 commit ed17059

3 files changed

Lines changed: 17 additions & 24 deletions

File tree

src/main/java/dev/zarr/zarrjava/store/BufferedZipStore.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* A Store implementation that buffers reads and writes and flushes them to an underlying Store as a zip file.
2424
*/
25-
public class BufferedZipStore extends ZipStore {
25+
public class BufferedZipStore extends ZipStore implements AutoCloseable {
2626

2727
private final Store.ListableStore bufferStore;
2828
private final boolean flushOnWrite;
@@ -228,6 +228,11 @@ public void flush() throws IOException {
228228
writeBuffer();
229229
}
230230

231+
@Override
232+
public void close() throws IOException {
233+
flush();
234+
}
235+
231236
@Override
232237
public String getArchiveComment() {
233238
return archiveComment;

src/main/java/dev/zarr/zarrjava/store/S3Store.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,6 @@ public void delete(String[] keys) {
103103
.build());
104104
}
105105

106-
// @Override
107-
// public Stream<String[]> list(String[] keys) {
108-
// final String fullKey = resolveKeys(keys);
109-
// ListObjectsRequest req = ListObjectsRequest.builder()
110-
// .bucket(bucketName).prefix(fullKey)
111-
// .build();
112-
// ListObjectsResponse res = s3client.listObjects(req);
113-
// return res.contents().stream()
114-
// .map(S3Object::key)
115-
// .flatMap(key -> {
116-
// List<String> pathSegments = new ArrayList<>();
117-
// int index = fullKey.length();
118-
// while ((index = key.indexOf('/', index + 1)) != -1) {
119-
// pathSegments.add(key.substring(fullKey.length() + 1, index));
120-
// }
121-
// pathSegments.add(key.substring(fullKey.length() + 1));
122-
// return pathSegments.stream();
123-
// })
124-
// .distinct()
125-
// .map(s -> s.split("/"))
126-
// .filter(arr -> arr.length > 0);
127-
// }
128-
129106
@Override
130107
public Stream<String[]> list(String[] keys) {
131108
String fullPrefix = resolveKeys(keys);

src/test/java/dev/zarr/zarrjava/store/BufferedZipStoreTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public void testWriteZipStore(boolean flushOnWrite) throws ZarrException, IOExce
7272
assertIsTestGroupV3(Group.open(fsStore.resolve()), true);
7373
}
7474

75+
@Test
76+
public void testAutoCloseable() throws ZarrException, IOException {
77+
Path path = TESTOUTPUT.resolve("testAutoCloseable.zip");
78+
try (BufferedZipStore zipStore = new BufferedZipStore(path)) {
79+
writeTestGroupV3(zipStore.resolve(), true);
80+
}
81+
// After closing, it should be flushed
82+
BufferedZipStore zipStoreRead = new BufferedZipStore(path);
83+
assertIsTestGroupV3(Group.open(zipStoreRead.resolve()), true);
84+
}
85+
7586
@ParameterizedTest
7687
@CsvSource({"false", "true",})
7788
public void testZipStoreWithComment(boolean flushOnWrite) throws ZarrException, IOException {

0 commit comments

Comments
 (0)