Java Utililty Methods ByteBuffer Write

List of utility methods to do ByteBuffer Write

Description

The list of methods to do ByteBuffer Write are organized into topic(s).

Method

voidwriteFully(WritableByteChannel bc, ByteBuffer buf)
Write a ByteBuffer to a WritableByteChannel, handling short writes.
do {
    bc.write(buf);
} while (buf.remaining() > 0);
longwriteFully(WritableByteChannel channel, ByteBuffer[] srcs)
write Fully
long totalBytes = remaining(srcs);
long bytesToWrite = totalBytes;
long bytesWritten;
do {
    bytesWritten = write(channel, srcs);
    bytesToWrite -= bytesWritten;
} while (bytesToWrite > 0);
return totalBytes;
...
voidwriteHalf(final ByteBuffer buf, final int value)
write Half
putUnsignedByte(buf, value >> 0);
putUnsignedByte(buf, value >> 8);
voidwriteHeader(int type, ByteBuffer lengthBuffer, ByteBuffer buffer)
write Header
buffer.put((byte) type);
buffer.put(lengthBuffer);
voidwriteHeaderAndLsd(ByteBuffer out, int width, int height, boolean hasGct, int gctSize)
write Header And Lsd
verifyRemaining(out, HEADER_LENGTH);
verifyShortValues(width, height);
out.put((byte) 0x47).put((byte) 0x49).put((byte) 0x46);
out.put((byte) 0x38).put((byte) 0x39).put((byte) 0x61);
out.putShort((short) width);
out.putShort((short) height);
byte gctFlag = (byte) ((hasGct ? 1 : 0) << 7);
byte colorResolution = 1 << 5;
...
voidwriteHexString(ByteBuffer buffer, String hex)
write Hex String
byte[] bytes = hexStringToBytes(hex);
for (int i = bytes.length - 1; i >= 0; i--) {
    buffer.put(bytes[i]);
voidwriteHexString(ByteBuffer buffer, String hexStr)
Writes a sequence of hexidecimal values into the given buffer, where every two characters represent one byte value.
char[] hexChars = hexStr.toCharArray();
if ((hexChars.length % 2) != 0) {
    throw new IOException("Hex string length must be even");
for (int i = 0; i < hexChars.length; i += 2) {
    String tmpStr = new String(hexChars, i, 2);
    buffer.put((byte) Long.parseLong(tmpStr, 16));
voidwriteImageDescriptor(ByteBuffer out, int imageLeft, int imageTop, int imageWidth, int imageHeight, boolean hasLct, int numColors)
write Image Descriptor
verifyRemaining(out, IMAGE_DESCRIPTOR_LENGTH);
verifyShortValues(imageLeft, imageTop, imageWidth, imageHeight);
final byte packed;
if (hasLct) {
    int size = log2(numColors) - 1;
    packed = (byte) (0x80 | size);
} else {
    packed = 0x00;
...
voidwriteInt(ByteBuffer buf, int pos, int v)
Writes a specific integer value (4 bytes) to the output byte buffer at the given offset.
buf.put(pos++, (byte) (0xff & (v >> 24)));
buf.put(pos++, (byte) (0xff & (v >> 16)));
buf.put(pos++, (byte) (0xff & (v >> 8)));
buf.put(pos, (byte) (0xff & v));
voidwriteInt(ByteBuffer logBuf, int i)
Write an int into the log.
byte b = (byte) ((i >> 0) & 0xff);
logBuf.put(b);
b = (byte) ((i >> 8) & 0xff);
logBuf.put(b);
b = (byte) ((i >> 16) & 0xff);
logBuf.put(b);
b = (byte) ((i >> 24) & 0xff);
logBuf.put(b);
...