Search in sources :

Example 16 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class RecordableReaderTest method testReadAndGetTextsAutoStopRecord.

public void testReadAndGetTextsAutoStopRecord() throws Exception {
    RecordableInputStream ris = new RecordableInputStream(new ByteArrayInputStream(DATA), "utf-8");
    assertEquals(0, ris.size());
    byte[] buf = new byte[64];
    // read 64 bytes
    int n = ris.read(buf, 0, buf.length);
    assertEquals(64, n);
    assertEquals(64, ris.size());
    // consume the 64 bytes
    String text = ris.getText(64);
    assertEquals(new String(DATA, 0, 64, "utf-8"), text);
    assertEquals(0, ris.size());
    // read the next 64 bytes
    n = ris.read(buf, 0, buf.length);
    assertEquals(64, n);
    assertEquals(0, ris.size());
    // turn back on the recording and read the next 64 bytes
    ris.record();
    n = ris.read(buf, 0, buf.length);
    assertEquals(64, n);
    assertEquals(64, ris.size());
    // consume the 64 bytes
    text = ris.getText(64);
    // 64 * 2 = 128
    assertEquals(new String(DATA, 128, 64, "utf-8"), text);
    assertEquals(0, ris.size());
    ris.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 17 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class RecordableReaderTest method testReadAndGetTextsBufferPurge.

public void testReadAndGetTextsBufferPurge() throws Exception {
    RecordableInputStream ris = new RecordableInputStream(new ByteArrayInputStream(DATA), "utf-8");
    assertEquals(0, ris.size());
    byte[] buf = new byte[64];
    // 8 * 64 = 512
    for (int i = 0; i < 8; i++) {
        // read in 64 bytes
        int n = ris.read(buf, 0, buf.length);
        assertEquals(64, n);
        assertEquals(64, ris.size());
        int offset = i * 64;
        // consume the first 32 bytes
        String text = ris.getText(32);
        assertEquals(new String(DATA, offset, 32, "utf-8"), text);
        assertEquals(32, ris.size());
        // consume the other 32 bytes
        text = ris.getText(32);
        assertEquals(new String(DATA, offset + 32, 32, "utf-8"), text);
        assertEquals(0, ris.size());
        ris.record();
    }
    ris.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 18 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class XMLTokenExpressionIteratorTest method testExtractSomeQualifiedChild.

public void testExtractSomeQualifiedChild() throws Exception {
    nsmap.put("", "urn:c");
    invokeAndVerify("//child", 'w', new ByteArrayInputStream(TEST_BODY_NO_NS_MIXED), RESULTS_CHILD_NS_MIXED_WRAPPED);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 19 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class XMLTokenExpressionIteratorTest method testExtractSomeUnqualifiedChildInjected.

public void testExtractSomeUnqualifiedChildInjected() throws Exception {
    String[] result = RESULTS_CHILD_NO_NS_MIXED_JAVA8;
    if (isJava7OrLower()) {
        result = RESULTS_CHILD_NO_NS_MIXED;
    }
    invokeAndVerify("//child", 'i', new ByteArrayInputStream(TEST_BODY_NO_NS_MIXED), result);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 20 with ByteArrayInputStream

use of java.io.ByteArrayInputStream in project camel by apache.

the class XMLTokenExpressionIteratorTest method testExtractCxxxd.

public void testExtractCxxxd() throws Exception {
    String[] result = RESULTS_CHILD_JAVA8;
    if (isJava7OrLower()) {
        result = RESULTS_CHILD;
    }
    invokeAndVerify("//C:c*d", 'i', new ByteArrayInputStream(TEST_BODY), result);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)6879 Test (org.junit.Test)2274 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1791 InputStream (java.io.InputStream)1531 IOException (java.io.IOException)1400 DataInputStream (java.io.DataInputStream)600 ObjectInputStream (java.io.ObjectInputStream)597 X509Certificate (java.security.cert.X509Certificate)397 CertificateFactory (java.security.cert.CertificateFactory)355 ObjectOutputStream (java.io.ObjectOutputStream)333 File (java.io.File)279 ArrayList (java.util.ArrayList)270 Certificate (java.security.cert.Certificate)234 HashMap (java.util.HashMap)212 DataOutputStream (java.io.DataOutputStream)200 FileInputStream (java.io.FileInputStream)182 InputStreamReader (java.io.InputStreamReader)180 Test (org.testng.annotations.Test)171 Document (org.w3c.dom.Document)143 Map (java.util.Map)138