Search in sources :

Example 1 with InputStreamWritable

use of org.apache.nifi.processors.hadoop.util.InputStreamWritable in project nifi by apache.

the class SequenceFileWriterImpl method processInputStream.

protected void processInputStream(InputStream stream, FlowFile flowFile, final Writer writer) throws IOException {
    int fileSize = (int) flowFile.getSize();
    final InputStreamWritable inStreamWritable = new InputStreamWritable(new BufferedInputStream(stream), fileSize);
    String key = flowFile.getAttribute(CoreAttributes.FILENAME.key());
    writer.append(new Text(key), inStreamWritable);
}
Also used : InputStreamWritable(org.apache.nifi.processors.hadoop.util.InputStreamWritable) BufferedInputStream(java.io.BufferedInputStream) Text(org.apache.hadoop.io.Text)

Example 2 with InputStreamWritable

use of org.apache.nifi.processors.hadoop.util.InputStreamWritable in project nifi by apache.

the class ZipUnpackerSequenceFileWriter method processInputStream.

@Override
protected void processInputStream(InputStream stream, final FlowFile flowFile, final Writer writer) throws IOException {
    try (final ZipInputStream zipIn = new ZipInputStream(new BufferedInputStream(stream))) {
        ZipEntry zipEntry;
        while ((zipEntry = zipIn.getNextEntry()) != null) {
            if (zipEntry.isDirectory()) {
                continue;
            }
            final File file = new File(zipEntry.getName());
            final String key = file.getName();
            long fileSize = zipEntry.getSize();
            final InputStreamWritable inStreamWritable = new InputStreamWritable(zipIn, (int) fileSize);
            writer.append(new Text(key), inStreamWritable);
            logger.debug("Appending FlowFile {} to Sequence File", new Object[] { key });
        }
    }
}
Also used : InputStreamWritable(org.apache.nifi.processors.hadoop.util.InputStreamWritable) ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(org.apache.nifi.stream.io.BufferedInputStream) ZipEntry(java.util.zip.ZipEntry) Text(org.apache.hadoop.io.Text) FlowFile(org.apache.nifi.flowfile.FlowFile) File(java.io.File)

Example 3 with InputStreamWritable

use of org.apache.nifi.processors.hadoop.util.InputStreamWritable in project nifi by apache.

the class TarUnpackerSequenceFileWriter method processInputStream.

@Override
protected void processInputStream(final InputStream stream, final FlowFile tarArchivedFlowFile, final Writer writer) throws IOException {
    try (final TarArchiveInputStream tarIn = new TarArchiveInputStream(new BufferedInputStream(stream))) {
        TarArchiveEntry tarEntry;
        while ((tarEntry = tarIn.getNextTarEntry()) != null) {
            if (tarEntry.isDirectory()) {
                continue;
            }
            final String key = tarEntry.getName();
            final long fileSize = tarEntry.getSize();
            final InputStreamWritable inStreamWritable = new InputStreamWritable(tarIn, (int) fileSize);
            writer.append(new Text(key), inStreamWritable);
            logger.debug("Appending FlowFile {} to Sequence File", new Object[] { key });
        }
    }
}
Also used : TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) InputStreamWritable(org.apache.nifi.processors.hadoop.util.InputStreamWritable) BufferedInputStream(org.apache.nifi.stream.io.BufferedInputStream) Text(org.apache.hadoop.io.Text) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Aggregations

Text (org.apache.hadoop.io.Text)3 InputStreamWritable (org.apache.nifi.processors.hadoop.util.InputStreamWritable)3 BufferedInputStream (org.apache.nifi.stream.io.BufferedInputStream)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)1 FlowFile (org.apache.nifi.flowfile.FlowFile)1