LittleEndianDataOutputStream extends FilterOutputStream implements DataOutput { @Override public void writeShort(int v) throws IOException { out.write(0xFF & v); out.write(0xFF & (v >> 8)); } LittleEndianDataOutputStream(OutputStream out); @Override void write(byte[] b, int off, int len); @Override void writeBoolean(boolean v); @Override void writeByte(int v); @Override void writeShort(int v); @Override void writeChar(int v); @Override void writeInt(int v); @Override void writeLong(long v); @Override void writeFloat(float v); @Override void writeDouble(double v); @Override void writeBytes(String s); @Override void writeChars(String s); @Override void writeUTF(String str); @Override void close();  }
@Test public void testWriteShort() throws IOException { final short value = (short) 256; final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); final LittleEndianDataOutputStream littleEndianOut = new LittleEndianDataOutputStream(byteOut); littleEndianOut.writeShort(value); littleEndianOut.close(); final byte[] expected = ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN).putShort(value).array(); assertTrue(Arrays.equals(expected, byteOut.toByteArray())); }