Java ByteBuffer Write writeCharacterString(ByteBuffer buf, byte[] bytes)

Here you can find the source of writeCharacterString(ByteBuffer buf, byte[] bytes)

Description

Writes a character string into the buffer.

License

Open Source License

Parameter

Parameter Description
buf the buffer to write to
bytes the character string to write

Declaration

public static void writeCharacterString(ByteBuffer buf, byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    /**//w ww .  j  a v  a 2s. co  m
     * Writes a character string into the buffer. The maximum length of the
     * character string is 254 bytes.
     *
     * @param buf
     *            the buffer to write to
     * @param bytes
     *            the character string to write
     */
    public static void writeCharacterString(ByteBuffer buf, byte[] bytes) {
        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);
    }
}

Related

  1. writeByteBuffer(RandomAccessFile file, ByteBuffer buffer)
  2. writeByteBuffer(WritableByteChannel channel, ByteBuffer buf, int bytesToWrite)
  3. writeBytesNoLength(ByteBuffer logBuf, byte[] b)
  4. writeByteString(ByteBuffer byteBuffer, String value)
  5. writeCDouble(ByteBuffer buffer, double value)
  6. writeCInt(ByteBuffer buffer, int anInt)
  7. writeColorTable(ByteBuffer out, int numColors)
  8. writeDouble(ByteBuffer buffer, double d)
  9. writeDouble(double v, ByteBuffer buffer)