Java Code Examples for javax.imageio.stream.MemoryCacheImageOutputStream#writeByte()

The following examples show how to use javax.imageio.stream.MemoryCacheImageOutputStream#writeByte() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ByteArrayTest.java    From zserio with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void constructorRead() throws IOException
{
    final byte BYTE_VALUE = -10;
    final int NUM_BITS = 8;

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final MemoryCacheImageOutputStream os = new MemoryCacheImageOutputStream(baos);
    os.writeByte(BYTE_VALUE);
    os.close();
    baos.close();

    final ByteArrayBitStreamReader in = new ByteArrayBitStreamReader(baos.toByteArray());

    final ArrayWrapper array = factory.create(in, 1, NUM_BITS);

    assertEquals(1, array.length());
    assertEquals(BYTE_VALUE, array.elementAt(0));
}
 
Example 2
Source File: UnsignedByteArrayTest.java    From zserio with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void constructorRead() throws IOException
{
    final int HIGH_NIBBLE = 1;
    final int LOW_NIBBLE = 2;

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final MemoryCacheImageOutputStream os = new MemoryCacheImageOutputStream(baos);
    os.writeByte((HIGH_NIBBLE << 4) | LOW_NIBBLE);
    os.close();
    baos.close();

    final ByteArrayBitStreamReader in = new ByteArrayBitStreamReader(baos.toByteArray());

    final ArrayWrapper array = factory.create(in, 2, 4);

    assertEquals(2, array.length());
    assertEquals(HIGH_NIBBLE, array.elementAt(0));
    assertEquals(LOW_NIBBLE, array.elementAt(1));
}