• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Buffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.embulk.spi.Buffer的典型用法代码示例。如果您正苦于以下问题:Java Buffer类的具体用法?Java Buffer怎么用?Java Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Buffer类属于org.embulk.spi包,在下文中一共展示了Buffer类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: poll

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Override
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;
        }
    }
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:26,代码来源:CommonsCompressFileInput.java


示例2: testPoll

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Test
public void testPoll(@Mocked final InputStream in, @Mocked final Buffer allocBuffer) throws Exception {
    final byte[] bytes = new byte[]{'f', 'o', 'o'};
    final int readLength = 3;

    new NonStrictExpectations() {{
        provider.openNext(); result = in;
        allocator.allocate(); result = allocBuffer;
        allocBuffer.array(); result = bytes;
        allocBuffer.offset(); result = 0;
        allocBuffer.capacity(); result = bytes.length;
        allocBuffer.limit(readLength); result = allocBuffer;
        allocBuffer.release();
        in.read(bytes, 0, bytes.length); result = readLength;
    }};
    
    CommonsCompressFileInput input = new CommonsCompressFileInput(allocator, provider);
    assertTrue("Verify there is a new stream.", input.nextFile());
    assertTrue("Verify allocated buffer is returned.", allocBuffer == input.poll());
    input.close();

    new Verifications() {{
        allocBuffer.limit(readLength); times = 1;
        allocBuffer.release(); times = 0;
    }};
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:27,代码来源:TestCommonsCompressFileInput.java


示例3: testPollThrowsException

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Test(expected=RuntimeException.class)
public void testPollThrowsException(@Mocked final InputStream in, @Mocked final Buffer allocBuffer) throws Exception {
    final byte[] bytes = new byte[]{'f', 'o', 'o'};

    new NonStrictExpectations() {{
        provider.openNext(); result = in;
        allocator.allocate(); result = allocBuffer;
        allocBuffer.array(); result = bytes;
        allocBuffer.offset(); result = 0;
        allocBuffer.capacity(); result = bytes.length;
        in.read(bytes, 0, bytes.length); result = new IOException("read throws IOException.");
    }};
    
    try {
        CommonsCompressFileInput input = new CommonsCompressFileInput(allocator, provider);
        assertTrue("Verify there is a new stream.", input.nextFile());
        input.poll();
        input.close();
    } finally {
        new Verifications() {{
            allocBuffer.release(); times = 1;
        }};
    }
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:25,代码来源:TestCommonsCompressFileInput.java


示例4: testGcsFileOutputByOpen

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Test
public void testGcsFileOutputByOpen() throws Exception
{
    ConfigSource configSource = config();
    PluginTask task = configSource.loadConfig(PluginTask.class);
    Schema schema = configSource.getNested("parser").loadConfig(CsvParserPlugin.PluginTask.class).getSchemaConfig().toSchema();
    runner.transaction(configSource, schema, 0, new Control());

    TransactionalFileOutput output = plugin.open(task.dump(), 0);

    output.nextFile();

    FileInputStream is = new FileInputStream(LOCAL_PATH_PREFIX);
    byte[] bytes = convertInputStreamToByte(is);
    Buffer buffer = Buffer.wrap(bytes);
    output.add(buffer);

    output.finish();
    output.commit();

    String remotePath = GCP_PATH_PREFIX + String.format(task.getSequenceFormat(), 0, 1) + task.getFileNameExtension();
    assertRecords(remotePath);
}
 
开发者ID:embulk,项目名称:embulk-output-gcs,代码行数:24,代码来源:TestGcsOutputPlugin.java


示例5: add

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Override
public void add(Buffer buffer)
{
    if (current == null) {
        throw new IllegalStateException(
                "nextFile() must be called before poll()");
    }

    try {
        current.write(buffer.array(), buffer.offset(), buffer.limit());
    }
    catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    finally {
        buffer.release();
    }
}
 
开发者ID:llibra,项目名称:embulk-output-s3,代码行数:19,代码来源:S3FileOutputPlugin.java


示例6: getInputStreamAsBuffer

import org.embulk.spi.Buffer; //导入依赖的package包/类
private Buffer getInputStreamAsBuffer(InputStream in) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    byte[] buff = new byte[1024];
    int len = in.read(buff);
    while (len != -1) {
      bout.write(buff, 0, len);
      len = in.read(buff);
    }
    in.close();
    return Buffer.wrap(bout.toByteArray());
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:12,代码来源:TestCommonsCompressDecoderPlugin.java


示例7: readFileInput

import org.embulk.spi.Buffer; //导入依赖的package包/类
private String readFileInput(FileInput input) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Buffer buffer = input.poll();
    while (buffer != null) {
        bout.write(buffer.array(), buffer.offset(), buffer.limit());
        buffer = input.poll();
    }
    return bout.toString().trim();
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:10,代码来源:TestCommonsCompressDecoderPlugin.java


示例8: poll

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Override
public Buffer poll() {
    if (buffer != null) {
        Buffer ret = buffer;
        buffer = null;
        return ret;
    } else {
        return null;
    }
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:11,代码来源:TestCommonsCompressDecoderPlugin.java


示例9: add

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Override
public void add(final Buffer buffer)
{
    try {
        localOutput.write(buffer.array(), buffer.offset(), buffer.limit());
    }
    catch (IOException ex) {
        throw Throwables.propagate(ex);
    }
    finally {
        buffer.release();
    }
}
 
开发者ID:embulk,项目名称:embulk-output-sftp,代码行数:14,代码来源:SftpFileOutput.java


示例10: add

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Override
public void add(Buffer buffer)
{
    try {
        logger.debug("#add called {} times for taskIndex {}", callCount, taskIndex);
        currentStream.write(buffer.array(), buffer.offset(), buffer.limit());
        callCount++;
    }
    catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    finally {
        buffer.release();
    }
}
 
开发者ID:embulk,项目名称:embulk-output-gcs,代码行数:16,代码来源:GcsOutputPlugin.java


示例11: guess

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Override
public ConfigDiff guess(ConfigSource config, Buffer sample) {

    GrokGuessPlugin.PluginTask task = config.getNested("parser").loadConfig(GrokGuessPlugin.PluginTask.class);

    LineDecoder.DecoderTask decoderTask = config.loadConfig(LineDecoder.DecoderTask.class);
    LineDecoder decoder = new LineDecoder(new ListFileInput(ImmutableList.of(ImmutableList.of((sample)))), decoderTask);

    List<String> sampleLines = new ArrayList<>();
    while (true) {
        if (!decoder.nextFile()) {
            break;
        }
        while (true) {
            String line = decoder.poll();
            if (line == null) {
                break;
            }
            sampleLines.add(line);
        }
    }

    GrokGuesser guesser = new GrokGuesser(
            task.getGuessPatterns(),
            task.getGrokPatternFiles()
    );
    try {
        String pattern = guesser.guessPattern(sampleLines);
        List<Map<String, Object>> columns = guesser.guessColumns(sampleLines, pattern);
        return Exec.newConfigDiff().set(
                "parser", ImmutableMap.of("grok_pattern", pattern, "columns", columns));
    } catch (GrokException e) {
        return Exec.newConfigDiff();
    }

}
 
开发者ID:arielnetworks,项目名称:embulk-parser-grok,代码行数:37,代码来源:GrokGuessPlugin.java


示例12: open

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Override
public TransactionalFileInput open(TaskSource taskSource, int taskIndex) {
	return new TransactionalFileInput() {
		private boolean eof = false;
		private int index = 0;

		@Override
		public Buffer poll() {
			if (index < list.size()) {
				String s = list.get(index++) + "\n";
				return Buffer.copyOf(s.getBytes(StandardCharsets.UTF_8));
			}

			eof = true;
			return null;
		}

		@Override
		public boolean nextFile() {
			return !eof;
		}

		@Override
		public void close() {
		}

		@Override
		public void abort() {
		}

		@Override
		public TaskReport commit() {
			return Exec.newTaskReport();
		}
	};
}
 
开发者ID:hishidama,项目名称:embulk-parser-poi_excel,代码行数:37,代码来源:EmbulkTestFileInputPlugin.java


示例13: add

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Override
public void add(Buffer buffer)
{
    try {
        // this implementation is for creating file when there is data.
        if (o == null) {
            o = hdfsClient.create(currentPath, overwrite);
            logger.info("Uploading '{}'", currentPath);
        }
        write(buffer);
    }
    catch (RetryExecutor.RetryGiveupException e) {
        throw new RuntimeException(e);
    }
    finally {
        buffer.release();
    }
}
 
开发者ID:civitaspo,项目名称:embulk-output-hdfs,代码行数:19,代码来源:HdfsFileOutput.java


示例14: getResourceAsBuffer

import org.embulk.spi.Buffer; //导入依赖的package包/类
private Buffer getResourceAsBuffer(String resource) throws IOException {
    return getInputStreamAsBuffer(getClass().getResourceAsStream(resource));
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:4,代码来源:TestCommonsCompressDecoderPlugin.java


示例15: MockFileInput

import org.embulk.spi.Buffer; //导入依赖的package包/类
MockFileInput(Buffer buffer) {
    this.buffer = buffer;
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:4,代码来源:TestCommonsCompressDecoderPlugin.java


示例16: allocate

import org.embulk.spi.Buffer; //导入依赖的package包/类
@Override
public Buffer allocate() {
    return allocate(8192);
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:5,代码来源:TestCommonsCompressDecoderPlugin.java



注:本文中的org.embulk.spi.Buffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FontAction类代码示例发布时间:2022-05-23
下一篇:
Java IColumn类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap