Class ByteBuffer


  • public class ByteBuffer
    extends java.lang.Object
    Byte buffer container including length of valid data.
    Since:
    11.10.2006
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] buffer  
      private java.lang.String encoding  
      private int length  
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteBuffer​(byte[] buffer)  
      ByteBuffer​(byte[] buffer, int length)  
      ByteBuffer​(byte[] buffer, int offset, int length)  
      ByteBuffer​(int initialCapacity)  
      ByteBuffer​(java.io.InputStream in)
      Loads the stream into a buffer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void append​(byte b)
      Appends a byte to the buffer.
      void append​(byte[] bytes)
      Append a byte array to the buffer
      void append​(byte[] bytes, int offset, int len)
      Appends a byte array or part of to the buffer.
      void append​(ByteBuffer anotherBuffer)
      Append another buffer to this buffer.
      byte byteAt​(int index)  
      int charAt​(int index)  
      private void ensureCapacity​(int requestedLength)
      Ensures the requested capacity by increasing the buffer size when the current length is exceeded.
      java.io.InputStream getByteStream()  
      java.lang.String getEncoding()
      Detects the encoding of the byte buffer, stores and returns it.
      int length()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • buffer

        private byte[] buffer
      • length

        private int length
      • encoding

        private java.lang.String encoding
    • 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​(java.io.InputStream in)
                   throws java.io.IOException
        Loads the stream into a buffer.
        Parameters:
        in - an InputStream
        Throws:
        java.io.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 java.io.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 java.lang.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.
      • ensureCapacity

        private void ensureCapacity​(int requestedLength)
        Ensures the requested capacity by increasing the buffer size when the current length is exceeded.
        Parameters:
        requestedLength - requested new buffer length