1919import org .janelia .saalfeldlab .n5 .StringDataBlock ;
2020import org .janelia .saalfeldlab .n5 .readdata .ReadData ;
2121
22- import static org .janelia .saalfeldlab .n5 .codec .N5Codecs .ChunkHeader .MODE_DEFAULT ;
23- import static org .janelia .saalfeldlab .n5 .codec .N5Codecs .ChunkHeader .MODE_OBJECT ;
24- import static org .janelia .saalfeldlab .n5 .codec .N5Codecs .ChunkHeader .MODE_VARLENGTH ;
22+ import static org .janelia .saalfeldlab .n5 .codec .N5Codecs .BlockHeader .MODE_DEFAULT ;
23+ import static org .janelia .saalfeldlab .n5 .codec .N5Codecs .BlockHeader .MODE_OBJECT ;
24+ import static org .janelia .saalfeldlab .n5 .codec .N5Codecs .BlockHeader .MODE_VARLENGTH ;
2525
2626public class N5Codecs {
2727
@@ -64,7 +64,7 @@ static class DefaultDataBlockCodec<T> implements DataBlockCodec<T> {
6464 @ Override
6565 public ReadData encode (final DataBlock <T > dataBlock ) throws IOException {
6666 return ReadData .from (out -> {
67- new ChunkHeader (dataBlock .getSize (), dataBlock .getNumElements ()).writeTo (out );
67+ new BlockHeader (dataBlock .getSize (), dataBlock .getNumElements ()).writeTo (out );
6868 compression .encode (dataCodec .serialize (dataBlock .getData ())).writeTo (out );
6969 out .flush ();
7070 });
@@ -73,7 +73,7 @@ public ReadData encode(final DataBlock<T> dataBlock) throws IOException {
7373 @ Override
7474 public DataBlock <T > decode (final ReadData readData , final long [] gridPosition ) throws IOException {
7575 try (final InputStream in = readData .inputStream ()) {
76- final ChunkHeader header = ChunkHeader .readFrom (in , MODE_DEFAULT , MODE_VARLENGTH );
76+ final BlockHeader header = BlockHeader .readFrom (in , MODE_DEFAULT , MODE_VARLENGTH );
7777 final T data = dataCodec .createData (header .numElements ());
7878 final int numBytes = header .numElements () * dataCodec .bytesPerElement ();
7979 final ReadData decompressed = compression .decode (ReadData .from (in ), numBytes );
@@ -102,7 +102,7 @@ public ReadData encode(final DataBlock<String[]> dataBlock) throws IOException {
102102 return ReadData .from (out -> {
103103 final String flattenedArray = String .join (NULLCHAR , dataBlock .getData ()) + NULLCHAR ;
104104 final byte [] serializedData = flattenedArray .getBytes (ENCODING );
105- new ChunkHeader (dataBlock .getSize (), serializedData .length ).writeTo (out );
105+ new BlockHeader (dataBlock .getSize (), serializedData .length ).writeTo (out );
106106 compression .encode (ReadData .from (serializedData )).writeTo (out );
107107 out .flush ();
108108 });
@@ -111,7 +111,7 @@ public ReadData encode(final DataBlock<String[]> dataBlock) throws IOException {
111111 @ Override
112112 public DataBlock <String []> decode (final ReadData readData , final long [] gridPosition ) throws IOException {
113113 try (final InputStream in = readData .inputStream ()) {
114- final ChunkHeader header = ChunkHeader .readFrom (in , MODE_DEFAULT , MODE_VARLENGTH );
114+ final BlockHeader header = BlockHeader .readFrom (in , MODE_DEFAULT , MODE_VARLENGTH );
115115 final ReadData decompressed = compression .decode (ReadData .from (in ), header .numElements ());
116116 final byte [] serializedData = decompressed .allBytes ();
117117 final String rawChars = new String (serializedData , ENCODING );
@@ -135,7 +135,7 @@ static class ObjectDataBlockCodec implements DataBlockCodec<byte[]> {
135135 @ Override
136136 public ReadData encode (final DataBlock <byte []> dataBlock ) throws IOException {
137137 return ReadData .from (out -> {
138- new ChunkHeader (null , dataBlock .getNumElements ()).writeTo (out );
138+ new BlockHeader (null , dataBlock .getNumElements ()).writeTo (out );
139139 compression .encode (ReadData .from (dataBlock .getData ())).writeTo (out );
140140 out .flush ();
141141 });
@@ -144,7 +144,7 @@ public ReadData encode(final DataBlock<byte[]> dataBlock) throws IOException {
144144 @ Override
145145 public DataBlock <byte []> decode (final ReadData readData , final long [] gridPosition ) throws IOException {
146146 try (final InputStream in = readData .inputStream ()) {
147- final ChunkHeader header = ChunkHeader .readFrom (in , MODE_OBJECT );
147+ final BlockHeader header = BlockHeader .readFrom (in , MODE_OBJECT );
148148 final byte [] data = new byte [header .numElements ()];
149149 final ReadData decompressed = compression .decode (ReadData .from (in ), data .length );
150150 new DataInputStream (decompressed .inputStream ()).readFully (data );
@@ -153,7 +153,7 @@ public DataBlock<byte[]> decode(final ReadData readData, final long[] gridPositi
153153 }
154154 }
155155
156- static class ChunkHeader {
156+ static class BlockHeader {
157157
158158 public static final short MODE_DEFAULT = 0 ;
159159 public static final short MODE_VARLENGTH = 1 ;
@@ -163,13 +163,13 @@ static class ChunkHeader {
163163 private final int [] blockSize ;
164164 private final int numElements ;
165165
166- ChunkHeader (final short mode , final int [] blockSize , final int numElements ) {
166+ BlockHeader (final short mode , final int [] blockSize , final int numElements ) {
167167 this .mode = mode ;
168168 this .blockSize = blockSize ;
169169 this .numElements = numElements ;
170170 }
171171
172- ChunkHeader (final int [] blockSize , final int numElements ) {
172+ BlockHeader (final int [] blockSize , final int numElements ) {
173173 if (blockSize == null ) {
174174 this .mode = MODE_OBJECT ;
175175 } else if (DataBlock .getNumElements (blockSize ) == numElements ) {
@@ -227,11 +227,11 @@ void writeTo(final OutputStream out) throws IOException {
227227 dos .flush ();
228228 }
229229
230- static ChunkHeader readFrom (final InputStream in ) throws IOException {
230+ static BlockHeader readFrom (final InputStream in ) throws IOException {
231231 return readFrom (in , null );
232232 }
233233
234- static ChunkHeader readFrom (final InputStream in , short ... allowedModes ) throws IOException {
234+ static BlockHeader readFrom (final InputStream in , short ... allowedModes ) throws IOException {
235235 final DataInputStream dis = new DataInputStream (in );
236236 final short mode = dis .readShort ();
237237 final int [] blockSize ;
@@ -262,7 +262,7 @@ static ChunkHeader readFrom(final InputStream in, short... allowedModes) throws
262262 throw new IOException ("unexpected mode: " + mode );
263263 }
264264
265- return new ChunkHeader (mode , blockSize , numElements );
265+ return new BlockHeader (mode , blockSize , numElements );
266266 }
267267 }
268268}
0 commit comments