Apache Tomcat 7.0.67
org.apache.catalina.tribes.io

Class XByteBuffer

    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected byte[] buf
      Variable to hold the data
      protected int bufSize
      Current length of data in the buffer
      protected boolean discard
      Flag for discarding invalid packages If this flag is set to true, and append(byte[],...) is called, the data added will be inspected, and if it doesn't start with START_DATA it will be thrown away.
    • Constructor Summary

      Constructors 
      Constructor and Description
      XByteBuffer(byte[] data, boolean discard) 
      XByteBuffer(byte[] data, int size, boolean discard) 
      XByteBuffer(int size, boolean discard)
      Constructs a new XByteBuffer.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      boolean append(boolean i) 
      boolean append(byte i) 
      boolean append(byte[] b, int off, int len) 
      boolean append(java.nio.ByteBuffer b, int len)
      Appends the data to the buffer.
      boolean append(int i) 
      boolean append(long i) 
      void clear()
      Resets the buffer
      int countPackages()
      Internal mechanism to make a check if a complete package exists within the buffer
      int countPackages(boolean first) 
      static byte[] createDataPackage(byte[] data) 
      static byte[] createDataPackage(byte[] data, int doff, int dlength, byte[] buffer, int bufoff) 
      static byte[] createDataPackage(ChannelData cdata)
      Creates a complete data package
      static java.io.Serializable deserialize(byte[] data) 
      static java.io.Serializable deserialize(byte[] data, int offset, int length) 
      static java.io.Serializable deserialize(byte[] data, int offset, int length, java.lang.ClassLoader[] cls) 
      boolean doesPackageExist()
      Method to check if a package exists in this byte buffer.
      void expand(int newcount) 
      XByteBuffer extractDataPackage(boolean clearFromBuffer)
      Extracts the message bytes from a package.
      ChannelData extractPackage(boolean clearFromBuffer) 
      static int firstIndexOf(byte[] src, int srcOff, byte[] find)
      Similar to a String.IndexOf, but uses pure bytes
      byte[] getBytes()
      Returns the bytes in the buffer, in its exact length
      byte[] getBytesDirect() 
      int getCapacity() 
      static int getDataPackageLength(int datalength) 
      boolean getDiscard() 
      int getLength() 
      void reset() 
      static byte[] serialize(java.io.Serializable msg)
      Serializes a message into cluster data
      void setDiscard(boolean discard) 
      void setLength(int size) 
      static boolean toBoolean(byte[] b, int offset)
      Converts a byte array entry to boolean
      static byte[] toBytes(boolean bool)
      Deprecated. 
      use toBytes(boolean,byte[],int)
      static byte[] toBytes(boolean bool, byte[] data, int offset) 
      static byte[] toBytes(int n)
      Deprecated. 
      use toBytes(int,byte[],int)
      static byte[] toBytes(int n, byte[] b, int offset) 
      static byte[] toBytes(long n)
      Deprecated. 
      use toBytes(long,byte[],int)
      static byte[] toBytes(long n, byte[] b, int offset) 
      static int toInt(byte[] b, int off)
      Convert four bytes to an int
      static long toLong(byte[] b, int off)
      Convert eight bytes to a long
      void trim(int length) 
      • Methods inherited from class java.lang.Object

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

      • buf

        protected byte[] buf
        Variable to hold the data
      • bufSize

        protected int bufSize
        Current length of data in the buffer
      • discard

        protected boolean discard
        Flag for discarding invalid packages If this flag is set to true, and append(byte[],...) is called, the data added will be inspected, and if it doesn't start with START_DATA it will be thrown away.
    • Constructor Detail

      • XByteBuffer

        public XByteBuffer(int size,
                   boolean discard)
        Constructs a new XByteBuffer.
        TODO use a pool of byte[] for performance
        Parameters:
        size - - the initial size of the byte buffer
      • XByteBuffer

        public XByteBuffer(byte[] data,
                   boolean discard)
      • XByteBuffer

        public XByteBuffer(byte[] data,
                   int size,
                   boolean discard)
    • Method Detail

      • getLength

        public int getLength()
      • setLength

        public void setLength(int size)
      • trim

        public void trim(int length)
      • reset

        public void reset()
      • getBytesDirect

        public byte[] getBytesDirect()
      • getBytes

        public byte[] getBytes()
        Returns the bytes in the buffer, in its exact length
      • clear

        public void clear()
        Resets the buffer
      • append

        public boolean append(java.nio.ByteBuffer b,
                     int len)
        Appends the data to the buffer. If the data is incorrectly formatted, ie, the data should always start with the header, false will be returned and the data will be discarded.
        Parameters:
        b - - bytes to be appended
        len - - the number of bytes to append.
        Returns:
        true if the data was appended correctly. Returns false if the package is incorrect, ie missing header or something, or the length of data is 0
      • append

        public boolean append(byte i)
      • append

        public boolean append(boolean i)
      • append

        public boolean append(long i)
      • append

        public boolean append(int i)
      • append

        public boolean append(byte[] b,
                     int off,
                     int len)
      • expand

        public void expand(int newcount)
      • getCapacity

        public int getCapacity()
      • countPackages

        public int countPackages()
        Internal mechanism to make a check if a complete package exists within the buffer
        Returns:
        - true if a complete package (header,compress,size,data,footer) exists within the buffer
      • countPackages

        public int countPackages(boolean first)
      • doesPackageExist

        public boolean doesPackageExist()
        Method to check if a package exists in this byte buffer.
        Returns:
        - true if a complete package (header,options,size,data,footer) exists within the buffer
      • extractDataPackage

        public XByteBuffer extractDataPackage(boolean clearFromBuffer)
        Extracts the message bytes from a package. If no package exists, a IllegalStateException will be thrown.
        Parameters:
        clearFromBuffer - - if true, the package will be removed from the byte buffer
        Returns:
        - returns the actual message bytes (header, compress,size and footer not included).
      • extractPackage

        public ChannelData extractPackage(boolean clearFromBuffer)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • createDataPackage

        public static byte[] createDataPackage(ChannelData cdata)
        Creates a complete data package
        Parameters:
        cdata - - the message data to be contained within the package
        Returns:
        - a full package (header,size,data,footer)
      • createDataPackage

        public static byte[] createDataPackage(byte[] data,
                               int doff,
                               int dlength,
                               byte[] buffer,
                               int bufoff)
      • getDataPackageLength

        public static int getDataPackageLength(int datalength)
      • createDataPackage

        public static byte[] createDataPackage(byte[] data)
      • toInt

        public static int toInt(byte[] b,
                int off)
        Convert four bytes to an int
        Parameters:
        b - - the byte array containing the four bytes
        off - - the offset
        Returns:
        the integer value constructed from the four bytes
        Throws:
        java.lang.ArrayIndexOutOfBoundsException
      • toLong

        public static long toLong(byte[] b,
                  int off)
        Convert eight bytes to a long
        Parameters:
        b - - the byte array containing the four bytes
        off - - the offset
        Returns:
        the long value constructed from the eight bytes
        Throws:
        java.lang.ArrayIndexOutOfBoundsException
      • toBytes

        @Deprecated
        public static byte[] toBytes(boolean bool)
        Deprecated. use toBytes(boolean,byte[],int)
        Converts a boolean to a 1-byte array
        Parameters:
        bool - - the integer
        Returns:
        - 1-byte array
      • toBytes

        public static byte[] toBytes(boolean bool,
                     byte[] data,
                     int offset)
      • toBoolean

        public static boolean toBoolean(byte[] b,
                        int offset)
        Converts a byte array entry to boolean
        Parameters:
        b - byte array
        offset - within byte array
        Returns:
        true if byte array entry is non-zero, false otherwise
      • toBytes

        @Deprecated
        public static byte[] toBytes(int n)
        Deprecated. use toBytes(int,byte[],int)
        Converts an integer to four bytes
        Parameters:
        n - - the integer
        Returns:
        - four bytes in an array
      • toBytes

        public static byte[] toBytes(int n,
                     byte[] b,
                     int offset)
      • toBytes

        @Deprecated
        public static byte[] toBytes(long n)
        Deprecated. use toBytes(long,byte[],int)
        Converts an long to eight bytes
        Parameters:
        n - - the long
        Returns:
        - eight bytes in an array
      • toBytes

        public static byte[] toBytes(long n,
                     byte[] b,
                     int offset)
      • firstIndexOf

        public static int firstIndexOf(byte[] src,
                       int srcOff,
                       byte[] find)
        Similar to a String.IndexOf, but uses pure bytes
        Parameters:
        src - - the source bytes to be searched
        srcOff - - offset on the source buffer
        find - - the string to be found within src
        Returns:
        - the index of the first matching byte. -1 if the find array is not found
      • deserialize

        public static java.io.Serializable deserialize(byte[] data)
                                                throws java.io.IOException,
                                                       java.lang.ClassNotFoundException,
                                                       java.lang.ClassCastException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
        java.lang.ClassCastException
      • deserialize

        public static java.io.Serializable deserialize(byte[] data,
                                       int offset,
                                       int length)
                                                throws java.io.IOException,
                                                       java.lang.ClassNotFoundException,
                                                       java.lang.ClassCastException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
        java.lang.ClassCastException
      • deserialize

        public static java.io.Serializable deserialize(byte[] data,
                                       int offset,
                                       int length,
                                       java.lang.ClassLoader[] cls)
                                                throws java.io.IOException,
                                                       java.lang.ClassNotFoundException,
                                                       java.lang.ClassCastException
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
        java.lang.ClassCastException
      • serialize

        public static byte[] serialize(java.io.Serializable msg)
                                throws java.io.IOException
        Serializes a message into cluster data
        Parameters:
        msg - ClusterMessage
        Returns:
        serialized content as byte[] array
        Throws:
        java.io.IOException
      • setDiscard

        public void setDiscard(boolean discard)
      • getDiscard

        public boolean getDiscard()
Apache Tomcat 7.0.67

Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.