List of utility methods to do ByteBuffer Put
ByteBuffer | put(ByteBuffer dst, ByteBuffer src, int transferLimit) Transfer from src to dst without throwing exception if src.remaining() > dst.remaining() but copying dst.remaining() bytes from src instead. if (src.remaining() <= dst.remaining() && transferLimit >= dst.remaining()) return dst.put(src); int oldLimit = src.limit(); src.limit(src.position() + Math.min(dst.remaining(), transferLimit)); dst.put(src); src.limit(oldLimit); return dst; |
int | put(ByteBuffer from, ByteBuffer to) Put data from one buffer into another, avoiding over/under flows int put; int remaining = from.remaining(); if (remaining > 0) { if (remaining <= to.remaining()) { to.put(from); put = remaining; from.position(from.limit()); } else if (from.hasArray()) { ... |
void | put(ByteBuffer src, ByteBuffer dst) Transfer bytes from src to dst. if (src.remaining() > dst.remaining()) { int limit = src.limit(); try { src.limit(src.position() + dst.remaining()); dst.put(src); } finally { src.limit(limit); } else { dst.put(src); |
void | put3ByteInt(ByteBuffer buffer, int val) Put an integer into the given buffer at the given offset as a 3-byte integer. put3ByteInt(buffer, val, buffer.order());
|
ByteBuffer | putAscii(ByteBuffer bytes, String value) put Ascii byte[] asciiBytes = value.getBytes("US-ASCII"); int numBytes = asciiBytes.length; if (numBytes > 65535) throw new IOException("ASCII string exceeds maximum size of 65535 bytes!"); if (bytes.remaining() < (numBytes + 2)) throw new IOException("not enough space in buffer to write string value"); putUnsignedShort(bytes, numBytes); for (int i = 0; i < numBytes; i++) ... |
boolean | putAsMuchAsPossible(ByteBuffer dest, ByteBuffer src) Put as many bytes as possible from the src buffer into the destination buffer. if (dest.remaining() >= src.remaining()) { dest.put(src); return true; if (dest.remaining() > 0) { int oldLimit = src.limit(); src.limit(src.position() + dest.remaining()); dest.put(src); ... |
void | putBoolean(ByteBuffer bb, boolean value) put Boolean bb.put((byte) (value ? 1 : 0));
|
void | putByte(ByteBuffer byteBuffer, int value) put Byte byteBuffer.put((byte) (value & BYTE_PADDING));
|
void | putByteArray(ByteBuffer byteBuffer, byte[] array) put Byte Array short length = array == null ? 0 : (short) array.length; byteBuffer.putShort(length); if (length != 0) { byteBuffer.put(array); |
ByteBuffer | putByteAsString(ByteBuffer buffer, byte value) Writes a single byte as raw characer data into the specified buffer. buffer.put(value);
return buffer;
|