Package com.igormaznitsa.jbbp.io
Class JBBPBitOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
com.igormaznitsa.jbbp.io.JBBPBitOutputStream
- All Implemented Interfaces:
JBBPCountableBitStream,Closeable,Flushable,AutoCloseable
The Filter allows to write bit by bit into an output stream and count the written byte number. The Class is not a thread-safe one.
- Since:
- 1.0
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionA Constructor.JBBPBitOutputStream(OutputStream out, JBBPBitOrder order) A Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidalign(long alignByteNumber) Write padding bytes to align the stream counter for the border.voidclose()voidflush()intGet the inside bit buffer value.Get the bit mode for writing operations.intGet the number of bits cached in the inside bit buffer.longGet number of bytes written into the output stream.voidReset the byte counter for the stream.voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int value) voidwriteBits(int value, JBBPBitNumber bitNumber) Write bits into the output stream.voidwriteBytes(byte[] array, int length, JBBPByteOrder byteOrder) Write number of items from byte array into streamvoidwriteDouble(double value, JBBPByteOrder byteOrder) Write a double value into the output stream.voidwriteFloat(float value, JBBPByteOrder byteOrder) Write a float value into the output stream.voidwriteInt(int value, JBBPByteOrder byteOrder) Write an integer value into the output stream.voidwriteLong(long value, JBBPByteOrder byteOrder) Write a long value into the output stream.voidwriteShort(int value, JBBPByteOrder byteOrder) Write a signed short value into the output stream.voidwriteString(String value, JBBPByteOrder order) Write string in UTF8 format into stream.voidwriteStringArray(String[] value, JBBPByteOrder order) Write array of strings in stream in UTF8 format the byte order in saved char data will be BIG_ENDIANvoidwriteUInt(long value, JBBPByteOrder byteOrder) Write an unsigned integer value into the output stream.Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
JBBPBitOutputStream
A Constructor. The Default LSB0 bit mode will be used for a bit writing operations.- Parameters:
out- the output stream to be filtered.
-
JBBPBitOutputStream
A Constructor.- Parameters:
out- an output stream to be filtered.order- a bit writing mode to used for writing operations.- See Also:
-
-
Method Details
-
getBitOrder
Get the bit mode for writing operations.- Specified by:
getBitOrderin interfaceJBBPCountableBitStream- Returns:
- the bit order for reading operations.
- See Also:
-
writeShort
Write a signed short value into the output stream.- Parameters:
value- a value to be written. Only two bytes will be written.byteOrder- the byte order of the value bytes to be used for writing.- Throws:
IOException- it will be thrown for transport errors- See Also:
-
writeInt
Write an integer value into the output stream.- Parameters:
value- a value to be written into the output stream.byteOrder- the byte order of the value bytes to be used for writing.- Throws:
IOException- it will be thrown for transport errors- See Also:
-
writeUInt
Write an unsigned integer value into the output stream.- Parameters:
value- a value to be written into the output stream.byteOrder- the byte order of the value bytes to be used for writing.- Throws:
IOException- it will be thrown for transport errors- Since:
- 2.0.4
- See Also:
-
writeFloat
Write a float value into the output stream.- Parameters:
value- a value to be written into the output stream.byteOrder- the byte order of the value bytes to be used for writing.- Throws:
IOException- it will be thrown for transport errors- Since:
- 1.4.0
- See Also:
-
writeLong
Write a long value into the output stream.- Parameters:
value- a value to be written into the output stream.byteOrder- the byte order of the value bytes to be used for writing.- Throws:
IOException- it will be thrown for transport errors- See Also:
-
writeDouble
Write a double value into the output stream.- Parameters:
value- a value to be written into the output stream.byteOrder- the byte order of the value bytes to be used for writing.- Throws:
IOException- it will be thrown for transport errors- Since:
- 1.4.0
- See Also:
-
getCounter
public long getCounter()Get number of bytes written into the output stream.- Specified by:
getCounterin interfaceJBBPCountableBitStream- Returns:
- the long value contains number of bytes written into the stream
-
getBitBuffer
public int getBitBuffer()Get the inside bit buffer value.- Specified by:
getBitBufferin interfaceJBBPCountableBitStream- Returns:
- the inside bit buffer value
-
getBufferedBitsNumber
public int getBufferedBitsNumber()Get the number of bits cached in the inside bit buffer.- Specified by:
getBufferedBitsNumberin interfaceJBBPCountableBitStream- Returns:
- the number of cached bits in the bit buffer
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
writeBits
Write bits into the output stream.- Parameters:
value- the value which bits will be written in the output streambitNumber- number of bits from the value to be written, must be in 1..8- Throws:
IOException- it will be thrown for transport errorsIllegalArgumentException- it will be thrown for wrong bit number
-
align
Write padding bytes to align the stream counter for the border.- Parameters:
alignByteNumber- the alignment border- Throws:
IOException- it will be thrown for transport errors
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
writeBytes
Write number of items from byte array into stream- Parameters:
array- array, must not be nulllength- number of items to be written, if -1 then whole arraybyteOrder- order of bytes, if LITTLE_ENDIAN then array will be reversed- Throws:
IOException- it will be thrown if any transport error- Since:
- 1.3.0
- See Also:
-
resetCounter
public void resetCounter()Reset the byte counter for the stream. The Inside bit buffer will be reset also.- Specified by:
resetCounterin interfaceJBBPCountableBitStream
-
writeString
Write string in UTF8 format into stream. the byte order in saved char data will be BIG_ENDIAN Format: PREFIX(FF=null | 0=empty | 0x8packedLength) LENGTH[packedLength] DATA_ARRAY[LENGTH]- Parameters:
value- string to be written, can be nullorder- order of bytes in written data (it doesn't affect encoded UTF8 array)- Throws:
IOException- i twill be thrown if transport error- Since:
- 1.4.0
-
writeStringArray
Write array of strings in stream in UTF8 format the byte order in saved char data will be BIG_ENDIAN- Parameters:
value- array to be written, must not be null but can contain null valuesorder- byte order to write char data, must not be null- Throws:
IOException- it will be thrown for transport errors- Since:
- 1.4.0
- See Also:
-