/** * Return <code>{@link #readByte()} != 0</code> * @return false if the byte read is zero, otherwise true * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ @Override public boolean readBoolean() throws IOException, EOFException { return 0 != readByte(); }
/** * Invokes the delegate's <code>read(byte[] data, int, int)</code> method. * * @param data the buffer to read the bytes into * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ @Override public void readFully( final byte[] data ) throws IOException, EOFException { readFully( data, 0, data.length ); }
/** * Reads a character delegating to {@link #readShort()}. * @return the byte read or -1 if the end of stream * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ @Override public char readChar() throws IOException, EOFException { return (char)readShort(); }
@Test public void testReadBoolean() throws IOException { bytes = new byte[] { 0x00, 0x01, 0x02, }; final ByteArrayInputStream bais = new ByteArrayInputStream( bytes ); final SwappedDataInputStream sdis = new SwappedDataInputStream( bais ); assertEquals( false, sdis.readBoolean() ); assertEquals( true, sdis.readBoolean() ); assertEquals( true, sdis.readBoolean() ); sdis.close(); }
/** * Invokes the delegate's <code>read(byte[] data, int, int)</code> method. * * @param data the buffer to read the bytes into * @param offset The start offset * @param length The number of bytes to read * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ @Override public void readFully( final byte[] data, final int offset, final int length ) throws IOException, EOFException { int remaining = length; while( remaining > 0 ) { final int location = offset + length - remaining; final int count = read( data, location, remaining ); if (EOF == count) { throw new EOFException(); } remaining -= count; } }
@Before public void setUp() { bytes = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; final ByteArrayInputStream bais = new ByteArrayInputStream( bytes ); this.sdis = new SwappedDataInputStream( bais ); }
/** @see java.io.DataInput#readFully(byte[], int, int) */ public void readFully( byte[] data, int offset, int length ) throws IOException, EOFException { int remaining = length; while( remaining > 0 ) { int location = offset + ( length - remaining ); int count = read( data, location, remaining ); if( -1 == count ) { throw new EOFException(); } remaining -= count; } }
/** @see java.io.DataInput#readBoolean() */ public boolean readBoolean() throws IOException, EOFException { return ( 0 == readByte() ); }
/** @see java.io.DataInput#readFully(byte[]) */ public void readFully( byte[] data ) throws IOException, EOFException { readFully( data, 0, data.length ); }
/** @see java.io.DataInput#readChar() */ public char readChar() throws IOException, EOFException { return (char)readShort(); }
/** * Invokes the delegate's <code>read(byte[] data, int, int)</code> method. * * @param data the buffer to read the bytes into * @param offset The start offset * @param length The number of bytes to read * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ public void readFully( byte[] data, int offset, int length ) throws IOException, EOFException { int remaining = length; while( remaining > 0 ) { int location = offset + ( length - remaining ); int count = read( data, location, remaining ); if( -1 == count ) { throw new EOFException(); } remaining -= count; } }
@Test public void testReadByte() throws IOException { assertEquals( 0x01, this.sdis.readByte() ); }
@Test public void testReadFully() throws IOException { final byte[] bytesIn = new byte[8]; this.sdis.readFully(bytesIn); for( int i=0; i<8; i++) { assertEquals( bytes[i], bytesIn[i] ); } }
@Test public void testReadShort() throws IOException { assertEquals( (short) 0x0201, this.sdis.readShort() ); }
/** * Invokes the delegate's <code>read(byte[] data, int, int)</code> method. * * @param data the buffer to read the bytes into * @param offset The start offset * @param length The number of bytes to read * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ public void readFully( final byte[] data, final int offset, final int length ) throws IOException, EOFException { int remaining = length; while( remaining > 0 ) { final int location = offset + length - remaining; final int count = read( data, location, remaining ); if (EOF == count) { throw new EOFException(); } remaining -= count; } }
/** * Return <code>{@link #readByte()} == 0</code> * @return the true if the byte read is zero, otherwise false * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ public boolean readBoolean() throws IOException, EOFException { return ( 0 == readByte() ); }
/** * Invokes the delegate's <code>read(byte[] data, int, int)</code> method. * * @param data the buffer to read the bytes into * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ public void readFully( byte[] data ) throws IOException, EOFException { readFully( data, 0, data.length ); }
/** * Reads a character delegating to {@link #readShort()}. * @return the byte read or -1 if the end of stream * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ public char readChar() throws IOException, EOFException { return (char)readShort(); }
/** * Invokes the delegate's <code>read(byte[] data, int, int)</code> method. * * @param data the buffer to read the bytes into * @param offset The start offset * @param length The number of bytes to read * @throws EOFException if an end of file is reached unexpectedly * @throws IOException if an I/O error occurs */ public void readFully( byte[] data, int offset, int length ) throws IOException, EOFException { int remaining = length; while( remaining > 0 ) { int location = offset + length - remaining; int count = read( data, location, remaining ); if( -1 == count ) { throw new EOFException(); } remaining -= count; } }
/** * Return <code>{@link #readByte()} == 0</code> * @return the true if the byte read is zero, otherwise false * @throws IOException if an I/O error occurs * @throws EOFException if an end of file is reached unexpectedly */ public boolean readBoolean() throws IOException, EOFException { return ( 0 == readByte() ); }