use of com.fasterxml.aalto.stax.InputFactoryImpl in project aalto-xml by FasterXML.
the class TestAsyncViaEventReader method testSimpleByteBuffer.
public void testSimpleByteBuffer() throws Exception {
final AsyncXMLInputFactory f = new InputFactoryImpl();
AsyncXMLStreamReader<AsyncByteBufferFeeder> sr = f.createAsyncFor(ByteBuffer.wrap("<root>a</r".getBytes("UTF-8")));
assertTokenType(START_DOCUMENT, sr.next());
XMLEventReader er = f.createXMLEventReader(sr);
XMLEvent evt = er.nextEvent();
assertTokenType(START_DOCUMENT, evt.getEventType());
evt = er.nextEvent();
assertTokenType(START_ELEMENT, evt.getEventType());
assertEquals("root", sr.getLocalName());
evt = er.nextEvent();
assertTokenType(CHARACTERS, evt.getEventType());
assertEquals("a", sr.getText());
// then need more input
evt = er.nextEvent();
assertTokenType(AsyncXMLStreamReader.EVENT_INCOMPLETE, evt.getEventType());
byte[] b = "oot>".getBytes("UTF-8");
sr.getInputFeeder().feedInput(ByteBuffer.wrap(b));
evt = er.nextEvent();
assertTokenType(END_ELEMENT, evt.getEventType());
assertEquals("root", sr.getLocalName());
evt = er.nextEvent();
assertTokenType(AsyncXMLStreamReader.EVENT_INCOMPLETE, evt.getEventType());
sr.getInputFeeder().endOfInput();
evt = er.nextEvent();
assertTokenType(END_DOCUMENT, evt.getEventType());
assertFalse(er.hasNext());
er.close();
sr.close();
}
use of com.fasterxml.aalto.stax.InputFactoryImpl in project aalto-xml by FasterXML.
the class TestCharactersParsing method _testLinefeeds.
/*
/**********************************************************************
/* Secondary test methods
/**********************************************************************
*/
private void _testLinefeeds(final int chunkSize, final boolean checkValues, final String SPC) throws Exception {
final String XML = SPC + "<root>\rFirst\r\nSecond\nThird: " + UNICODE_SEGMENT + "</root>";
final AsyncXMLInputFactory f = new InputFactoryImpl();
// test for byte array
AsyncXMLStreamReader<AsyncByteArrayFeeder> sr_array = null;
try {
sr_array = f.createAsyncForByteArray();
final AsyncReaderWrapperForByteArray reader_array = new AsyncReaderWrapperForByteArray(sr_array, chunkSize, XML);
_testLinefeeds(sr_array, reader_array, checkValues);
} finally {
if (sr_array != null) {
sr_array.close();
}
}
// test for byte buffer
AsyncXMLStreamReader<AsyncByteBufferFeeder> sr_buffer = null;
try {
sr_buffer = f.createAsyncForByteBuffer();
final AsyncReaderWrapperForByteBuffer reader_buffer = new AsyncReaderWrapperForByteBuffer(sr_buffer, chunkSize, XML);
_testLinefeeds(sr_buffer, reader_buffer, checkValues);
} finally {
if (sr_buffer != null) {
sr_buffer.close();
}
}
}
use of com.fasterxml.aalto.stax.InputFactoryImpl in project aalto-xml by FasterXML.
the class TestCharactersParsing method _testTextWithEntities.
private void _testTextWithEntities(final int chunkSize, final boolean checkValues, final String SPC) throws Exception {
final String XML = SPC + "<root>a<b\rMOT</root>";
final AsyncXMLInputFactory f = new InputFactoryImpl();
// test for byte array
AsyncXMLStreamReader<AsyncByteArrayFeeder> sr_array = null;
try {
sr_array = f.createAsyncForByteArray();
final AsyncReaderWrapperForByteArray reader_array = new AsyncReaderWrapperForByteArray(sr_array, chunkSize, XML);
_testTextWithEntities(sr_array, reader_array, checkValues);
} finally {
if (sr_array != null) {
sr_array.close();
}
}
// test for byte buffer
AsyncXMLStreamReader<AsyncByteBufferFeeder> sr_buffer = null;
try {
sr_buffer = f.createAsyncForByteBuffer();
final AsyncReaderWrapperForByteBuffer reader_buffer = new AsyncReaderWrapperForByteBuffer(sr_buffer, chunkSize, XML);
_testTextWithEntities(sr_buffer, reader_buffer, checkValues);
} finally {
if (sr_buffer != null) {
sr_buffer.close();
}
}
}
use of com.fasterxml.aalto.stax.InputFactoryImpl in project aalto-xml by FasterXML.
the class TestDoctypeParsing method _testInvalidDup.
private void _testInvalidDup(final String spaces, final int chunkSize) throws Exception {
final String XML = spaces + "<!DOCTYPE root> <!DOCTYPE root> <root />";
final AsyncXMLInputFactory f = new InputFactoryImpl();
// test for byte array
AsyncXMLStreamReader<AsyncByteArrayFeeder> sr_array = null;
try {
sr_array = f.createAsyncForByteArray();
final AsyncReaderWrapperForByteArray reader_array = new AsyncReaderWrapperForByteArray(sr_array, chunkSize, XML);
_testInvalidDup(sr_array, reader_array);
} finally {
if (sr_array != null) {
sr_array.close();
}
}
// test for byte buffer
AsyncXMLStreamReader<AsyncByteBufferFeeder> sr_buffer = null;
try {
sr_buffer = f.createAsyncForByteBuffer();
final AsyncReaderWrapperForByteBuffer reader_buffer = new AsyncReaderWrapperForByteBuffer(sr_buffer, chunkSize, XML);
_testInvalidDup(sr_buffer, reader_buffer);
} finally {
if (sr_buffer != null) {
sr_buffer.close();
}
}
}
use of com.fasterxml.aalto.stax.InputFactoryImpl in project aalto-xml by FasterXML.
the class TestDoctypeParsing method _testSimplest.
/*
/**********************************************************************
/* Helper methods
/**********************************************************************
*/
private void _testSimplest(final String spaces, final int chunkSize) throws Exception {
final String XML = spaces + "<!DOCTYPE root> <root />";
final AsyncXMLInputFactory f = new InputFactoryImpl();
// test for byte array
AsyncXMLStreamReader<AsyncByteArrayFeeder> sr_array = null;
try {
sr_array = f.createAsyncForByteArray();
final AsyncReaderWrapperForByteArray reader_array = new AsyncReaderWrapperForByteArray(sr_array, chunkSize, XML);
_testSimplest(sr_array, reader_array);
} finally {
if (sr_array != null) {
sr_array.close();
}
}
// test for byte buffer
AsyncXMLStreamReader<AsyncByteBufferFeeder> sr_buffer = null;
try {
sr_buffer = f.createAsyncForByteBuffer();
final AsyncReaderWrapperForByteBuffer reader_buffer = new AsyncReaderWrapperForByteBuffer(sr_buffer, chunkSize, XML);
_testSimplest(sr_buffer, reader_buffer);
} finally {
if (sr_buffer != null) {
sr_buffer.close();
}
}
}
Aggregations