Package com.comphenix.bitspeak
Class BitspeakDecoder
- java.lang.Object
-
- com.comphenix.bitspeak.BitspeakDecoder
-
public abstract class BitspeakDecoder extends Object
A bitspeak decoder. UseBitspeak
for common decode operations.A decoder may be acquired using
Bitspeak.newDecoder()
. To decode a stream of characters, calldecodeBlock(char[], int, int, byte[], int, int)
repeatedly with a range of input characters and a range of output bytes to a byte array. The method returns the number of written bytes in the byte array, usegetReadCount()
to determine the number of read characters (total accumulated) from the character array.Finally, call
finishBlock(byte[], int, int)
to indicate that the stream of characters have ended (EOF). Repeat until the finishBlock method returns negative one (-1).WARNING: This class is not thread safe.
-
-
Field Summary
Fields Modifier and Type Field Description protected long
readCount
protected long
writeCount
-
Constructor Summary
Constructors Constructor Description BitspeakDecoder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
decodeBlock(char[] source, int sourceOffset, int sourceLength, byte[] destination, int destinationOffset, int destinationLength)
Decode the bitspeak in the given source array to the given destination byte array.int
decodeFinal(char[] source, byte[] destination)
Decode the bitspeak in the given source array to the given destination byte array, as a final block.abstract int
finishBlock(byte[] destination, int destinationOffset, int destinationLength)
Finish decoding a stream of bitspeak content, writing the final output to the given destination.long
getReadCount()
Retrieve the total number of character this decoder has readlong
getWriteCount()
Retrieve the number of bytes this decoder has written.InputStream
wrap(Reader input, int byteBufferSize, int charBufferSize)
Create an input stream wrapping the given character input.
-
-
-
Method Detail
-
wrap
public InputStream wrap(Reader input, int byteBufferSize, int charBufferSize)
Create an input stream wrapping the given character input.- Parameters:
input
- the input.byteBufferSize
- the byte buffer size.charBufferSize
- the char buffer size.- Returns:
- The corresponding input stream.
-
getReadCount
public long getReadCount()
Retrieve the total number of character this decoder has read- Returns:
- The total number of read characters.
-
getWriteCount
public long getWriteCount()
Retrieve the number of bytes this decoder has written.- Returns:
- Total number of written bytes.
-
decodeFinal
public int decodeFinal(char[] source, byte[] destination)
Decode the bitspeak in the given source array to the given destination byte array, as a final block.- Parameters:
source
- the source character array with the bitspeak content.destination
- the destination byte array.- Returns:
- Number of decoded bytes.
-
decodeBlock
public abstract int decodeBlock(char[] source, int sourceOffset, int sourceLength, byte[] destination, int destinationOffset, int destinationLength)
Decode the bitspeak in the given source array to the given destination byte array.- Parameters:
source
- the source character array with the bitspeak content.sourceOffset
- the source offset.sourceLength
- the number of source characters to read from the character array.destination
- the destination byte array.destinationOffset
- the starting position of the destination array.destinationLength
- the maximum number of bytes to write to the destination array.- Returns:
- Number of decoded bytes, no less than zero.
-
finishBlock
public abstract int finishBlock(byte[] destination, int destinationOffset, int destinationLength)
Finish decoding a stream of bitspeak content, writing the final output to the given destination.- Parameters:
destination
- the destination byte array.destinationOffset
- the starting position of the destination array.destinationLength
- the maximum number of bytes to write to the destination array.- Returns:
- Number of decoded bytes, zero if we reached the end of the buffer, or -1 if the decoder is finished.
-
-