All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.spuchmann.xml.splitter.stax.InMemoryStaxNodeSplitter Maven / Gradle / Ivy

The newest version!
package com.github.spuchmann.xml.splitter.stax;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

/**
 * in memory split storage. every fragment will be stored inside the memory.
 * Hint:  Make sure you have configured enough memory or just use the FileStaxNodeSplitter
 *
 * @since 0.1.0
 */
public class InMemoryStaxNodeSplitter extends StaxNodeSplitter {

    private List baosList = new ArrayList<>();

    @Override
    protected XMLStreamWriter createNewStreamWriter(SplitContext context) throws XMLStreamException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        baosList.add(baos);
        return getOutputFactory().createXMLStreamWriter(baos);
    }

    @Override
    protected void closeInternalStream() {
        //baos don't needed to be closed
    }

    public List getResultList() {
        return baosList;
    }

    /**
     * resets the whole internal storage
     */
    public void resetResultList() {
        baosList = new ArrayList<>();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy