/** * Writes an array of longs to the underlying stream. If the underlying stream does not contain * enough of free space to write it will be expanded before it is written to. A long takes up 8 * bytes. * * @param x The array to write to the stream. */ public void putLongs(long[] x) { ByteBuffer b = stream.getWriter(x.length << 3); for (int i = 0; i < x.length; i++) { b.putLong(x[i]); } }
/** * Writes an array of unsigned ints to the underlying stream. If the underlying stream does not * contain enough of free space to write it will be expanded before it is written to. An unsigned * int takes up 4 bytes. * * @param x The array to write to the stream. */ public void putUints(long[] x) { ByteBuffer b = stream.getWriter(x.length << 2); for (int i = 0; i < x.length; i++) { b.putInt((int) x[i]); } }
/** * Writes a long to the underlying stream. If the underlying stream does not contain enough of * free space to write it, it will be expanded before it is written to. A long takes up 8 bytes. * * @param value The value to write to the stream. */ public void putLong(long value) { stream.getWriter(8).putLong(value); }
/** * Returns the byte order of the writer. * * @return The byte order of the writer. */ public ByteOrder order() { return stream.order(); }
/** * Writes an array of booleans to the underlying stream. If the underlying stream does not contain * enough of free space to write it will be expanded before it is written to. * * @param x The array to write to the stream. */ public void putBooleans(boolean[] x) { ByteBuffer b = stream.getWriter(x.length); for (int i = 0; i < x.length; i++) { b.put((byte) (x[i] ? 1 : 0)); } }
/** * Writes a double to the underlying stream. If the underlying stream does not contain enough of * free space to write it, it will be expanded before it is written to. A double takes up 8 bytes. * * @param value The value to write to the stream. */ public void putDouble(double value) { stream.getWriter(8).putDouble(value); }
/** * Writes the remaining data in the given buffer to the underlying stream. If the underlying * stream does not contain enough of free space to write it will be expanded before it is written * to. * * @param x The buffer to transfer data from. */ public void putBuffer(ByteBuffer x) { stream.drain(x); }
/** * Writes an array of chars to the underlying stream. If the underlying stream does not contain * enough of free space to write it will be expanded before it is written to. A char takes up 2 * bytes. * * @param x The array to write to the stream. */ public void putChars(char[] x) { ByteBuffer b = stream.getWriter(x.length << 1); for (int i = 0; i < x.length; i++) { b.putChar(x[i]); } }
/** * Writes a short to the underlying stream. If the underlying stream does not contain enough of * free space to write it, it will be expanded before it is written to. A short takes up 2 bytes. * * @param value The value to write to the stream. */ public void putShort(short value) { stream.getWriter(2).putShort(value); }
/** * Writes an array of unsigned bytes to the underlying stream. If the underlying stream does not * contain enough of free space to write it will be expanded before it is written to. * * @param x The array to write to the stream. */ public void putUbytes(short[] x) { ByteBuffer b = stream.getWriter(x.length); for (int i = 0; i < x.length; i++) { b.put((byte) x[i]); } }
/** * Writes a char to the underlying stream. If the underlying stream does not contain enough of * free space to write it, it will be expanded before it is written to. A char takes up 2 bytes. * * @param value The value to write to the stream. */ public void putChar(char value) { stream.getWriter(2).putChar(value); }
/** * Writes an unsigned byte to the underlying stream. If the underlying stream does not contain * enough of free space to write it, it will be expanded before it is written to. * * @param value The value to write to the stream. */ public void putUbyte(short value) { stream.getWriter(1).put((byte) value); }
/** * Writes an array of bytes to the underlying stream. If the underlying stream does not contain * enough of free space to write it will be expanded before it is written to. * * @param x The array to write to the stream. */ public void putBytes(byte[] x) { stream.getWriter(x.length).put(x); }
/** * Writes a byte to the underlying stream. If the underlying stream does not contain enough of * free space to write it, it will be expanded before it is written to. * * @param value The value to write to the stream. */ public void putByte(byte value) { stream.getWriter(1).put(value); }
/** * Writes a float to the underlying stream. If the underlying stream does not contain enough of * free space to write it, it will be expanded before it is written to. A float takes up 4 bytes. * * @param value The value to write to the stream. */ public void putFloat(float value) { stream.getWriter(4).putFloat(value); }
/** * Writes an array of shorts to the underlying stream. If the underlying stream does not contain * enough of free space to write it will be expanded before it is written to. A short takes up 2 * bytes. * * @param x The array to write to the stream. */ public void putShorts(short[] x) { ByteBuffer b = stream.getWriter(x.length << 1); for (int i = 0; i < x.length; i++) { b.putShort(x[i]); } }
/** * Writes an array of floats to the underlying stream. If the underlying stream does not contain * enough of free space to write it will be expanded before it is written to. A float takes up 4 * bytes. * * @param x The array to write to the stream. */ public void putFloats(float[] x) { ByteBuffer b = stream.getWriter(x.length << 2); for (int i = 0; i < x.length; i++) { b.putFloat(x[i]); } }
/** * Writes an unsigned short to the underlying stream. If the underlying stream does not contain * enough of free space to write it, it will be expanded before it is written to. An unsigned * short takes up 2 bytes. * * @param value The value to write to the stream. */ public void putUshort(int value) { stream.getWriter(2).putShort((short) value); }
/** * Writes an array of doubles to the underlying stream. If the underlying stream does not contain * enough of free space to write it will be expanded before it is written to. A double takes up 8 * bytes. * * @param x The array to write to the stream. */ public void putDoubles(double[] x) { ByteBuffer b = stream.getWriter(x.length << 3); for (int i = 0; i < x.length; i++) { b.putDouble(x[i]); } }
/** * Writes an int to the underlying stream. If the underlying stream does not contain enough of * free space to write it, it will be expanded before it is written to. An int takes up 4 bytes. * * @param value The value to write to the stream. */ public void putInt(int value) { stream.getWriter(4).putInt(value); }
/** * Returns the total number of bytes in the underlying stream which have been written. * * @return The number of bytes written. */ public int size() { return stream.size(); }
/** * Writes an unsigned int to the underlying stream. If the underlying stream does not contain * enough of free space to write it, it will be expanded before it is written to. An unsigned int * takes up 4 bytes. * * @param value The value to write to the stream. */ public void putUint(long value) { stream.getWriter(4).putInt((int) value); }
/** * Sets the byte order of the reader. * * @param order The new byte order of the reader. */ public void order(ByteOrder order) { stream.order(order); }
/** * Writes a boolean to the underlying stream. If the underlying stream does not contain enough of * free space to write it will be expanded before it is written to. A boolean takes up a single * byte, a 0 for false and every other number means true. * * @param value The value to write to the stream. */ public void putBoolean(boolean value) { stream.getWriter(1).put((byte) (value ? 1 : 0)); }