use of com.fasterxml.aalto.stax.InputFactoryImpl in project georocket by georocket.
the class FirstLevelSplitterTest method split.
/**
* Use the {@link FirstLevelSplitter} and split an XML string
* @param xml the XML string
* @return the chunks created by the splitter
* @throws Exception if the XML string could not be parsed
*/
private List<Result<XMLChunkMeta>> split(String xml) throws Exception {
Window window = new Window();
window.append(Buffer.buffer(xml));
AsyncXMLInputFactory xmlInputFactory = new InputFactoryImpl();
AsyncXMLStreamReader<AsyncByteArrayFeeder> reader = xmlInputFactory.createAsyncForByteArray();
byte[] xmlBytes = xml.getBytes(StandardCharsets.UTF_8);
reader.getInputFeeder().feedInput(xmlBytes, 0, xmlBytes.length);
FirstLevelSplitter splitter = new FirstLevelSplitter(window);
List<Result<XMLChunkMeta>> chunks = new ArrayList<>();
while (reader.hasNext()) {
int event = reader.next();
if (event == AsyncXMLStreamReader.EVENT_INCOMPLETE) {
reader.close();
continue;
}
int pos = reader.getLocation().getCharacterOffset();
Result<XMLChunkMeta> chunk = splitter.onEvent(new XMLStreamEvent(event, pos, reader));
if (chunk != null) {
chunks.add(chunk);
}
}
return chunks;
}
use of com.fasterxml.aalto.stax.InputFactoryImpl in project aalto-xml by FasterXML.
the class TestCommentParsing method _testComments.
private void _testComments(final String spaces, final int chunkSize) throws Exception {
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, spaces + XML);
_testComments(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, spaces + XML);
_testComments(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 TestElementParsing method testTrivial_array.
/**
* Trivial test to verify basic operation with a full buffer.
*/
public void testTrivial_array() throws Exception {
final AsyncXMLInputFactory f = new InputFactoryImpl();
AsyncXMLStreamReader<AsyncByteArrayFeeder> sr = null;
try {
sr = f.createAsyncFor("<root>a</root>".getBytes("UTF-8"));
assertTokenType(START_DOCUMENT, sr.next());
assertTokenType(START_ELEMENT, sr.next());
assertEquals("root", sr.getLocalName());
assertTokenType(CHARACTERS, sr.next());
assertEquals("a", sr.getText());
assertTokenType(END_ELEMENT, sr.next());
assertEquals("root", sr.getLocalName());
// no input to see (could still get a PI, comment etc), so
assertTokenType(AsyncXMLStreamReader.EVENT_INCOMPLETE, sr.next());
sr.getInputFeeder().endOfInput();
assertTokenType(END_DOCUMENT, sr.next());
} finally {
if (sr != null) {
sr.close();
}
}
}
use of com.fasterxml.aalto.stax.InputFactoryImpl in project aalto-xml by FasterXML.
the class TestXmlDeclaration method testStandAloneDeclaration2.
public void testStandAloneDeclaration2() throws Exception {
final String XML = "<?xml version=\"1.0\" standalone='yes'?>\n<root/>";
final AsyncXMLInputFactory f = new InputFactoryImpl();
for (final int chunkSize : CHUNK_SIZES) {
// test for byte array
AsyncXMLStreamReader<AsyncByteArrayFeeder> sr_array = null;
try {
sr_array = f.createAsyncForByteArray();
final AsyncReaderWrapperForByteArray reader_array = new AsyncReaderWrapperForByteArray(sr_array, chunkSize, XML);
_testStandAloneDeclaration2(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);
_testStandAloneDeclaration2(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 TestXmlDeclaration method testEncodingDeclaration.
public void testEncodingDeclaration() throws Exception {
final String XML = "<?xml version= \"1.0\" encoding='UTF-8' ?><root/>";
final AsyncXMLInputFactory f = new InputFactoryImpl();
for (final int chunkSize : CHUNK_SIZES) {
// test for byte array
AsyncXMLStreamReader<AsyncByteArrayFeeder> sr_array = null;
try {
sr_array = f.createAsyncForByteArray();
final AsyncReaderWrapperForByteArray reader_array = new AsyncReaderWrapperForByteArray(sr_array, chunkSize, XML);
_testEncodingDeclaration(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);
_testEncodingDeclaration(sr_buffer, reader_buffer);
} finally {
if (sr_buffer != null) {
sr_buffer.close();
}
}
}
}
Aggregations