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;
}
}
}
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);
}
}
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;
}
Aggregations