Package ej.ecom.io
Interface BitsOutput
-
public interface BitsOutputThis interface defines methods for writing data bits.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intgetLength()Returns the data length in bits (1 to 32 bits).voidwriteBits(byte[] data, boolean signExtends)Writesdata.lengthdata from the specified short array to this output stream.voidwriteBits(byte[] data, int off, int len, boolean signExtends)Writeslendata from the specified short array starting at offsetoffto this output stream.voidwriteBits(int val)The data to send is masked using the following formula:
val &= (1 << getLength()) - 1voidwriteBits(int[] data)Writesdata.lengthdata from the specified integer array to this output stream.voidwriteBits(int[] data, int off, int len)Writeslendata from the specified integer array starting at offsetoffto this output stream.voidwriteBits(short[] data, boolean signExtends)Writesdata.lengthdata from the specified short array to this output stream.voidwriteBits(short[] data, int off, int len, boolean signExtends)Writeslendata from the specified short array starting at offsetoffto this output stream.
-
-
-
Method Detail
-
getLength
int getLength()
Returns the data length in bits (1 to 32 bits).- Returns:
- the data length in bits (1 to 32 bits).
-
writeBits
void writeBits(int val) throws IOExceptionThe data to send is masked using the following formula:
val &= (1 << getLength()) - 1- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
writeBits
void writeBits(int[] data) throws IOExceptionWritesdata.lengthdata from the specified integer array to this output stream. The general contract forwriteBits(data)is that it should have exactly the same effect as the callwriteBits(data, 0, data.length).- Parameters:
data- the data to send- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
writeBits
void writeBits(int[] data, int off, int len) throws IOExceptionWriteslendata from the specified integer array starting at offsetoffto this output stream. The general contract forwriteBits(b, off, len)is that some of the data in the arraydataare written to the output stream in order; elementdata[off]is the first byte written andb[off+len-1]is the last data written by this operation.
Thewritemethod ofOutputStreamcalls thewritemethod of one argument on each of the data to be written out. Subclasses are encouraged to override this method and provide a more efficient implementation.
Ifdatais null, aNullPointerExceptionis thrown.
Ifoffis negative, orlenis negative, oroff+lenis greater than the length of the arraydata, then anIndexOutOfBoundsExceptionis thrown.- Parameters:
data- the data to sendoff- the start offset in the data.len- the number of data to write.- Throws:
IOException- if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
-
writeBits
void writeBits(short[] data, boolean signExtends) throws IOExceptionWritesdata.lengthdata from the specified short array to this output stream. The general contract forwriteBits(data, signExtends)is that it should have exactly the same effect as the callwriteBits(b, 0, b.length, signExtends).- Parameters:
data- the data to sendsignExtends- true to sign-extend the data in case ofgetLength()> 16 (shortsize)- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
writeBits
void writeBits(short[] data, int off, int len, boolean signExtends) throws IOExceptionWriteslendata from the specified short array starting at offsetoffto this output stream. The general contract forwriteBits(b, off, len, signExtends)is that some of the data in the arraydataare written to the output stream in order; elementdata[off]is the first byte written andb[off+len-1]is the last data written by this operation.
Thewritemethod ofOutputStreamcalls thewritemethod of one argument on each of the data to be written out. Subclasses are encouraged to override this method and provide a more efficient implementation.
Ifdatais null, aNullPointerExceptionis thrown.
Ifoffis negative, orlenis negative, oroff+lenis greater than the length of the arraydata, then anIndexOutOfBoundsExceptionis thrown.
IfgetLength()is higher than 16 (shortsize), the data will are sign extended or not accordingsignExtendsboolean.- Parameters:
data- the data to sendoff- the start offset in the data.len- the number of data to write.signExtends- true to sign-extend the data in case ofgetLength()> 16 (shortsize)- Throws:
IOException- if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
-
writeBits
void writeBits(byte[] data, boolean signExtends) throws IOExceptionWritesdata.lengthdata from the specified short array to this output stream. The general contract forwriteBits(data, signExtends)is that it should have exactly the same effect as the callwriteBits(b, 0, b.length, signExtends).- Parameters:
data- the data to sendsignExtends- true to sign-extend the data in case ofgetLength()> 8 (bytesize)- Throws:
IOException- if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.
-
writeBits
void writeBits(byte[] data, int off, int len, boolean signExtends) throws IOExceptionWriteslendata from the specified short array starting at offsetoffto this output stream. The general contract forwriteBits(b, off, len, signExtends)is that some of the data in the arraydataare written to the output stream in order; elementdata[off]is the first byte written andb[off+len-1]is the last data written by this operation.
Thewritemethod ofOutputStreamcalls thewritemethod of one argument on each of the data to be written out. Subclasses are encouraged to override this method and provide a more efficient implementation.
Ifdatais null, aNullPointerExceptionis thrown.
Ifoffis negative, orlenis negative, oroff+lenis greater than the length of the arraydata, then anIndexOutOfBoundsExceptionis thrown.
IfgetLength()is higher than 8 (bytesize), the data will are sign extended or not accordingsignExtendsboolean.- Parameters:
data- the data to sendoff- the start offset in the data.len- the number of data to write.signExtends- true to sign-extend the data in case ofgetLength()> 8 (bytesize)- Throws:
IOException- if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.
-
-