1 16 package org.apache.commons.io.input; 17 18 import java.io.DataInput ; 19 import java.io.EOFException ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 23 import org.apache.commons.io.EndianUtils; 24 25 35 public class SwappedDataInputStream extends ProxyInputStream 36 implements DataInput 37 { 38 39 44 public SwappedDataInputStream( InputStream input ) 45 { 46 super( input ); 47 } 48 49 50 public boolean readBoolean() 51 throws IOException , EOFException 52 { 53 return ( 0 == readByte() ); 54 } 55 56 57 public byte readByte() 58 throws IOException , EOFException 59 { 60 return (byte)in.read(); 61 } 62 63 64 public char readChar() 65 throws IOException , EOFException 66 { 67 return (char)readShort(); 68 } 69 70 71 public double readDouble() 72 throws IOException , EOFException 73 { 74 return EndianUtils.readSwappedDouble( in ); 75 } 76 77 78 public float readFloat() 79 throws IOException , EOFException 80 { 81 return EndianUtils.readSwappedFloat( in ); 82 } 83 84 85 public void readFully( byte[] data ) 86 throws IOException , EOFException 87 { 88 readFully( data, 0, data.length ); 89 } 90 91 92 public void readFully( byte[] data, int offset, int length ) 93 throws IOException , EOFException 94 { 95 int remaining = length; 96 97 while( remaining > 0 ) 98 { 99 int location = offset + ( length - remaining ); 100 int count = read( data, location, remaining ); 101 102 if( -1 == count ) 103 { 104 throw new EOFException (); 105 } 106 107 remaining -= count; 108 } 109 } 110 111 112 public int readInt() 113 throws IOException , EOFException 114 { 115 return EndianUtils.readSwappedInteger( in ); 116 } 117 118 123 public String readLine() 124 throws IOException , EOFException 125 { 126 throw new UnsupportedOperationException ( 127 "Operation not supported: readLine()" ); 128 } 129 130 131 public long readLong() 132 throws IOException , EOFException 133 { 134 return EndianUtils.readSwappedLong( in ); 135 } 136 137 138 public short readShort() 139 throws IOException , EOFException 140 { 141 return EndianUtils.readSwappedShort( in ); 142 } 143 144 145 public int readUnsignedByte() 146 throws IOException , EOFException 147 { 148 return in.read(); 149 } 150 151 152 public int readUnsignedShort() 153 throws IOException , EOFException 154 { 155 return EndianUtils.readSwappedUnsignedShort( in ); 156 } 157 158 163 public String readUTF() 164 throws IOException , EOFException 165 { 166 throw new UnsupportedOperationException ( 167 "Operation not supported: readUTF()" ); 168 } 169 170 171 public int skipBytes( int count ) 172 throws IOException , EOFException 173 { 174 return (int)in.skip( count ); 175 } 176 177 } 178 | Popular Tags |