org.apache.ratis.thirdparty.com.google.protobuf.ByteString.copyFrom()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(153)

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

ByteString.copyFrom介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-ratis

static ByteString toByteString(byte[] bytes, int offset, int size) {
 // return singleton to reduce object allocation
 return bytes.length == 0 ?
   ByteString.EMPTY : ByteString.copyFrom(bytes, offset, size);
}

代码示例来源:origin: apache/incubator-ratis

private static ByteString toByteString(UUID uuid) {
 Objects.requireNonNull(uuid, "uuid == null");
 final ByteBuffer buf = ByteBuffer.wrap(new byte[BYTE_LENGTH]);
 buf.putLong(uuid.getMostSignificantBits());
 buf.putLong(uuid.getLeastSignificantBits());
 return ByteString.copyFrom(buf.array());
}

代码示例来源:origin: apache/incubator-ratis

private RaftPeerId(String id) {
 this.idString = Objects.requireNonNull(id, "id == null");
 Preconditions.assertTrue(!id.isEmpty(), "id is an empty string.");
 this.id = ByteString.copyFrom(idString, StandardCharsets.UTF_8);
}

代码示例来源:origin: hortonworks/ratis

public static LogServiceException toLogException(Throwable t) {
 LogServiceException.Builder builder = LogServiceException.newBuilder();
 builder.setExceptionClassName(t.getClass().getName());
 builder.setErrorMsg(t.getMessage());
 StackTraceElement[] trace = t.getStackTrace();
 StringBuffer buf = new StringBuffer();
 for (StackTraceElement el: trace) {
  buf.append(el.toString()).append("\n");
 }
 String strace = buf.toString();
 builder.setStacktrace(ByteString.copyFrom(strace, Charset.defaultCharset()));
 return builder.build();
}

代码示例来源:origin: hortonworks/ratis

public static ReadLogReplyProto toReadLogReplyProto(List<byte[]> entries, Throwable t) {
 ReadLogReplyProto.Builder builder = ReadLogReplyProto.newBuilder();
 if (t != null) {
  builder.setException(toLogException(t));
 } else {
  for(byte[] record: entries) {
   builder.addLogRecord( ByteString.copyFrom(record));
  }
 }
 return builder.build();
}

代码示例来源:origin: apache/incubator-ratis

ByteString read(CheckedFunction<Path, Path, IOException> resolver, long offset, long length)
  throws IOException {
 flush();
 if (offset + length > getSize()) {
  throw new IOException("Failed to read: offset (=" + offset
    + " + length (=" + length + ") > size = " + getSize()
    + ", path=" + getRelativePath());
 }
 try(final SeekableByteChannel in = Files.newByteChannel(
   resolver.apply(getRelativePath()), StandardOpenOption.READ)) {
  final ByteBuffer buffer = ByteBuffer.allocateDirect(FileStoreCommon.getChunkSize(length));
  in.position(offset).read(buffer);
  buffer.flip();
  return ByteString.copyFrom(buffer);
 }
}

代码示例来源:origin: hortonworks/ratis

public static LogServiceRequestProto toAppendEntryLogRequestProto(LogName name,
  List<byte[]> entries) {
 LogNameProto logNameProto =
   LogNameProto.newBuilder().setName(name.getName()).build();
 AppendLogEntryRequestProto.Builder builder = AppendLogEntryRequestProto.newBuilder();
 builder.setLogName(logNameProto);
 for (int i=0; i < entries.size(); i++) {
  builder.addData(ByteString.copyFrom(entries.get(i)));
 }
 return LogServiceRequestProto.newBuilder().setAppendRequest(builder.build()).build();
}

代码示例来源:origin: hortonworks/ratis

public static LogServiceRequestProto toAppendBBEntryLogRequestProto(LogName name,
  List<ByteBuffer> entries) {
 LogNameProto logNameProto =
   LogNameProto.newBuilder().setName(name.getName()).build();
 AppendLogEntryRequestProto.Builder builder = AppendLogEntryRequestProto.newBuilder();
 builder.setLogName(logNameProto);
 for (int i=0; i < entries.size(); i++) {
  builder.addData(ByteString.copyFrom(entries.get(i)));
 }
 return LogServiceRequestProto.newBuilder().setAppendRequest(builder.build()).build();
}

代码示例来源:origin: apache/incubator-ratis

final ByteBuffer expected = ByteString.copyFrom(randomBytes(length, r)).asReadOnlyByteBuffer();

代码示例来源:origin: apache/incubator-ratis

private FileChunkProto readFileChunk(FileInfo fileInfo,
  FileInputStream in, byte[] buf, int length, long offset, int chunkIndex)
  throws IOException {
 FileChunkProto.Builder builder = FileChunkProto.newBuilder()
   .setOffset(offset).setChunkIndex(chunkIndex);
 IOUtils.readFully(in, buf, 0, length);
 Path relativePath = server.getState().getStorage().getStorageDir()
   .relativizeToRoot(fileInfo.getPath());
 builder.setFilename(relativePath.toString());
 builder.setDone(offset + length == fileInfo.getFileSize());
 builder.setFileDigest(
   ByteString.copyFrom(fileInfo.getFileDigest().getDigest()));
 builder.setData(ByteString.copyFrom(buf, 0, length));
 return builder.build();
}

代码示例来源:origin: apache/incubator-ratis

private static <OUTPUT, THROWABLE extends Throwable> OUTPUT writeImpl(
  CheckedFunction<ByteString, OUTPUT, THROWABLE> sendFunction,
  String path, long offset, boolean close, ByteBuffer data)
  throws THROWABLE {
 final WriteRequestHeaderProto.Builder header = WriteRequestHeaderProto.newBuilder()
   .setPath(ProtoUtils.toByteString(path))
   .setOffset(offset)
   .setLength(data.position())
   .setClose(close);
 final WriteRequestProto.Builder write = WriteRequestProto.newBuilder()
   .setHeader(header)
   .setData(ByteString.copyFrom(data));
 final FileStoreRequestProto request = FileStoreRequestProto.newBuilder().setWrite(write).build();
 return sendFunction.apply(request.toByteString());
}

相关文章