/** * Writes a {@code TAG_Short} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeShortTagPayload(ShortTag tag) throws IOException { os.writeShort(tag.getValue()); }
/** * Writes a {@code TAG_Short} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeShortTagPayload(ShortTag tag) throws IOException { os.writeShort(tag.getValue()); }
/** * Writes a {@code TAG_Short} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeShortTagPayload(ShortTag tag) throws IOException { os.writeShort(tag.getValue()); }
/** * Writes a {@code TAG_String} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeStringTagPayload(StringTag tag) throws IOException { byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET.name()); os.writeShort(bytes.length); os.write(bytes); }
/** * Writes a {@code TAG_String} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeStringTagPayload(StringTag tag) throws IOException { byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET.name()); os.writeShort(bytes.length); os.write(bytes); }
/** * Writes a {@code TAG_String} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeStringTagPayload(StringTag tag) throws IOException { byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET.name()); os.writeShort(bytes.length); os.write(bytes); }
/** * Writes a {@code TAG_Short_Array} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeShortArrayTagPayload(ShortArrayTag tag) throws IOException { short[] shorts = tag.getValue(); os.writeInt(shorts.length); for (int i = 0; i < shorts.length; i++) { os.writeShort(shorts[i]); } }
/** * Writes a {@code TAG_Short_Array} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeShortArrayTagPayload(ShortArrayTag tag) throws IOException { short[] shorts = tag.getValue(); os.writeInt(shorts.length); for (int i = 0; i < shorts.length; i++) { os.writeShort(shorts[i]); } }
/** * Writes a {@code TAG_Short_Array} tag. * * @param tag The tag. * @throws java.io.IOException if an I/O error occurs. */ private void writeShortArrayTagPayload(ShortArrayTag tag) throws IOException { short[] shorts = tag.getValue(); os.writeInt(shorts.length); for (int i = 0; i < shorts.length; i++) { os.writeShort(shorts[i]); } }
/** * Writes a tag. * * @param tag The tag to write. * @throws java.io.IOException if an I/O error occurs. */ public void writeTag(Tag<?> tag) throws IOException { String name = tag.getName(); byte[] nameBytes = name.getBytes(NBTConstants.CHARSET.name()); os.writeByte(tag.getType().getId()); os.writeShort(nameBytes.length); os.write(nameBytes); if (tag.getType() == TagType.TAG_END) { throw new IOException("Named TAG_End not permitted."); } writeTagPayload(tag); }
/** * Writes a tag. * * @param tag The tag to write. * @throws java.io.IOException if an I/O error occurs. */ public void writeTag(Tag<?> tag) throws IOException { String name = tag.getName(); byte[] nameBytes = name.getBytes(NBTConstants.CHARSET.name()); os.writeByte(tag.getType().getId()); os.writeShort(nameBytes.length); os.write(nameBytes); if (tag.getType() == TagType.TAG_END) { throw new IOException("Named TAG_End not permitted."); } writeTagPayload(tag); }
/** * Writes a tag. * * @param tag The tag to write. * @throws java.io.IOException if an I/O error occurs. */ public void writeTag(Tag<?> tag) throws IOException { String name = tag.getName(); byte[] nameBytes = name.getBytes(NBTConstants.CHARSET.name()); os.writeByte(tag.getType().getId()); os.writeShort(nameBytes.length); os.write(nameBytes); if (tag.getType() == TagType.TAG_END) { throw new IOException("Named TAG_End not permitted."); } writeTagPayload(tag); }
@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()); } }