Class ByteBuffer


  • public class ByteBuffer
    extends Object
    Byte buffer container including length of valid data.
    Since:
    11.10.2006
    • Constructor Detail

      • ByteBuffer

        public ByteBuffer​(int initialCapacity)
        Parameters:
        initialCapacity - the initial capacity for this buffer
      • ByteBuffer

        public ByteBuffer​(byte[] buffer)
        Parameters:
        buffer - a byte array that will be wrapped with ByteBuffer.
      • ByteBuffer

        public ByteBuffer​(byte[] buffer,
                          int length)
        Parameters:
        buffer - a byte array that will be wrapped with ByteBuffer.
        length - the length of valid bytes in the array
      • ByteBuffer

        public ByteBuffer​(InputStream in)
                   throws IOException
        Loads the stream into a buffer.
        Parameters:
        in - an InputStream
        Throws:
        IOException - If the stream cannot be read.
      • ByteBuffer

        public ByteBuffer​(byte[] buffer,
                          int offset,
                          int length)
        Parameters:
        buffer - a byte array that will be wrapped with ByteBuffer.
        offset - the offset of the provided buffer.
        length - the length of valid bytes in the array
    • Method Detail

      • getByteStream

        public InputStream getByteStream()
        Returns:
        Returns a byte stream that is limited to the valid amount of bytes.
      • length

        public int length()
        Returns:
        Returns the length, that means the number of valid bytes, of the buffer; the inner byte array might be bigger than that.
      • byteAt

        public byte byteAt​(int index)
        Parameters:
        index - the index to retrieve the byte from
        Returns:
        Returns a byte from the buffer
      • charAt

        public int charAt​(int index)
        Parameters:
        index - the index to retrieve a byte as int or char.
        Returns:
        Returns a byte from the buffer
      • append

        public void append​(byte b)
        Appends a byte to the buffer.
        Parameters:
        b - a byte
      • append

        public void append​(byte[] bytes,
                           int offset,
                           int len)
        Appends a byte array or part of to the buffer.
        Parameters:
        bytes - a byte array
        offset - an offset with
        len -
      • append

        public void append​(byte[] bytes)
        Append a byte array to the buffer
        Parameters:
        bytes - a byte array
      • append

        public void append​(ByteBuffer anotherBuffer)
        Append another buffer to this buffer.
        Parameters:
        anotherBuffer - another ByteBuffer
      • getEncoding

        public String getEncoding()
        Detects the encoding of the byte buffer, stores and returns it. Only UTF-8, UTF-16LE/BE and UTF-32LE/BE are recognized. Note: UTF-32 flavors are not supported by Java, the XML-parser will complain.
        Returns:
        Returns the encoding string.