1bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook/*
2bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Licensed to the Apache Software Foundation (ASF) under one or more
3bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * contributor license agreements.  See the NOTICE file distributed with
4bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * this work for additional information regarding copyright ownership.
5bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * The ASF licenses this file to You under the Apache License, Version 2.0
6bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * (the "License"); you may not use this file except in compliance with
7bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * the License.  You may obtain a copy of the License at
8bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook *
9bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook *      http://www.apache.org/licenses/LICENSE-2.0
10bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook *
11bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * Unless required by applicable law or agreed to in writing, software
12bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * distributed under the License is distributed on an "AS IS" BASIS,
13bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * See the License for the specific language governing permissions and
15bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * limitations under the License.
16bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */
17bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookpackage org.apache.commons.io.input;
18bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
19bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport java.io.DataInput;
20bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport java.io.EOFException;
21bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport java.io.IOException;
22bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport java.io.InputStream;
23bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
24bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookimport org.apache.commons.io.EndianUtils;
25bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
26bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook/**
27bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * DataInput for systems relying on little endian data formats.
28bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * When read, values will be changed from little endian to big
29bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * endian formats for internal usage.
30bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * <p>
31bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * <b>Origin of code: </b>Avalon Excalibur (IO)
32bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook *
33bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @author <a href="mailto:peter@apache.org">Peter Donald</a>
34bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook * @version CVS $Revision: 610010 $ $Date: 2008-01-08 14:50:59 +0000 (Tue, 08 Jan 2008) $
35bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook */
36bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrookpublic class SwappedDataInputStream extends ProxyInputStream
37bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    implements DataInput
38bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook{
39bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
40bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
41bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Constructs a SwappedDataInputStream.
42bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     *
43bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @param input InputStream to read from
44bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
45bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public SwappedDataInputStream( InputStream input )
46bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
47bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        super( input );
48bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
49bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
50bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
51bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Return <code>{@link #readByte()} == 0</code>
52bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the true if the byte read is zero, otherwise false
53bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
54bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
55bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
56bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public boolean readBoolean()
57bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
58bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
59bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return ( 0 == readByte() );
60bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
61bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
62bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
63bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Invokes the delegate's <code>read()</code> method.
64bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the byte read or -1 if the end of stream
65bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
66bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
67bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
68bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public byte readByte()
69bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
70bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
71bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return (byte)in.read();
72bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
73bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
74bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
75bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Reads a character delegating to {@link #readShort()}.
76bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the byte read or -1 if the end of stream
77bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
78bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
79bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
80bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public char readChar()
81bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
82bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
83bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return (char)readShort();
84bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
85bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
86bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
87bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Delegates to {@link EndianUtils#readSwappedDouble(InputStream)}.
88bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the read long
89bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
90bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
91bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
92bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public double readDouble()
93bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
94bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
95bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return EndianUtils.readSwappedDouble( in );
96bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
97bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
98bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
99bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Delegates to {@link EndianUtils#readSwappedFloat(InputStream)}.
100bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the read long
101bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
102bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
103bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
104bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public float readFloat()
105bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
106bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
107bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return EndianUtils.readSwappedFloat( in );
108bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
109bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
110bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
111bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Invokes the delegate's <code>read(byte[] data, int, int)</code> method.
112bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     *
113bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @param data the buffer to read the bytes into
114bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
115bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
116bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
117bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public void readFully( byte[] data )
118bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
119bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
120bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        readFully( data, 0, data.length );
121bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
122bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
123bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
124bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
125bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Invokes the delegate's <code>read(byte[] data, int, int)</code> method.
126bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     *
127bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @param data the buffer to read the bytes into
128bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @param offset The start offset
129bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @param length The number of bytes to read
130bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
131bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
132bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
133bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public void readFully( byte[] data, int offset, int length )
134bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
135bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
136bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        int remaining = length;
137bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
138bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        while( remaining > 0 )
139bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        {
140bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook            int location = offset + ( length - remaining );
141bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook            int count = read( data, location, remaining );
142bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
143bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook            if( -1 == count )
144bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook            {
145bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook                throw new EOFException();
146bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook            }
147bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
148bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook            remaining -= count;
149bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        }
150bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
151bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
152bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
153bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Delegates to {@link EndianUtils#readSwappedInteger(InputStream)}.
154bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the read long
155bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
156bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
157bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
158bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public int readInt()
159bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
160bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
161bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return EndianUtils.readSwappedInteger( in );
162bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
163bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
164bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
165bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Not currently supported - throws {@link UnsupportedOperationException}.
166bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the line read
167bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
168bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
169bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
170bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public String readLine()
171bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
172bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
173bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throw new UnsupportedOperationException(
174bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook                "Operation not supported: readLine()" );
175bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
176bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
177bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
178bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Delegates to {@link EndianUtils#readSwappedLong(InputStream)}.
179bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the read long
180bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
181bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
182bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
183bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public long readLong()
184bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
185bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
186bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return EndianUtils.readSwappedLong( in );
187bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
188bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
189bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
190bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Delegates to {@link EndianUtils#readSwappedShort(InputStream)}.
191bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the read long
192bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
193bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
194bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
195bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public short readShort()
196bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
197bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
198bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return EndianUtils.readSwappedShort( in );
199bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
200bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
201bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
202bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Invokes the delegate's <code>read()</code> method.
203bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the byte read or -1 if the end of stream
204bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
205bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
206bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
207bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public int readUnsignedByte()
208bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
209bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
210bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return in.read();
211bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
212bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
213bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
214bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Delegates to {@link EndianUtils#readSwappedUnsignedShort(InputStream)}.
215bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the read long
216bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
217bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
218bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
219bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public int readUnsignedShort()
220bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
221bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
222bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return EndianUtils.readSwappedUnsignedShort( in );
223bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
224bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
225bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
226bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Not currently supported - throws {@link UnsupportedOperationException}.
227bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return UTF String read
228bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
229bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
230bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
231bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public String readUTF()
232bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
233bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
234bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throw new UnsupportedOperationException(
235bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook                "Operation not supported: readUTF()" );
236bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
237bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
238bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    /**
239bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * Invokes the delegate's <code>skip(int)</code> method.
240bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @param count the number of bytes to skip
241bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @return the number of bytes to skipped or -1 if the end of stream
242bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws EOFException if an end of file is reached unexpectedly
243bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     * @throws IOException if an I/O error occurs
244bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook     */
245bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    public int skipBytes( int count )
246bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        throws IOException, EOFException
247bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    {
248bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook        return (int)in.skip( count );
249bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook    }
250bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook
251bc47398187c6ffd132435e51d8d61e6ec79a79dbPaul Westbrook}
252