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

voidwriteByteBuffer(ByteBuffer bbuf, String filename)
write Byte Buffer
File file;
try {
    String logfile = "C:\\" + filename + ".txt";
    file = new File(logfile);
    boolean exists = file.exists();
    if (!exists) {
        try {
            file = new File(logfile);
...
intwriteByteBuffer(RandomAccessFile file, ByteBuffer buffer)
Write an entire ByteBuffer into a file.
return file.getChannel().write(buffer);
intwriteByteBuffer(WritableByteChannel channel, ByteBuffer buf, int bytesToWrite)
Writes bytes from buf to the channel until at least bytesToWrite number of bytes are written.
int t = bytesToWrite; 
while (t > 0) {
    t -= channel.write(buf);
return bytesToWrite - t;
voidwriteBytesNoLength(ByteBuffer logBuf, byte[] b)
Write a byte array into the log.
logBuf.put(b);
voidwriteByteString(ByteBuffer byteBuffer, String value)
write Byte String
byteBuffer.putInt(value.length());
byteBuffer.put(value.getBytes());
voidwriteCDouble(ByteBuffer buffer, double value)
write C Double
writeCLong(buffer, Double.doubleToLongBits(value));
voidwriteCharacterString(ByteBuffer buf, byte[] bytes)
Writes a character string into the buffer.
if (bytes.length > 254) {
    throw new IllegalArgumentException(
            "The length of a character string must be between 0 and 254 octets.");
buf.put((byte) bytes.length);
buf.put(bytes);
voidwriteCInt(ByteBuffer buffer, int anInt)
write C Int
if (anInt > -127 && anInt <= 127) {
    buffer.put((byte) anInt);
} else if (anInt >= Short.MIN_VALUE && anInt <= Short.MAX_VALUE) {
    buffer.put((byte) -128);
    buffer.putShort((short) anInt);
} else {
    buffer.put((byte) -127);
    buffer.putInt(anInt);
...
voidwriteColorTable(ByteBuffer out, int numColors)
write Color Table
verifyRemaining(out, getColorTableLength(numColors));
for (int i = 0; i < numColors; i++) {
    out.put((byte) (0xFF0000 & i));
    out.put((byte) (0x00FF00 & i));
    out.put((byte) (0x0000FF & i));
voidwriteDouble(ByteBuffer buffer, double d)
write Double
writeLong(buffer, Double.doubleToLongBits(d));