|
22 | 22 |
|
23 | 23 | public class NbtUtils { |
24 | 24 | public static final int MAX_DEPTH = 16; |
| 25 | + public static final long MAX_READ_SIZE = 0; // Disabled by default |
25 | 26 |
|
26 | 27 | private NbtUtils() { |
27 | 28 | } |
28 | 29 |
|
29 | 30 | public static NBTInputStream createReader(InputStream stream, boolean internKeys, boolean internValues) { |
| 31 | + return createReader(stream, internKeys, internValues, MAX_READ_SIZE); |
| 32 | + } |
| 33 | + |
| 34 | + public static NBTInputStream createReader(InputStream stream, boolean internKeys, boolean internValues, long maxReadSize) { |
30 | 35 | requireNonNull(stream, "stream"); |
31 | | - return new NBTInputStream(new DataInputStream(stream), internKeys, internValues); |
| 36 | + return new NBTInputStream(new DataInputStream(stream), internKeys, internValues, maxReadSize); |
32 | 37 | } |
33 | 38 |
|
34 | 39 | public static NBTInputStream createReaderLE(InputStream stream, boolean internKeys, boolean internValues) { |
| 40 | + return createReaderLE(stream, internKeys, internValues, MAX_READ_SIZE); |
| 41 | + } |
| 42 | + |
| 43 | + public static NBTInputStream createReaderLE(InputStream stream, boolean internKeys, boolean internValues, long maxReadSize) { |
35 | 44 | requireNonNull(stream, "stream"); |
36 | | - return new NBTInputStream(new LittleEndianDataInputStream(stream), internKeys, internValues); |
| 45 | + return new NBTInputStream(new LittleEndianDataInputStream(stream, maxReadSize), internKeys, internValues); |
37 | 46 | } |
38 | 47 |
|
39 | 48 | public static NBTInputStream createGZIPReader(InputStream stream, boolean internKeys, boolean internValues) throws IOException { |
40 | | - return createReader(new GZIPInputStream(stream), internKeys, internValues); |
| 49 | + return createGZIPReader(stream, internKeys, internValues, MAX_READ_SIZE); |
| 50 | + } |
| 51 | + |
| 52 | + public static NBTInputStream createGZIPReader(InputStream stream, boolean internKeys, boolean internValues, long maxReadSize) throws IOException { |
| 53 | + return createReader(new GZIPInputStream(stream), internKeys, internValues, maxReadSize); |
41 | 54 | } |
42 | 55 |
|
43 | 56 | public static NBTInputStream createNetworkReader(InputStream stream, boolean internKeys, boolean internValues) { |
| 57 | + return createNetworkReader(stream, internKeys, internValues, MAX_READ_SIZE); |
| 58 | + } |
| 59 | + |
| 60 | + public static NBTInputStream createNetworkReader(InputStream stream, boolean internKeys, boolean internValues, long maxReadSize) { |
44 | 61 | requireNonNull(stream, "stream"); |
45 | | - return new NBTInputStream(new NetworkDataInputStream(stream), internKeys, internValues); |
| 62 | + return new NBTInputStream(new NetworkDataInputStream(stream, maxReadSize), internKeys, internValues); |
46 | 63 | } |
47 | 64 |
|
48 | 65 | public static NBTInputStream createReader(InputStream stream) { |
49 | | - return createReader(stream, false, false); |
| 66 | + return createReader(stream, MAX_READ_SIZE); |
| 67 | + } |
| 68 | + |
| 69 | + public static NBTInputStream createReader(InputStream stream, long maxReadSize) { |
| 70 | + return createReader(stream, false, false, maxReadSize); |
50 | 71 | } |
51 | 72 |
|
52 | 73 | public static NBTInputStream createReaderLE(InputStream stream) { |
53 | | - return createReaderLE(stream, false, false); |
| 74 | + return createReaderLE(stream, MAX_READ_SIZE); |
| 75 | + } |
| 76 | + |
| 77 | + public static NBTInputStream createReaderLE(InputStream stream, long maxReadSize) { |
| 78 | + return createReaderLE(stream, false, false, maxReadSize); |
54 | 79 | } |
55 | 80 |
|
56 | 81 | public static NBTInputStream createGZIPReader(InputStream stream) throws IOException { |
57 | | - return createGZIPReader(stream, false, false); |
| 82 | + return createGZIPReader(stream, MAX_READ_SIZE); |
| 83 | + } |
| 84 | + |
| 85 | + public static NBTInputStream createGZIPReader(InputStream stream, long maxReadSize) throws IOException { |
| 86 | + return createGZIPReader(stream, false, false, maxReadSize); |
58 | 87 | } |
59 | 88 |
|
60 | 89 | public static NBTInputStream createNetworkReader(InputStream stream) { |
61 | | - return createNetworkReader(stream, false, false); |
| 90 | + return createNetworkReader(stream, MAX_READ_SIZE); |
| 91 | + } |
| 92 | + |
| 93 | + public static NBTInputStream createNetworkReader(InputStream stream, long maxReadSize) { |
| 94 | + return createNetworkReader(stream, false, false, maxReadSize); |
62 | 95 | } |
63 | 96 |
|
64 | 97 | public static NBTOutputStream createWriter(OutputStream stream) { |
|
0 commit comments