org.bson.io.Bits类的使用及代码示例

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

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

Bits介绍

[英]Utility class for reading values from an 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 long value from the buffer. The equivalent of called {@link #readLong(byte[], int)} with an offset of
 * zero.
 *
 * @param buffer the buffer to read from
 * @return the long value
 */
public static long readLong(final byte[] buffer) {
  return readLong(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
 * @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

/**
 * Reads and returns a single long 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 long value
 * @throws IOException if there's an error reading from the {@code inputStream}
 */
public static long readLong(final InputStream inputStream, final byte[] buffer) throws IOException {
  readFully(inputStream, buffer, 8);
  return readLong(buffer);
}

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

_callback.gotDouble(name, Double.longBitsToDouble(Bits.readLong(_data, _pos)));
_pos += 8;
return true;
_callback.gotInt(name, Bits.readInt(_data, _pos));
_pos += 4;
return true;
_callback.gotLong(name, Bits.readLong(_data, _pos));
_pos += 8;
return true;
final int p1 = Bits.readIntBE(_data, _pos);
_pos += 4;
final int p2 = Bits.readIntBE(_data, _pos);
_pos += 4;
final int p3 = Bits.readIntBE(_data, _pos);
_pos += 4;
final int p1 = Bits.readInt(_data, _pos);
_pos += 4;
final int p2 = Bits.readInt(_data, _pos);
_pos += 4;
final int p3 = Bits.readInt(_data, _pos);
_pos += 4;

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

private final void _binary(final String pName) {
  final int totalLen = Bits.readInt(_data, _pos);
  _pos += 4;
      final int len = Bits.readInt(_data, _pos);
      _pos += 4;
        throw new IllegalArgumentException("bad data size subtype 3 len: " + totalLen + " != 16");
      final long part1 = Bits.readLong(_data, _pos);
      _pos += 8;
      final long part2 = Bits.readLong(_data, _pos);
      _pos += 8;

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

/**
 * Reads bytes from the input stream and puts them into the given byte buffer. The equivalent of calling
 * {@link #readFully(java.io.InputStream, byte[], int, int)} with an offset of zero and a length equal to the length of the buffer.
 *
 * @param inputStream the input stream to read from
 * @param buffer      the buffer into which the data is read.
 * @throws IOException if there's an error reading from the {@code inputStream}
 */
public static void readFully(final InputStream inputStream, final byte[] buffer)
throws IOException {
  readFully(inputStream, buffer, buffer.length);
}

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

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

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

public static long readLong( InputStream in , byte[] data )
  throws IOException {
  readFully(in, data, 8);
  return readLong(data);
}

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

/**
 * Reads bytes from the input stream and puts them into the given byte buffer. The equivalent of calling
 * {@link #readFully(java.io.InputStream, byte[], int, int)} with an offset of zero.
 *
 * @param inputStream the input stream to read from
 * @param buffer      the buffer into which the data is read.
 * @param length      the maximum number of bytes to read.
 * @throws IOException if there's an error reading from the {@code inputStream}
 */
public static void readFully(final InputStream inputStream, final byte[] buffer, final int length)
throws IOException {
  readFully(inputStream, buffer, 0, length);
}

代码示例来源: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

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: org.mongodb/mongo-java-driver

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

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

public static void readFully( InputStream in, byte[] b )
  throws IOException {
  readFully( in , b , b.length );
}

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

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

代码示例来源: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

@Override
protected void doWriteBinaryData(final BsonBinary value) {
  if (value.getType() == BsonBinarySubType.UUID_LEGACY.getValue()) {
    bsonCallback.gotUUID(getName(),
        readLong(value.getData(), 0),
        readLong(value.getData(), 8));
  } else {
    bsonCallback.gotBinary(getName(), value.getType(), value.getData());
  }
}

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

public static void readFully( InputStream in, byte[] b, int length )
  throws IOException {
  readFully(in, b, 0, length);
}

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

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

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

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

相关文章