FileDocCategorySizeDatePackage
SwappedDataInputStream.javaAPI DocAndroid 1.5 API8199Wed May 06 22:42:46 BST 2009org.apache.commons.io.input

SwappedDataInputStream

public class SwappedDataInputStream extends ProxyInputStream implements DataInput
DataInput for systems relying on little endian data formats. When read, values will be changed from little endian to big endian formats for internal usage.

Origin of code: Avalon Excalibur (IO)

author
Peter Donald
version
CVS $Revision: 610010 $ $Date: 2008-01-08 14:50:59 +0000 (Tue, 08 Jan 2008) $

Fields Summary
Constructors Summary
public SwappedDataInputStream(InputStream input)
Constructs a SwappedDataInputStream.

param
input InputStream to read from

        super( input );
    
Methods Summary
public booleanreadBoolean()
Return {@link #readByte()} == 0

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

        return ( 0 == readByte() );
    
public bytereadByte()
Invokes the delegate's read() method.

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

        return (byte)in.read();
    
public charreadChar()
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

        return (char)readShort();
    
public doublereadDouble()
Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}.

return
the read long
throws
IOException if an I/O error occurs
throws
EOFException if an end of file is reached unexpectedly

        return EndianUtils.readSwappedDouble( in );
    
public floatreadFloat()
Delegates to {@link EndianUtils#readSwappedFloat(InputStream)}.

return
the read long
throws
IOException if an I/O error occurs
throws
EOFException if an end of file is reached unexpectedly

        return EndianUtils.readSwappedFloat( in );
    
public voidreadFully(byte[] data)
Invokes the delegate's read(byte[] data, int, int) 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

        readFully( data, 0, data.length );
    
public voidreadFully(byte[] data, int offset, int length)
Invokes the delegate's read(byte[] data, int, int) 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

        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;
        }
    
public intreadInt()
Delegates to {@link EndianUtils#readSwappedInteger(InputStream)}.

return
the read long
throws
EOFException if an end of file is reached unexpectedly
throws
IOException if an I/O error occurs

        return EndianUtils.readSwappedInteger( in );
    
public java.lang.StringreadLine()
Not currently supported - throws {@link UnsupportedOperationException}.

return
the line read
throws
EOFException if an end of file is reached unexpectedly
throws
IOException if an I/O error occurs

        throw new UnsupportedOperationException( 
                "Operation not supported: readLine()" );
    
public longreadLong()
Delegates to {@link EndianUtils#readSwappedLong(InputStream)}.

return
the read long
throws
EOFException if an end of file is reached unexpectedly
throws
IOException if an I/O error occurs

        return EndianUtils.readSwappedLong( in );
    
public shortreadShort()
Delegates to {@link EndianUtils#readSwappedShort(InputStream)}.

return
the read long
throws
EOFException if an end of file is reached unexpectedly
throws
IOException if an I/O error occurs

        return EndianUtils.readSwappedShort( in );
    
public java.lang.StringreadUTF()
Not currently supported - throws {@link UnsupportedOperationException}.

return
UTF String read
throws
EOFException if an end of file is reached unexpectedly
throws
IOException if an I/O error occurs

        throw new UnsupportedOperationException( 
                "Operation not supported: readUTF()" );
    
public intreadUnsignedByte()
Invokes the delegate's read() method.

return
the byte read or -1 if the end of stream
throws
EOFException if an end of file is reached unexpectedly
throws
IOException if an I/O error occurs

        return in.read();
    
public intreadUnsignedShort()
Delegates to {@link EndianUtils#readSwappedUnsignedShort(InputStream)}.

return
the read long
throws
EOFException if an end of file is reached unexpectedly
throws
IOException if an I/O error occurs

        return EndianUtils.readSwappedUnsignedShort( in );
    
public intskipBytes(int count)
Invokes the delegate's skip(int) method.

param
count the number of bytes to skip
return
the number of bytes to skipped or -1 if the end of stream
throws
EOFException if an end of file is reached unexpectedly
throws
IOException if an I/O error occurs

        return (int)in.skip( count );