Search in sources :

Example 1 with FSOutputStreamFactory

use of org.apache.tika.batch.fs.FSOutputStreamFactory in project tika by apache.

the class BasicTikaFSConsumersBuilder method getOutputStreamFactory.

private OutputStreamFactory getOutputStreamFactory(Node node, Map<String, String> runtimeAttributes, ContentHandlerFactory contentHandlerFactory, boolean useRecursiveParserWrapper) {
    Map<String, String> attrs = XMLDOMUtil.mapifyAttrs(node, runtimeAttributes);
    Path outputDir = PropsUtil.getPath(attrs.get("outputDir"), null);
    /*        FSUtil.HANDLE_EXISTING handleExisting = null;
        String handleExistingString = attrs.get("handleExisting");
        if (handleExistingString == null) {
            handleExistingException();
        } else if (handleExistingString.equals("overwrite")){
            handleExisting = FSUtil.HANDLE_EXISTING.OVERWRITE;
        } else if (handleExistingString.equals("rename")) {
            handleExisting = FSUtil.HANDLE_EXISTING.RENAME;
        } else if (handleExistingString.equals("skip")) {
            handleExisting = FSUtil.HANDLE_EXISTING.SKIP;
        } else {
            handleExistingException();
        }
*/
    String compressionString = attrs.get("compression");
    FSOutputStreamFactory.COMPRESSION compression = FSOutputStreamFactory.COMPRESSION.NONE;
    if (compressionString == null) {
    //do nothing
    } else if (compressionString.contains("bz")) {
        compression = FSOutputStreamFactory.COMPRESSION.BZIP2;
    } else if (compressionString.contains("gz")) {
        compression = FSOutputStreamFactory.COMPRESSION.GZIP;
    } else if (compressionString.contains("zip")) {
        compression = FSOutputStreamFactory.COMPRESSION.ZIP;
    }
    String suffix = attrs.get("outputSuffix");
    //suffix should not start with "."
    if (suffix == null) {
        StringBuilder sb = new StringBuilder();
        if (useRecursiveParserWrapper) {
            sb.append("json");
        } else if (contentHandlerFactory instanceof BasicContentHandlerFactory) {
            appendSuffix(((BasicContentHandlerFactory) contentHandlerFactory).getType(), sb);
        }
        appendCompression(compression, sb);
        suffix = sb.toString();
    }
    //if the driver restarts and this is set to overwrite...
    return new FSOutputStreamFactory(outputDir, FSUtil.HANDLE_EXISTING.SKIP, compression, suffix);
}
Also used : Path(java.nio.file.Path) BasicContentHandlerFactory(org.apache.tika.sax.BasicContentHandlerFactory) FSOutputStreamFactory(org.apache.tika.batch.fs.FSOutputStreamFactory)

Aggregations

Path (java.nio.file.Path)1 FSOutputStreamFactory (org.apache.tika.batch.fs.FSOutputStreamFactory)1 BasicContentHandlerFactory (org.apache.tika.sax.BasicContentHandlerFactory)1