Search in sources :

Example 1 with AsyncByteBufferFeeder

use of com.fasterxml.aalto.AsyncByteBufferFeeder in project aalto-xml by FasterXML.

the class AsyncReaderWrapperForByteBuffer method nextToken.

@Override
public int nextToken() throws XMLStreamException {
    int token;
    while ((token = _streamReader.next()) == AsyncXMLStreamReader.EVENT_INCOMPLETE) {
        _buf.clear();
        AsyncByteBufferFeeder feeder = _streamReader.getInputFeeder();
        if (!feeder.needMoreInput()) {
            AsyncTestBase.fail("Got EVENT_INCOMPLETE, could not feed more input");
        }
        if (_offset >= _xml.length) {
            // end-of-input?
            feeder.endOfInput();
        } else {
            int amount = Math.min(_bytesPerFeed, _xml.length - _offset);
            _buf.put(_xml, _offset, amount);
            _buf.flip();
            feeder.feedInput(_buf);
            _offset += amount;
        }
    }
    return token;
}
Also used : AsyncByteBufferFeeder(com.fasterxml.aalto.AsyncByteBufferFeeder)

Example 2 with AsyncByteBufferFeeder

use of com.fasterxml.aalto.AsyncByteBufferFeeder 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 AsyncByteBufferFeeder

use of com.fasterxml.aalto.AsyncByteBufferFeeder 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 AsyncByteBufferFeeder

use of com.fasterxml.aalto.AsyncByteBufferFeeder 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 AsyncByteBufferFeeder

use of com.fasterxml.aalto.AsyncByteBufferFeeder 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

AsyncByteBufferFeeder (com.fasterxml.aalto.AsyncByteBufferFeeder)24 AsyncXMLInputFactory (com.fasterxml.aalto.AsyncXMLInputFactory)22 InputFactoryImpl (com.fasterxml.aalto.stax.InputFactoryImpl)22 AsyncByteArrayFeeder (com.fasterxml.aalto.AsyncByteArrayFeeder)21 ByteBuffer (java.nio.ByteBuffer)1