Java 类org.apache.hadoop.hbase.io.LimitInputStream 实例源码

项目:ditb    文件:ProtobufUtil.java   
/**
 * This version of protobuf's mergeDelimitedFrom avoids the hard-coded 64MB limit for decoding
 * buffers
 * @param builder current message builder
 * @param in Inputsream with delimited protobuf data
 * @throws IOException
 */
public static void mergeDelimitedFrom(Message.Builder builder, InputStream in)
  throws IOException {
  // This used to be builder.mergeDelimitedFrom(in);
  // but is replaced to allow us to bump the protobuf size limit.
  final int firstByte = in.read();
  if (firstByte != -1) {
    final int size = CodedInputStream.readRawVarint32(firstByte, in);
    final InputStream limitedInput = new LimitInputStream(in, size);
    final CodedInputStream codedInput = CodedInputStream.newInstance(limitedInput);
    codedInput.setSizeLimit(size);
    builder.mergeFrom(codedInput);
    codedInput.checkLastTagWas(0);
  }
}