Class CodeStream


  • public final class CodeStream
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] _data
      The content of this stream.
      private int _length
      Actual number of bytes in this stream.
      private static int DEFAULT_SIZE  
    • Constructor Summary

      Constructors 
      Constructor Description
      CodeStream()
      Constructs a new CodeStream with a default initial size.
      CodeStream​(int initialSize)
      Constructs a new CodeStream with the given initial size.
    • Field Detail

      • _data

        private byte[] _data
        The content of this stream.
      • _length

        private int _length
        Actual number of bytes in this stream.
    • Constructor Detail

      • CodeStream

        public CodeStream()
        Constructs a new CodeStream with a default initial size.
      • CodeStream

        public CodeStream​(int initialSize)
        Constructs a new CodeStream with the given initial size.
        Parameters:
        initialSize - the initial size of the byte stream to be constructed.
    • Method Detail

      • reset

        public void reset()
      • reset

        public void reset​(int initialSize)
      • getData

        public byte[] getData()
      • getLength

        public int getLength()
      • putByte

        public CodeStream putByte​(int b)
        Puts a byte into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        b - a byte.
        Returns:
        this byte stream.
      • put11

        CodeStream put11​(int b1,
                         int b2)
        Puts two bytes into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        b1 - a byte.
        b2 - another byte.
        Returns:
        this byte stream.
      • putShort

        public CodeStream putShort​(int s)
        Puts a short into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        s - a short.
        Returns:
        this byte stream.
      • put12

        CodeStream put12​(int b,
                         int s)
        Puts a byte and a short into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        b - a byte.
        s - a short.
        Returns:
        this byte stream.
      • putInt

        public CodeStream putInt​(int i)
        Puts an int into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        i - an int.
        Returns:
        this byte stream.
      • putLong

        public CodeStream putLong​(long l)
        Puts a long into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        l - a long.
        Returns:
        this byte stream.
      • putFloat

        public CodeStream putFloat​(float f)
        Puts a float into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        f - a float.
        Returns:
        this byte stream.
      • putDouble

        public CodeStream putDouble​(double d)
        Puts a double into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        d - a double.
        Returns:
        this byte stream.
      • putUtf8

        public CodeStream putUtf8​(java.lang.String s)
        Puts an UTF8 string into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        s - a String.
        Returns:
        this byte stream.
      • putByteArray

        public CodeStream putByteArray​(byte[] b,
                                       int offset,
                                       int length)
        Puts an array of bytes into this byte stream. The byte stream is automatically enlarged if necessary.
        Parameters:
        b - an array of bytes. May be null to put length null bytes into this byte stream.
        offset - index of the fist byte of b that must be copied.
        length - number of bytes of b that must be copied.
        Returns:
        this byte stream.
      • ensureCapacity

        void ensureCapacity​(int size)
        Enlarge this byte stream so that it can receive n more bytes.
        Parameters:
        size - number of additional bytes that this byte stream should be able to receive.