Search in sources :

Example 6 with Buffer

use of org.embulk.spi.Buffer in project embulk by embulk.

the class InputStreamFileInput method poll.

public Buffer poll() {
    if (current == null) {
        throw new IllegalStateException("nextFile() must be called before poll()");
    }
    Buffer buffer = allocator.allocate();
    try {
        int n = current.read(buffer.array(), buffer.offset(), buffer.capacity());
        if (n < 0) {
            return null;
        }
        buffer.limit(n);
        Buffer b = buffer;
        buffer = null;
        return b;
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } finally {
        if (buffer != null) {
            buffer.release();
            buffer = null;
        }
    }
}
Also used : Buffer(org.embulk.spi.Buffer) IOException(java.io.IOException)

Example 7 with Buffer

use of org.embulk.spi.Buffer in project embulk by embulk.

the class PreviewExecutor method doPreview.

private PreviewResult doPreview(ConfigSource config) {
    PreviewTask task = config.loadConfig(PreviewTask.class);
    InputPlugin inputPlugin = newInputPlugin(task);
    List<FilterPlugin> filterPlugins = newFilterPlugins(task);
    if (inputPlugin instanceof FileInputRunner) {
        // file input runner
        Buffer sample = SamplingParserPlugin.runFileInputSampling((FileInputRunner) inputPlugin, config.getNested("in"), createSampleBufferConfigFromExecConfig(task.getExecConfig()));
        FileInputRunner previewRunner = new FileInputRunner(new BufferFileInputPlugin(sample));
        return doPreview(task, previewRunner, filterPlugins);
    } else {
        return doPreview(task, inputPlugin, filterPlugins);
    }
}
Also used : Buffer(org.embulk.spi.Buffer) InputPlugin(org.embulk.spi.InputPlugin) FilterPlugin(org.embulk.spi.FilterPlugin) FileInputRunner(org.embulk.spi.FileInputRunner)

Example 8 with Buffer

use of org.embulk.spi.Buffer in project embulk by embulk.

the class SamplingParserPlugin method readSample.

public static Buffer readSample(FileInput fileInput, Buffer sample, int offset, int sampleBufferBytes) {
    if (!fileInput.nextFile()) {
        // no input files
        return sample;
    }
    try {
        for (Buffer buffer : each(fileInput)) {
            int size = Math.min(buffer.limit(), sample.capacity() - offset);
            sample.setBytes(offset, buffer, 0, size);
            offset += size;
            buffer.release();
            if (offset >= sampleBufferBytes) {
                break;
            }
        }
    } finally {
        sample.limit(offset);
    }
    return sample;
}
Also used : Buffer(org.embulk.spi.Buffer)

Aggregations

Buffer (org.embulk.spi.Buffer)8 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 TaskReport (org.embulk.config.TaskReport)1 FileInputRunner (org.embulk.spi.FileInputRunner)1 FilterPlugin (org.embulk.spi.FilterPlugin)1 InputPlugin (org.embulk.spi.InputPlugin)1 TransactionalFileOutput (org.embulk.spi.TransactionalFileOutput)1