Skip to content

Commit fd25ec3

Browse files
committed
move BytesBytesCodec.copy to Utils.copyStream
1 parent 8ba6946 commit fd25ec3

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/main/java/dev/zarr/zarrjava/core/codec/BytesBytesCodec.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,4 @@ public abstract class BytesBytesCodec extends AbstractCodec {
1313

1414
public abstract ByteBuffer decode(ByteBuffer chunkBytes) throws ZarrException;
1515

16-
protected void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
17-
byte[] buffer = new byte[4096];
18-
int len;
19-
while ((len = inputStream.read(buffer)) > 0) {
20-
outputStream.write(buffer, 0, len);
21-
}
22-
}
2316
}

src/main/java/dev/zarr/zarrjava/utils/Utils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.ByteArrayOutputStream;
44
import java.io.IOException;
55
import java.io.InputStream;
6+
import java.io.OutputStream;
67
import java.nio.ByteBuffer;
78
import java.nio.ByteOrder;
89
import java.util.Arrays;
@@ -78,6 +79,15 @@ public static <T> T[] concatArrays(T[] array1, T[]... arrays) {
7879
return result;
7980
}
8081

82+
public static void copyStream(InputStream inputStream, OutputStream outputStream) throws IOException {
83+
byte[] buffer = new byte[4096];
84+
int len;
85+
while ((len = inputStream.read(buffer)) > 0) {
86+
outputStream.write(buffer, 0, len);
87+
}
88+
}
89+
90+
8191
public static boolean isPermutation(int[] array) {
8292
if (array.length==0){
8393
return false;

src/main/java/dev/zarr/zarrjava/v2/codec/core/ZlibCodec.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import dev.zarr.zarrjava.ZarrException;
66
import dev.zarr.zarrjava.utils.Utils;
77
import dev.zarr.zarrjava.v2.codec.Codec;
8-
import dev.zarr.zarrjava.core.ArrayMetadata;
98
import dev.zarr.zarrjava.core.codec.BytesBytesCodec;
109

1110
import java.io.ByteArrayInputStream;
@@ -34,7 +33,7 @@ public ZlibCodec(
3433
public ByteBuffer decode(ByteBuffer chunkBytes) throws ZarrException {
3534
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); InflaterInputStream inputStream = new InflaterInputStream(
3635
new ByteArrayInputStream(Utils.toArray(chunkBytes)))) {
37-
copy(inputStream, outputStream);
36+
Utils.copyStream(inputStream, outputStream);
3837
inputStream.close();
3938
return ByteBuffer.wrap(outputStream.toByteArray());
4039
} catch (IOException ex) {

src/main/java/dev/zarr/zarrjava/v3/codec/core/GzipCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ByteBuffer decode(ByteBuffer chunkBytes)
3434
throws ZarrException {
3535
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); GZIPInputStream inputStream = new GZIPInputStream(
3636
new ByteArrayInputStream(Utils.toArray(chunkBytes)))) {
37-
copy(inputStream, outputStream);
37+
Utils.copyStream(inputStream, outputStream);
3838
inputStream.close();
3939
return ByteBuffer.wrap(outputStream.toByteArray());
4040
} catch (IOException ex) {

0 commit comments

Comments
 (0)