Search in sources :

Example 11 with AsyncByteArrayFeeder

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

the class TestPIParsing method _testPI.

private void _testPI(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);
        _testPI(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);
        _testPI(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 12 with AsyncByteArrayFeeder

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

the class TestPIParsing method _testPISkip.

private void _testPISkip(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);
        _testPISkip(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);
        _testPISkip(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 13 with AsyncByteArrayFeeder

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

the class TestXmlDeclaration method testNoDeclaration.

public void testNoDeclaration() throws Exception {
    final AsyncXMLInputFactory f = new InputFactoryImpl();
    for (final String XML : new String[] { "   <root />", "<root/>" }) {
        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);
                _testNoDeclaration(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);
                _testNoDeclaration(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 14 with AsyncByteArrayFeeder

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

the class TestXmlDeclaration method testStandAloneDeclaration.

public void testStandAloneDeclaration() throws Exception {
    final String XML = "<?xml version  ='1.0' encoding=\"UTF-8\"  standalone='yes' ?>  <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);
            _testStandAloneDeclaration(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);
            _testStandAloneDeclaration(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 15 with AsyncByteArrayFeeder

use of com.fasterxml.aalto.AsyncByteArrayFeeder 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;
}
Also used : Window(io.georocket.util.Window) XMLStreamEvent(io.georocket.util.XMLStreamEvent) ArrayList(java.util.ArrayList) AsyncByteArrayFeeder(com.fasterxml.aalto.AsyncByteArrayFeeder) InputFactoryImpl(com.fasterxml.aalto.stax.InputFactoryImpl) Result(io.georocket.input.Splitter.Result) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) AsyncXMLInputFactory(com.fasterxml.aalto.AsyncXMLInputFactory)

Aggregations

AsyncByteArrayFeeder (com.fasterxml.aalto.AsyncByteArrayFeeder)25 AsyncXMLInputFactory (com.fasterxml.aalto.AsyncXMLInputFactory)24 InputFactoryImpl (com.fasterxml.aalto.stax.InputFactoryImpl)23 AsyncByteBufferFeeder (com.fasterxml.aalto.AsyncByteBufferFeeder)21 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 XMLStreamException (javax.xml.stream.XMLStreamException)1