Class BitspeakEncoder


  • public abstract class BitspeakEncoder
    extends Object
    A bitspeak encoder. Use Bitspeak for common encode operations.

    An encoder may be acquired using Bitspeak.newEncoder(). To encode a stream of bytes, call encodeBlock(byte[], int, int, char[], int, int) repeatedly with a range of input bytes and a range of output character to a char array. The method returns the number of written characters to the output character array, use getReadCount() to determine the number of read bytes (total accumulated over the life-time of the decoder) from the byte arrays.

    Finally, call finishBlock(char[], int, int) to indicate that the stream of bytes have ended (EOF). Repeat until the finishBlock method returns negative one (-1).

    WARNING: This class is not thread safe.

    • Field Detail

      • readCount

        protected long readCount
      • writeCount

        protected long writeCount
    • Constructor Detail

      • BitspeakEncoder

        public BitspeakEncoder()
    • Method Detail

      • wrap

        public Reader wrap​(InputStream input,
                           int byteBufferSize,
                           int charBufferSize)
      • getReadCount

        public long getReadCount()
        Retrieve the total number of bytes this decoder has read
        Returns:
        The total number of read bytes.
      • getWriteCount

        public long getWriteCount()
        Retrieve the number of chracters this decoder has written.
        Returns:
        Total number of written characters.
      • encodeBlock

        public abstract int encodeBlock​(byte[] source,
                                        int sourceOffset,
                                        int sourceLength,
                                        char[] destination,
                                        int destinationOffset,
                                        int destinationLength)
        Encode the bytes in the source array as bitspeak to the given destination character array.
        Parameters:
        source - the source byte array.
        sourceOffset - the source offset.
        sourceLength - the number of bytes to read from the byte array.
        destination - the destination character array.
        destinationOffset - the starting position of the destination array.
        destinationLength - the maximum number of characters to write to the destination array.
        Returns:
        Number of encoded characters, no less than zero.
      • finishBlock

        public abstract int finishBlock​(char[] destination,
                                        int destinationOffset,
                                        int destinationLength)
        Finish encoding the written data.
        Parameters:
        destination - the destination character array.
        destinationOffset - the starting position of the destination array.
        destinationLength - the maximum number of characters to write to the destination array.
        Returns:
        Number of encoded characters, zero if we reached the end of the buffer, or -1 if the encoder is finished.