Java Code Examples for org.jboss.marshalling.Marshalling#createByteInput()

The following examples show how to use org.jboss.marshalling.Marshalling#createByteInput() . 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: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testEqualBuffer() throws Exception {
    final byte[] content = "1234567890".getBytes(StandardCharsets.UTF_8);

    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);

    byteOutput.write(content);
    byteOutput.flush();

    final byte[] chunked = byteArrayOutputStream.toByteArray();

    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
    final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));
    byte[] result = new byte[content.length];
    byteInput.read(result);
    byteInput.close();

    Assert.assertArrayEquals(content, result);
    Assert.assertEquals(-1, byteInput.read());
}
 
Example 2
Source File: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testMultiChunk() throws Exception {
    final byte[] content = "12345678901234567890123456789012345678901234567890".getBytes(StandardCharsets.UTF_8);

    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);

    byteOutput.write(content);
    byteOutput.flush();

    final byte[] chunked = byteArrayOutputStream.toByteArray();

    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
    final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));
    byte[] result = new byte[content.length];
    byteInput.read(result);
    byteInput.close();

    Assert.assertArrayEquals(content, result);
    Assert.assertEquals(-1, byteInput.read());
}
 
Example 3
Source File: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRemainingBytes() throws Exception {
    final byte[] content = "1234567890123456789012345678901234567890123".getBytes(StandardCharsets.UTF_8);

    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);

    byteOutput.write(content);
    byteOutput.flush();

    final byte[] chunked = byteArrayOutputStream.toByteArray();

    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
    final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));
    byte[] result = new byte[content.length];
    byteInput.read(result);
    byteInput.close();

    Assert.assertArrayEquals(content, result);
    Assert.assertEquals(-1, byteInput.read());
}
 
Example 4
Source File: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testIncompleteRead() throws Exception {
    final byte[] content = "1234567890123456789012345678901234567890123".getBytes(StandardCharsets.UTF_8);

    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);

    byteOutput.write(content);
    byteOutput.flush();

    final byte[] chunked = byteArrayOutputStream.toByteArray();

    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
    final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));
    int readLength = content.length - 15;
    byte[] result = new byte[readLength];
    byteInput.read(result);
    byteInput.close();

    byte[] expected = new byte[readLength];
    System.arraycopy(content, 0, expected, 0, readLength);

    Assert.assertArrayEquals(expected, result);
    Assert.assertEquals(-1, byteInput.read());
}
 
Example 5
Source File: ChunkyByteInputOutputTest.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testOffsetRead() throws Exception {
    final byte[] content = "1234567890123456789012345678901234567890123".getBytes(StandardCharsets.UTF_8);

    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    final ByteOutput byteOutput = new ChunkyByteOutput(Marshalling.createByteOutput(byteArrayOutputStream), 10);

    byteOutput.write(content);
    byteOutput.flush();

    final byte[] chunked = byteArrayOutputStream.toByteArray();

    final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(chunked);
    final ByteInput byteInput = new ChunkyByteInput(Marshalling.createByteInput(byteArrayInputStream));

    int readLength = 5;
    byte[] result = new byte[content.length];
    byteInput.read(result, content.length - 6, readLength);
    byteInput.close();

    byte[] expected = new byte[content.length];
    System.arraycopy(content, 0, expected, content.length - 6, readLength);

    Assert.assertArrayEquals(expected, result);
    Assert.assertEquals(-1, byteInput.read());
}
 
Example 6
Source File: ChunkyByteInput.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ChunkyByteInput(final InputStream inputStream) {
    input = Marshalling.createByteInput(inputStream);
}
 
Example 7
Source File: ChunkyByteInput.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ChunkyByteInput(final InputStream inputStream, final int remaining) {
    input = Marshalling.createByteInput(inputStream);
    this.remaining = remaining;
}
 
Example 8
Source File: SimpleByteDataInput.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SimpleByteDataInput(final InputStream inputStream) {
    this.input = new SimpleDataInput(Marshalling.createByteInput(inputStream));
}