JBBPBitOutputStream extends FilterOutputStream implements JBBPCountableBitStream { public void writeString(final String value, final JBBPByteOrder order) throws IOException { if (value == null) { this.write(0xFF); } else if (value.length() == 0) { this.write(0); } else { final byte[] array = JBBPUtils.strToUtf8(value); final int len = array.length; if (len < 0x80) { this.write(len); } else if ((len & 0xFFFFFF00) == 0) { this.write(0x81); this.write(len); } else if ((len & 0xFFFF0000) == 0) { this.write(0x82); this.writeShort(len, order); } else if ((len & 0xFF000000) == 0) { this.write(0x83); if (order == JBBPByteOrder.BIG_ENDIAN) { this.write(len >>> 16); this.write(len >>> 8); this.write(len); } else { this.write(len); this.write(len >>> 8); this.write(len >>> 16); } } else { this.write(0x84); this.writeInt(len, order); } this.write(array); } } JBBPBitOutputStream(final OutputStream out);  JBBPBitOutputStream(final OutputStream out, final JBBPBitOrder order); @Override JBBPBitOrder getBitOrder(); void writeShort(final int value, final JBBPByteOrder byteOrder); void writeInt(final int value, final JBBPByteOrder byteOrder); void writeFloat(final float value, final JBBPByteOrder byteOrder); void writeLong(final long value, final JBBPByteOrder byteOrder); void writeDouble(final double value, final JBBPByteOrder byteOrder); @Override long getCounter(); @Override int getBitBuffer(); @Override int getBufferedBitsNumber(); @Override void flush(); @SuppressWarnings("NullableProblems") @Override void write(final byte[] b, final int off, final int len); @SuppressWarnings("NullableProblems") @Override void write(final byte[] b); void writeBits(final int value, final JBBPBitNumber bitNumber); void align(final long alignByteNumber); @Override void close(); @Override void write(final int value); void writeBytes(final byte[] array, final int length, final JBBPByteOrder byteOrder); @Override void resetCounter(); void writeString(final String value, final JBBPByteOrder order); void writeStringArray(final String[] value, final JBBPByteOrder order);  }
@Test public void testWriteString_BigEndian_Null() throws Exception { assertArrayEquals(new byte[] {(byte) 0xFF}, writeString(JBBPByteOrder.BIG_ENDIAN, null)); }
@Test public void testWriteString_BigEndian_Empty() throws Exception { assertArrayEquals(new byte[] {0}, writeString(JBBPByteOrder.BIG_ENDIAN, "")); }
@Test public void testWriteString_BigEndian_ShortString() throws Exception { assertArrayEquals(new byte[] {0x03, 65, 66, 67}, writeString(JBBPByteOrder.BIG_ENDIAN, "ABC")); }
@Test public void testWriteString_LittleEndian_Null() throws Exception { assertArrayEquals(new byte[] {(byte) 0xFF}, writeString(JBBPByteOrder.LITTLE_ENDIAN, null)); }
@Test public void testWriteString_LittleEndian_Empty() throws Exception { assertArrayEquals(new byte[] {0}, writeString(JBBPByteOrder.LITTLE_ENDIAN, "")); }
@Test public void testWriteString_LittleEndian_ShortString() throws Exception { assertArrayEquals(new byte[] {0x03, 65, 66, 67}, writeString(JBBPByteOrder.LITTLE_ENDIAN, "ABC")); }