Search in sources :

Example 1 with CountingInputStream

use of com.amazonaws.util.CountingInputStream in project aws-sdk-android by aws-amplify.

the class InputStreamsTest method testSimple.

/**
 * Tests the simple use case for InputSubstream
 */
@Test
public void testSimple() throws Exception {
    InputSubstream in = new InputSubstream(new ByteArrayInputStream(sampleData.getBytes(StringUtils.UTF8)), 10, 10, true);
    assertEquals(10, in.available());
    byte[] buffer = new byte[10];
    assertEquals(10, in.read(buffer));
    assertEquals("1234567890", new String(buffer, StringUtils.UTF8));
    assertEquals(0, in.available());
    CountingInputStream countingStream = new CountingInputStream(new InputSubstream(new ByteArrayInputStream(sampleData.getBytes(StringUtils.UTF8)), 10, 10, true));
    int c;
    System.out.print("Data: ");
    while ((c = countingStream.read()) > -1) {
        System.out.print((char) c);
    }
    System.out.println();
    assertEquals(10, countingStream.getByteCount());
    countingStream = new CountingInputStream(new InputSubstream(new ByteArrayInputStream(sampleData.getBytes(StringUtils.UTF8)), 10, 10, true));
    byte[] bytes = new byte[1];
    System.out.print("Data: ");
    while ((c = countingStream.read(bytes)) > -1) {
        System.out.print((char) bytes[0]);
    }
    System.out.println();
    assertEquals(10, countingStream.getByteCount());
}
Also used : InputSubstream(com.amazonaws.services.s3.internal.InputSubstream) ByteArrayInputStream(java.io.ByteArrayInputStream) CountingInputStream(com.amazonaws.util.CountingInputStream) Test(org.junit.Test)

Aggregations

InputSubstream (com.amazonaws.services.s3.internal.InputSubstream)1 CountingInputStream (com.amazonaws.util.CountingInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.Test)1