Search in sources :

Example 1 with InputFactoryImpl

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();
}
Also used : XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) InputFactoryImpl(com.fasterxml.aalto.stax.InputFactoryImpl)

Example 2 with InputFactoryImpl

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();
        }
    }
}
Also used : AsyncByteBufferFeeder(com.fasterxml.aalto.AsyncByteBufferFeeder) AsyncByteArrayFeeder(com.fasterxml.aalto.AsyncByteArrayFeeder) InputFactoryImpl(com.fasterxml.aalto.stax.InputFactoryImpl) AsyncXMLInputFactory(com.fasterxml.aalto.AsyncXMLInputFactory)

Example 3 with InputFactoryImpl

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&lt;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();
        }
    }
}
Also used : AsyncByteBufferFeeder(com.fasterxml.aalto.AsyncByteBufferFeeder) AsyncByteArrayFeeder(com.fasterxml.aalto.AsyncByteArrayFeeder) InputFactoryImpl(com.fasterxml.aalto.stax.InputFactoryImpl) AsyncXMLInputFactory(com.fasterxml.aalto.AsyncXMLInputFactory)

Example 4 with InputFactoryImpl

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();
        }
    }
}
Also used : AsyncByteBufferFeeder(com.fasterxml.aalto.AsyncByteBufferFeeder) AsyncByteArrayFeeder(com.fasterxml.aalto.AsyncByteArrayFeeder) InputFactoryImpl(com.fasterxml.aalto.stax.InputFactoryImpl) AsyncXMLInputFactory(com.fasterxml.aalto.AsyncXMLInputFactory)

Example 5 with InputFactoryImpl

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();
        }
    }
}
Also used : AsyncByteBufferFeeder(com.fasterxml.aalto.AsyncByteBufferFeeder) AsyncByteArrayFeeder(com.fasterxml.aalto.AsyncByteArrayFeeder) InputFactoryImpl(com.fasterxml.aalto.stax.InputFactoryImpl) AsyncXMLInputFactory(com.fasterxml.aalto.AsyncXMLInputFactory)

Aggregations

InputFactoryImpl (com.fasterxml.aalto.stax.InputFactoryImpl)25 AsyncXMLInputFactory (com.fasterxml.aalto.AsyncXMLInputFactory)24 AsyncByteArrayFeeder (com.fasterxml.aalto.AsyncByteArrayFeeder)23 AsyncByteBufferFeeder (com.fasterxml.aalto.AsyncByteBufferFeeder)22 Result (io.georocket.input.Splitter.Result)1 XMLChunkMeta (io.georocket.storage.XMLChunkMeta)1 Window (io.georocket.util.Window)1 XMLStreamEvent (io.georocket.util.XMLStreamEvent)1 ArrayList (java.util.ArrayList)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLEvent (javax.xml.stream.events.XMLEvent)1