/** * Creates a new {@link NBTOutputStream}, which will write data to the specified underlying output stream. A flag indicates if the output should be compressed with GZIP or not. * * @param os The output stream. * @param compressed A flag that indicates if the output should be compressed. * @param endianness A flag that indicates if numbers in the output should be output in little-endian format. * @throws java.io.IOException if an I/O error occurs. */ public NBTOutputStream(OutputStream os, boolean compressed, ByteOrder endianness) throws IOException { this.os = new EndianSwitchableOutputStream(compressed ? new GZIPOutputStream(os) : os, endianness); }
/** * Creates a new {@link NBTOutputStream}, which will write data to the specified underlying output stream. A flag indicates if the output should be compressed with GZIP or not. * * @param os The output stream. * @param compressed A flag that indicates if the output should be compressed. * @param endianness A flag that indicates if numbers in the output should be output in little-endian format. * @throws java.io.IOException if an I/O error occurs. */ public NBTOutputStream(OutputStream os, boolean compressed, ByteOrder endianness) throws IOException { this.os = new EndianSwitchableOutputStream(compressed ? new GZIPOutputStream(os) : os, endianness); }
/** * Creates a new {@link NBTOutputStream}, which will write data to the specified underlying output stream. A flag indicates if the output should be compressed with GZIP or not. * * @param os The output stream. * @param compressed A flag that indicates if the output should be compressed. * @param endianness A flag that indicates if numbers in the output should be output in little-endian format. * @throws java.io.IOException if an I/O error occurs. */ public NBTOutputStream(OutputStream os, boolean compressed, ByteOrder endianness) throws IOException { this.os = new EndianSwitchableOutputStream(compressed ? new GZIPOutputStream(os) : os, 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()); } }