/** * Creates a new {@link NBTInputStream}, which sources its data from the specified input stream. A flag must be passed which indicates if the stream is compressed with GZIP or not. * * @param is The input stream. * @param compressed A flag indicating if the stream is compressed. * @param endianness Whether to read numbers from the InputStream with little endian encoding. * @throws java.io.IOException if an I/O error occurs. */ public NBTInputStream(InputStream is, boolean compressed, ByteOrder endianness) throws IOException { this.is = new EndianSwitchableInputStream(compressed ? new GZIPInputStream(is) : is, endianness); }
/** * Creates a new {@link NBTInputStream}, which sources its data from the specified input stream. A flag must be passed which indicates if the stream is compressed with GZIP or not. * * @param is The input stream. * @param compressed A flag indicating if the stream is compressed. * @param endianness Whether to read numbers from the InputStream with little endian encoding. * @throws java.io.IOException if an I/O error occurs. */ public NBTInputStream(InputStream is, boolean compressed, ByteOrder endianness) throws IOException { this.is = new EndianSwitchableInputStream(compressed ? new GZIPInputStream(is) : is, endianness); }
/** * Creates a new {@link NBTInputStream}, which sources its data from the specified input stream. A flag must be passed which indicates if the stream is compressed with GZIP or not. * * @param is The input stream. * @param compressed A flag indicating if the stream is compressed. * @param endianness Whether to read numbers from the InputStream with little endian encoding. * @throws java.io.IOException if an I/O error occurs. */ public NBTInputStream(InputStream is, boolean compressed, ByteOrder endianness) throws IOException { this.is = new EndianSwitchableInputStream(compressed ? new GZIPInputStream(is) : is, endianness); }
@Test public void testWriteLEUnsignedShort() throws IOException { int unsigned = Short.MAX_VALUE + 5; char testChar = 'b'; ByteArrayOutputStream rawOutput = new ByteArrayOutputStream(); EndianSwitchableOutputStream output = new EndianSwitchableOutputStream(rawOutput, ByteOrder.LITTLE_ENDIAN); output.writeShort(unsigned); output.writeChar(testChar); EndianSwitchableInputStream input = new EndianSwitchableInputStream(new ByteArrayInputStream(rawOutput.toByteArray()), ByteOrder.LITTLE_ENDIAN); assertEquals(unsigned, input.readUnsignedShort()); assertEquals(testChar, input.readChar()); } }