org.bson.io.Bits.readInt()方法的使用及代码示例

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

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

Bits.readInt介绍

[英]Reads and returns a single integer value from the input stream.
[中]从输入流读取并返回单个整数值。

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Reads and returns a single integer value from the buffer. The equivalent of calling {@link #readInt(byte[], int)}
 * with an offset of zero.
 *
 * @param buffer the buffer to read from
 * @return the integer value
 */
public static int readInt(final byte[] buffer) {
  return readInt(buffer, 0);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Reads and returns a single integer value from the input stream.
 *
 * @param inputStream the input stream to read from
 * @return the integer value
 * @throws IOException if there's an error reading from the {@code inputStream}
 */
public static int readInt(final InputStream inputStream) throws IOException {
  return readInt(inputStream, new byte[4]);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Reads and returns a single integer value from the input stream.
 *
 * @param inputStream the input stream to read from
 * @param buffer the buffer to write the input stream bytes into
 * @return the integer value
 * @throws IOException if there's an error reading from the {@code inputStream}
 */
public static int readInt(final InputStream inputStream, final byte[] buffer) throws IOException {
  readFully(inputStream, buffer, 4);
  return readInt(buffer);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

@Override
  public int decode(final InputStream in, final BSONCallback callback) throws IOException {
    byte[] documentSizeBuffer = new byte[BYTES_IN_INTEGER];
    int documentSize = Bits.readInt(in, documentSizeBuffer);
    byte[] documentBytes = Arrays.copyOf(documentSizeBuffer, documentSize);
    Bits.readFully(in, documentBytes, BYTES_IN_INTEGER, documentSize - BYTES_IN_INTEGER);

    // note that we are handing off ownership of the documentBytes byte array to the callback
    callback.gotBinary(null, (byte) 0, documentBytes);
    return documentSize;
  }
}

代码示例来源:origin: org.mongodb/mongo-java-driver

private byte[] readFully(final InputStream input) throws IOException {
    byte[] sizeBytes = new byte[4];
    Bits.readFully(input, sizeBytes);
    int size = Bits.readInt(sizeBytes);

    byte[] buffer = new byte[size];
    System.arraycopy(sizeBytes, 0, buffer, 0, 4);
    Bits.readFully(input, buffer, 4, size - 4);
    return buffer;
  }
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

public static int readInt( InputStream in )
  throws IOException {
  return readInt( in , new byte[4] );
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

public static int readInt( byte[] data ) {
  return readInt( data , 0 );
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

@Override
public int decode(byte[] b, BSONCallback callback) {
  _length = Bits.readInt(b);
  return _decode(b, 0, callback);
}

代码示例来源:origin: org.mongodb/mongo-hadoop-core_0.23.1

private synchronized void checkHeader(){
  // Read the BSON length from the start of the record
  byte[] l = new byte[4];
  try {
    _input.readFully( l );
    nextLen = org.bson.io.Bits.readInt( l );
    nextHdr = l;
    hasMore.set( true );
  } catch (Exception e) {
    log.debug( "Failed to get next header: " + e, e );
    hasMore.set( false );
    try {
      _input.close();
    }
    catch ( IOException e1 ) { }
  }
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

public BSONObject readObject(final InputStream pIn) throws IOException {
  // Slurp in the data and convert to a byte array.
  _length = Bits.readInt(pIn);
  if (_data == null || _data.length < _length) {
    _data = new byte[_length];
  }
  (new DataInputStream(pIn)).readFully(_data, 4, (_length - 4));
  return readObject(_data);
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

@Override
public int decode(byte[] b, int offset, BSONCallback callback) {
  _length = Bits.readInt(b, offset);
  return _decode(b, offset, callback);
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

public static int readInt( InputStream in , byte[] data )
  throws IOException {
  readFully(in, data, 4);
  return readInt(data);
}

代码示例来源:origin: org.mongodb/mongo-hadoop-core_cdh3u3

private synchronized void checkHeader(){
  // Read the BSON length from the start of the record
  byte[] l = new byte[4];
  try {
    _input.readFully( l );
    nextLen = org.bson.io.Bits.readInt( l );
    nextHdr = l;
    hasMore.set( true );
  } catch (Exception e) {
    log.debug( "Failed to get next header: " + e, e );
    hasMore.set( false );
    try {
      _input.close();
    }
    catch ( IOException e1 ) { }
  }
}

代码示例来源:origin: org.mongodb/mongo-hadoop-core_0.22.0

private synchronized void checkHeader(){
  // Read the BSON length from the start of the record
  byte[] l = new byte[4];
  try {
    _input.readFully( l );
    nextLen = org.bson.io.Bits.readInt( l );
    nextHdr = l;
    hasMore.set( true );
  } catch (Exception e) {
    log.debug( "Failed to get next header: " + e, e );
    hasMore.set( false );
    try {
      _input.close();
    }
    catch ( IOException e1 ) { }
  }
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

public int decode(final InputStream pIn, final BSONCallback pCallback) throws IOException {
  _length = Bits.readInt(pIn);
  if (_data == null || _data.length < _length) {
    _data = new byte[_length];
  }
  (new DataInputStream(pIn)).readFully(_data, 4, (_length - 4));
  return _decode(_data, 0, pCallback);
}

代码示例来源:origin: org.mongodb/mongo-hadoop-core_0.20.205.0

private synchronized void checkHeader(){
  // Read the BSON length from the start of the record
  byte[] l = new byte[4];
  try {
    _input.readFully( l );
    nextLen = org.bson.io.Bits.readInt( l );
    nextHdr = l;
    hasMore.set( true );
  } catch (Exception e) {
    log.debug( "Failed to get next header: " + e, e );
    hasMore.set( false );
    try {
      _input.close();
    }
    catch ( IOException e1 ) { }
  }
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

public int readInt()
    throws IOException {
  return org.bson.io.Bits.readInt( _inputBuffer , _need(4) );
}

代码示例来源:origin: thiloplanz/jmockmongo

static final int readInt32(ChannelBuffer buffer, byte[] fourBytes) {
  buffer.readBytes(fourBytes);
  return Bits.readInt(fourBytes);
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

private final String readUtf8Str() {
  final int length = Bits.readInt(_data, _pos);
  _pos += 4;
  if (length <= 0 || length > MAX_STRING) throw new BSONException("String invalid - corruption");
  try {
    final String str = new String(_data, _pos, (length - 1), DEFAULT_ENCODING);
    _pos += length;
    return str;
  } catch (final UnsupportedEncodingException uee) {
    throw new BSONException("What is in the db", uee);
  }
}

代码示例来源:origin: com.sequoiadb/sequoiadb-driver

@Override
public BSONObject readObject(byte[] b, int offset) {
  _length = Bits.readInt(b, offset);
  final BasicBSONCallback c = new BasicBSONCallback();
  _decode(b, offset, c);
  return (BSONObject)c.get();
}

相关文章