Package com.comphenix.bitspeak
Class BitspeakEncoder
- java.lang.Object
-
- com.comphenix.bitspeak.BitspeakEncoder
-
public abstract class BitspeakEncoder extends Object
A bitspeak encoder. UseBitspeak
for common encode operations.An encoder may be acquired using
Bitspeak.newEncoder()
. To encode a stream of bytes, callencodeBlock(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, usegetReadCount()
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 Summary
Fields Modifier and Type Field Description protected long
readCount
protected long
writeCount
-
Constructor Summary
Constructors Constructor Description BitspeakEncoder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.abstract int
finishBlock(char[] destination, int destinationOffset, int destinationLength)
Finish encoding the written data.long
getReadCount()
Retrieve the total number of bytes this decoder has readlong
getWriteCount()
Retrieve the number of chracters this decoder has written.Reader
wrap(InputStream input, int byteBufferSize, int charBufferSize)
-
-
-
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.
-
-