Java Code Examples for org.apache.ratis.thirdparty.com.google.protobuf.ByteString#Output

The following examples show how to use org.apache.ratis.thirdparty.com.google.protobuf.ByteString#Output . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestContainerCommandRequestMessage.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
static ByteString newData(int length) {
  final ByteString.Output out = ByteString.newOutput();
  for(int i = 0; i < length; i++) {
    out.write(RANDOM.nextInt());
  }
  return out.toByteString();
}
 
Example 2
Source File: TestClientProtoUtils.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
static ByteString newByteString(int size, int offset) throws IOException {
  try(final ByteString.Output out = ByteString.newOutput()) {
    for (int i = 0; i < size; i++) {
      out.write(i + offset);
    }
    return out.toByteString();
  }
}
 
Example 3
Source File: ProtoUtils.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
static ByteString writeObject2ByteString(Object obj) {
  final ByteString.Output byteOut = ByteString.newOutput();
  try(ObjectOutputStream objOut = new ObjectOutputStream(byteOut)) {
    objOut.writeObject(obj);
  } catch (IOException e) {
    throw new IllegalStateException(
        "Unexpected IOException when writing an object to a ByteString.", e);
  }
  return byteOut.toByteString();
}
 
Example 4
Source File: ProtoUtils.java    From ratis with Apache License 2.0 5 votes vote down vote up
static ByteString writeObject2ByteString(Object obj) {
  final ByteString.Output byteOut = ByteString.newOutput();
  try(final ObjectOutputStream objOut = new ObjectOutputStream(byteOut)) {
    objOut.writeObject(obj);
  } catch (IOException e) {
    throw new IllegalStateException(
        "Unexpected IOException when writing an object to a ByteString.", e);
  }
  return byteOut.toByteString();
}