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();
}
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();
}
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);
}
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);
}
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);
}
Aggregations