JBBPOut extends AbstractMappedClassFieldObserver { public static JBBPOut BeginBin(final JBBPByteOrder byteOrder, final JBBPBitOrder bitOrder) { return new JBBPOut(new ByteArrayOutputStream(), byteOrder, bitOrder); } private  JBBPOut(final OutputStream outStream, final JBBPByteOrder byteOrder, final JBBPBitOrder bitOrder); static JBBPOut BeginBin(final JBBPByteOrder byteOrder, final JBBPBitOrder bitOrder); static JBBPOut BeginBin(final OutputStream out, final JBBPByteOrder byteOrder, final JBBPBitOrder bitOrder); static JBBPOut BeginBin(); static JBBPOut BeginBin(final int initialSize); static JBBPOut BeginBin(final OutputStream out); static JBBPOut BeginBin(final JBBPByteOrder byteOrder); static JBBPOut BeginBin(final JBBPBitOrder bitOrder); JBBPOut Align(); JBBPOut Align(final int value); JBBPOut Skip(int numberOfBytes); JBBPOut ByteOrder(final JBBPByteOrder value); JBBPOut Bit(final boolean value); JBBPOut Bit(final byte value); JBBPOut Bit(final byte[] value); JBBPOut Bit(final int... value); JBBPOut Bit(final boolean... value); JBBPOut Bits(final JBBPBitNumber numberOfBits, final int value); JBBPOut Bits(final JBBPBitNumber numberOfBits, final int... value); JBBPOut Bits(final JBBPBitNumber numberOfBits, final byte[] value); JBBPOut Byte(final int value); JBBPOut Byte(final int... value); JBBPOut Byte(final byte[] value); JBBPOut Byte(final String str); JBBPOut Byte(final String str, final JBBPBitOrder bitOrder); JBBPOut Utf8(final String str); JBBPOut String(String str); JBBPOut Strings(final String... strings); JBBPOut Bool(final boolean value); JBBPOut Bool(final boolean value, final JBBPBitOrder bitOrder); JBBPOut Bool(final boolean... value); JBBPOut Short(final int value); JBBPOut Short(final String str); JBBPOut Short(final String str, final JBBPBitOrder bitOrder); JBBPOut Short(final short[] value); JBBPOut Short(final char[] value); JBBPOut Short(final int... value); JBBPOut Int(final int value); JBBPOut Int(final int... value); JBBPOut Float(final float... value); JBBPOut Long(final long value); JBBPOut Double(final double... value); JBBPOut ResetCounter(); JBBPOut Long(final long... value); JBBPOut Var(final JBBPOutVarProcessor processor, final Object... args); JBBPOut Flush(); ByteArrayOutputStream End(); long getByteCounter(); JBBPOut Bin(final Object object); JBBPOut Bin(final Object object, final JBBPCustomFieldWriter customFieldWriter); JBBPOut Bin(final Object object, final BinAnnotationWrapper binAnnotationWrapper, final JBBPCustomFieldWriter customFieldWriter); JBBPOut BinForceByteOrder(final Object object); JBBPOut BinForceByteOrder(final Object object, final JBBPCustomFieldWriter customFieldWriter); static final JBBPByteOrder DEFAULT_BYTE_ORDER; static final JBBPBitOrder DEFAULT_BIT_ORDER; }
@Test public void testBeginBin() throws Exception { assertArrayEquals(new byte[] {1}, BeginBin().Byte(1).End().toByteArray()); assertArrayEquals(new byte[] {0x02, 0x01}, BeginBin(JBBPByteOrder.LITTLE_ENDIAN).Short(0x0102).End().toByteArray()); assertArrayEquals(new byte[] {0x40, (byte) 0x80}, BeginBin(JBBPByteOrder.LITTLE_ENDIAN, JBBPBitOrder.MSB0).Short(0x0102).End().toByteArray()); assertArrayEquals(new byte[] {(byte) 0x80}, BeginBin(JBBPBitOrder.MSB0).Byte(1).End().toByteArray()); assertArrayEquals(new byte[] {(byte) 0x80}, BeginBin(1).Byte(0x80).End().toByteArray()); final ByteArrayOutputStream buffer1 = new ByteArrayOutputStream(); assertSame(buffer1, BeginBin(buffer1).End()); final ByteArrayOutputStream buffer2 = new ByteArrayOutputStream(); BeginBin(buffer2, JBBPByteOrder.LITTLE_ENDIAN, JBBPBitOrder.MSB0).Short(1234).End(); assertArrayEquals(new byte[] {(byte) 0x4b, (byte) 0x20}, buffer2.toByteArray()); }
@Test public void testExceptionForBitOrderConfilctInCaseOfUsageBitOutputStream() throws Exception { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); final JBBPBitOutputStream bitstream = new JBBPBitOutputStream(buffer, JBBPBitOrder.LSB0); assertThrows(IllegalArgumentException.class, () -> BeginBin(bitstream, JBBPByteOrder.BIG_ENDIAN, JBBPBitOrder.MSB0)); }