/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
_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;
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;
/** * 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); }
public int readIntBE() throws IOException { return org.bson.io.Bits.readIntBE( _inputBuffer , _need(4) ); }
/** * 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); }
/** * 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]); }
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; } }
/** * 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]); }
public static void readFully( InputStream in, byte[] b ) throws IOException { readFully( in , b , b.length ); }
public static int readInt( InputStream in ) throws IOException { return readInt( in , new byte[4] ); }
@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; } }
@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()); } }
public static void readFully( InputStream in, byte[] b, int length ) throws IOException { readFully(in, b, 0, length); }
public static int readInt( byte[] data ) { return readInt( data , 0 ); }