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

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

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

Bits.readFully介绍

[英]Reads bytes from the input stream and puts them into the given byte buffer. The equivalent of calling #readFully(java.io.InputStream,byte[],int,int) with an offset of zero and a length equal to the length of the buffer.
[中]从输入流读取字节并将它们放入给定的字节缓冲区。相当于以零偏移量和等于缓冲区长度的长度调用#readFully(java.io.InputStream,byte[],int,int)。

代码示例

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

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 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: 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: 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 void readFully( InputStream in, byte[] b )
  throws IOException {
  readFully( in , b , b.length );
}

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

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

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

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

相关文章