Skip to content

Commit 2648d38

Browse files
committed
Remove unnecessary flush()s, instead close OutputStream where it is constructed
1 parent 4db22cf commit 2648d38

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/main/java/org/janelia/saalfeldlab/n5/DefaultBlockWriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@ static <T> void writeBlock(
5757

5858
final DataBlockCodec<T> codec = datasetAttributes.getDataBlockCodec();
5959
codec.encode(dataBlock).writeTo(out);
60-
out.flush();
6160
}
6261
}

src/main/java/org/janelia/saalfeldlab/n5/GsonKeyValueN5Writer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package org.janelia.saalfeldlab.n5;
2727

2828
import java.io.IOException;
29+
import java.io.OutputStream;
2930
import java.io.UncheckedIOException;
3031
import java.util.Arrays;
3132
import java.util.List;
@@ -217,8 +218,11 @@ default <T> void writeBlock(
217218
final DataBlock<T> dataBlock) throws N5Exception {
218219

219220
final String blockPath = absoluteDataBlockPath(N5URI.normalizeGroupPath(path), dataBlock.getGridPosition());
220-
try (final LockedChannel lock = getKeyValueAccess().lockForWriting(blockPath)) {
221-
DefaultBlockWriter.writeBlock(lock.newOutputStream(), datasetAttributes, dataBlock);
221+
try (
222+
final LockedChannel lock = getKeyValueAccess().lockForWriting(blockPath);
223+
final OutputStream out = lock.newOutputStream()
224+
) {
225+
DefaultBlockWriter.writeBlock(out, datasetAttributes, dataBlock);
222226
} catch (final IOException | UncheckedIOException e) {
223227
throw new N5IOException(
224228
"Failed to write block " + Arrays.toString(dataBlock.getGridPosition()) + " into dataset " + path,

src/main/java/org/janelia/saalfeldlab/n5/codec/N5Codecs.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public ReadData encode(final DataBlock<T> dataBlock) throws IOException {
6666
return ReadData.from(out -> {
6767
new BlockHeader(dataBlock.getSize(), dataBlock.getNumElements()).writeTo(out);
6868
compression.encode(dataCodec.serialize(dataBlock.getData())).writeTo(out);
69-
out.flush();
7069
});
7170
}
7271

@@ -104,7 +103,6 @@ public ReadData encode(final DataBlock<String[]> dataBlock) throws IOException {
104103
final byte[] serializedData = flattenedArray.getBytes(ENCODING);
105104
new BlockHeader(dataBlock.getSize(), serializedData.length).writeTo(out);
106105
compression.encode(ReadData.from(serializedData)).writeTo(out);
107-
out.flush();
108106
});
109107
}
110108

@@ -137,7 +135,6 @@ public ReadData encode(final DataBlock<byte[]> dataBlock) throws IOException {
137135
return ReadData.from(out -> {
138136
new BlockHeader(null, dataBlock.getNumElements()).writeTo(out);
139137
compression.encode(ReadData.from(dataBlock.getData())).writeTo(out);
140-
out.flush();
141138
});
142139
}
143140

0 commit comments

Comments
 (0)