Skip to content

Commit 83a6add

Browse files
committed
Create no-op byte data impl
1 parent 620c84d commit 83a6add

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

src/main/java/software/coley/lljzip/util/ByteDataUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ public static byte[] readArray(ByteData data, int start, int len) {
298298
*/
299299
public static ByteBuffer sliceExact(ByteBuffer data, int start, int end) {
300300
ByteBuffer slice = data.slice();
301-
slice = ((ByteBuffer) ((Buffer)slice).position(start)).slice();
302-
((Buffer)slice).limit(end - start);
301+
slice = ((ByteBuffer) ((Buffer) slice).position(start)).slice();
302+
((Buffer) slice).limit(end - start);
303303
return slice.order(data.order());
304304
}
305305

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package software.coley.lljzip.util;
2+
3+
import java.io.OutputStream;
4+
5+
/**
6+
* Empty file that yields {@code 0} for everything.
7+
*
8+
* @author Matt Coley
9+
*/
10+
public class NoopByteData implements ByteData {
11+
/**
12+
* Shared instance.
13+
*/
14+
public static final NoopByteData INSTANCE = new NoopByteData();
15+
16+
private NoopByteData() {
17+
// deny construction
18+
}
19+
20+
@Override
21+
public boolean isClosed() {
22+
return false;
23+
}
24+
25+
@Override
26+
public int getInt(long position) {
27+
return 0;
28+
}
29+
30+
@Override
31+
public long getLong(long position) {
32+
return 0;
33+
}
34+
35+
@Override
36+
public short getShort(long position) {
37+
return 0;
38+
}
39+
40+
@Override
41+
public byte get(long position) {
42+
return 0;
43+
}
44+
45+
@Override
46+
public void get(long position, byte[] buffer, int off, int len) {
47+
}
48+
49+
@Override
50+
public void transferTo(OutputStream out, byte[] buffer) {
51+
}
52+
53+
@Override
54+
public ByteData slice(long startIndex, long endIndex) {
55+
return this;
56+
}
57+
58+
@Override
59+
public long length() {
60+
return 0;
61+
}
62+
63+
@Override
64+
public void close() {
65+
}
66+
}

0 commit comments

Comments
 (0)