1 50 package org.apache.avalon.excalibur.io; 51 52 import java.io.DataInput ; 53 import java.io.EOFException ; 54 import java.io.IOException ; 55 import java.io.InputStream ; 56 57 64 public class SwappedDataInputStream 65 implements DataInput 66 { 67 private InputStream m_input; 69 70 public SwappedDataInputStream( final InputStream input ) 71 { 72 m_input = input; 73 } 74 75 public boolean readBoolean() 76 throws IOException , EOFException 77 { 78 return ( 0 == readByte() ); 79 } 80 81 public byte readByte() 82 throws IOException , EOFException 83 { 84 return (byte)m_input.read(); 85 } 86 87 public char readChar() 88 throws IOException , EOFException 89 { 90 return (char)readShort(); 91 } 92 93 public double readDouble() 94 throws IOException , EOFException 95 { 96 return EndianUtil.readSwappedDouble( m_input ); 97 } 98 99 public float readFloat() 100 throws IOException , EOFException 101 { 102 return EndianUtil.readSwappedFloat( m_input ); 103 } 104 105 public void readFully( final byte[] data ) 106 throws IOException , EOFException 107 { 108 readFully( data, 0, data.length ); 109 } 110 111 public void readFully( final byte[] data, final int offset, final int length ) 112 throws IOException , EOFException 113 { 114 int remaining = length; 115 116 while( remaining > 0 ) 117 { 118 final int location = offset + ( length - remaining ); 119 final int count = read( data, location, remaining ); 120 121 if( -1 == count ) 122 { 123 throw new EOFException (); 124 } 125 126 remaining -= count; 127 } 128 } 129 130 public int readInt() 131 throws IOException , EOFException 132 { 133 return EndianUtil.readSwappedInteger( m_input ); 134 } 135 136 public String readLine() 137 throws IOException , EOFException 138 { 139 throw new IOException ( "Operation not supported" ); 140 } 141 142 public long readLong() 143 throws IOException , EOFException 144 { 145 return EndianUtil.readSwappedLong( m_input ); 146 } 147 148 public short readShort() 149 throws IOException , EOFException 150 { 151 return EndianUtil.readSwappedShort( m_input ); 152 } 153 154 public int readUnsignedByte() 155 throws IOException , EOFException 156 { 157 return m_input.read(); 158 } 159 160 public int readUnsignedShort() 161 throws IOException , EOFException 162 { 163 return EndianUtil.readSwappedUnsignedShort( m_input ); 164 } 165 166 public String readUTF() 167 throws IOException , EOFException 168 { 169 throw new IOException ( "Operation not supported" ); 170 } 171 172 public int skipBytes( final int count ) 173 throws IOException , EOFException 174 { 175 return (int)m_input.skip( count ); 176 } 177 178 public int available() 179 throws IOException , EOFException 180 { 181 return m_input.available(); 182 } 183 184 public void close() 185 throws IOException , EOFException 186 { 187 m_input.close(); 188 } 189 190 public int read() 191 throws IOException , EOFException 192 { 193 return m_input.read(); 194 } 195 196 public int read( final byte[] data ) 197 throws IOException , EOFException 198 { 199 return read( data, 0, data.length ); 200 } 201 202 public int read( final byte[] data, final int offset, final int length ) 203 throws IOException , EOFException 204 { 205 return m_input.read( data, offset, length ); 206 } 207 208 public long skip( final long count ) 209 throws IOException , EOFException 210 { 211 return m_input.skip( count ); 212 } 213 214 public void mark( final int readLimit ) 215 { 216 m_input.mark( readLimit ); 217 } 218 219 public boolean markSupported() 220 { 221 return m_input.markSupported(); 222 } 223 224 public void reset() 225 throws IOException 226 { 227 m_input.reset(); 228 } 229 } 230 | Popular Tags |