org.vertx.java.core.buffer.Buffer.getByteBuf()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(1.5k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中org.vertx.java.core.buffer.Buffer.getByteBuf()方法的一些代码示例,展示了Buffer.getByteBuf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.getByteBuf()方法的具体详情如下:
包路径:org.vertx.java.core.buffer.Buffer
类名称:Buffer
方法名:getByteBuf

Buffer.getByteBuf介绍

暂无

代码示例

代码示例来源:origin: liveoak-io/liveoak

@Override
public void readContent(RequestContext ctx, BinaryContentSink sink) {
  vertx().fileSystem().open(file.getPath(), (result) -> {
    if (result.succeeded()) {
      AsyncFile asyncFile = result.result();
      asyncFile.dataHandler((buffer) -> {
        sink.accept(buffer.getByteBuf());
      });
      asyncFile.endHandler((end) -> {
        sink.close();
        asyncFile.close();
      });
    } else {
      sink.close();
    }
  });
}

代码示例来源:origin: liveoak-io/liveoak

@Override
public void readContent(RequestContext ctx, BinaryContentSink sink) throws Exception {
  GridFS gridfs = getUserspace().getGridFS();
  // TODO - maybe use netty directly here?
  // TODO - BinaryContentSink should flush to socket (pipeline channel), not queue to memory
  // get tmp file
  File tmpFile = getTempFile();
  // sync copy from db to tmp file first - no async API
  GridFSDBFile file = gridfs.findOne(new BasicDBObject("_id", fileInfo().getId()));
  file.writeTo(tmpFile);
  // async copy from local tmp file to sink
  getRoot().vertx().fileSystem().open(tmpFile.getPath(), (result) -> {
    if (result.succeeded()) {
      AsyncFile asyncFile = result.result();
      asyncFile.dataHandler((buffer) -> {
        sink.accept(buffer.getByteBuf());
      });
      asyncFile.endHandler((end) -> {
        sink.close();
        asyncFile.close();
        tmpFile.delete();
      });
    } else {
      sink.close();
      tmpFile.delete();
    }
  });
}

相关文章