JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
LEDataInputStream.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * - Redistribution of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of Sun Microsystems, Inc. or the names of
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * This software is provided "AS IS," without a warranty of any kind. ALL
20 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
23 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
24 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
25 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
26 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
27 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
28 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
29 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
30 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31 *
32 * You acknowledge that this software is not designed or intended for use
33 * in the design, construction, operation or maintenance of any nuclear
34 * facility.
35 *
36 * Sun gratefully acknowledges that this software was originally authored
37 * and developed by Kenneth Bradley Russell and Christopher John Kline.
38 */
39
40package com.jogamp.opengl.util.texture.spi;
41
42import java.io.DataInput;
43import java.io.DataInputStream;
44import java.io.FilterInputStream;
45import java.io.InputStream;
46import java.io.FileInputStream;
47import java.io.EOFException;
48import java.io.IOException;
49
50/**
51 * Little Endian Data Input Stream.
52 *
53 * This class implements an input stream filter to allow reading
54 * of java native datatypes from an input stream which has those
55 * native datatypes stored in a little endian byte order.<p>
56 *
57 * This is the sister class of the DataInputStream which allows
58 * for reading of java native datatypes from an input stream with
59 * the datatypes stored in big endian byte order.<p>
60 *
61 * This class implements the minimum required and calls DataInputStream
62 * for some of the required methods for DataInput.<p>
63 *
64 * Not all methods are implemented due to lack of immediatte requirement
65 * for that functionality. It is not clear if it is ever going to be
66 * functionally required to be able to read UTF data in a LittleEndianManner<p>
67 *
68 * @author Robin Luiten
69 * @version 1.1 15/Dec/1997
70 */
71public class LEDataInputStream extends FilterInputStream implements DataInput
72{
73 /**
74 * To reuse some of the non endian dependent methods from
75 * DataInputStreams methods.
76 */
77 DataInputStream dataIn;
78
79 public LEDataInputStream(final InputStream in)
80 {
81 super(in);
82 dataIn = new DataInputStream(in);
83 }
84
85 @Override
86 public void close() throws IOException
87 {
88 dataIn.close(); // better close as we create it.
89 // this will close underlying as well.
90 }
91
92 @Override
93 public synchronized final int read(final byte b[]) throws IOException
94 {
95 return dataIn.read(b, 0, b.length);
96 }
97
98 @Override
99 public synchronized final int read(final byte b[], final int off, final int len) throws IOException
100 {
101 final int rl = dataIn.read(b, off, len);
102 return rl;
103 }
104
105 @Override
106 public final void readFully(final byte b[]) throws IOException
107 {
108 dataIn.readFully(b, 0, b.length);
109 }
110
111 @Override
112 public final void readFully(final byte b[], final int off, final int len) throws IOException
113 {
114 dataIn.readFully(b, off, len);
115 }
116
117 @Override
118 public final int skipBytes(final int n) throws IOException
119 {
120 return dataIn.skipBytes(n);
121 }
122
123 @Override
124 public final boolean readBoolean() throws IOException
125 {
126 final int ch = dataIn.read();
127 if (ch < 0)
128 throw new EOFException();
129 return (ch != 0);
130 }
131
132 @Override
133 public final byte readByte() throws IOException
134 {
135 final int ch = dataIn.read();
136 if (ch < 0)
137 throw new EOFException();
138 return (byte)(ch);
139 }
140
141 @Override
142 public final int readUnsignedByte() throws IOException
143 {
144 final int ch = dataIn.read();
145 if (ch < 0)
146 throw new EOFException();
147 return ch;
148 }
149
150 @Override
151 public final short readShort() throws IOException
152 {
153 final int ch1 = dataIn.read();
154 final int ch2 = dataIn.read();
155 if ((ch1 | ch2) < 0)
156 throw new EOFException();
157 return (short)((ch1 << 0) + (ch2 << 8));
158 }
159
160 @Override
161 public final int readUnsignedShort() throws IOException
162 {
163 final int ch1 = dataIn.read();
164 final int ch2 = dataIn.read();
165 if ((ch1 | ch2) < 0)
166 throw new EOFException();
167 return (ch1 << 0) + (ch2 << 8);
168 }
169
170 @Override
171 public final char readChar() throws IOException
172 {
173 final int ch1 = dataIn.read();
174 final int ch2 = dataIn.read();
175 if ((ch1 | ch2) < 0)
176 throw new EOFException();
177 return (char)((ch1 << 0) + (ch2 << 8));
178 }
179
180 @Override
181 public final int readInt() throws IOException
182 {
183 final int ch1 = dataIn.read();
184 final int ch2 = dataIn.read();
185 final int ch3 = dataIn.read();
186 final int ch4 = dataIn.read();
187 if ((ch1 | ch2 | ch3 | ch4) < 0)
188 throw new EOFException();
189 return ((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24));
190 }
191
192 @Override
193 public final long readLong() throws IOException
194 {
195 final int i1 = readInt();
196 final int i2 = readInt();
197 return (i1 & 0xFFFFFFFFL) + ((long)i2 << 32);
198 }
199
200 @Override
201 public final float readFloat() throws IOException
202 {
203 return Float.intBitsToFloat(readInt());
204 }
205
206 @Override
207 public final double readDouble() throws IOException
208 {
209 return Double.longBitsToDouble(readLong());
210 }
211
212 /**
213 * dont call this it is not implemented.
214 * @return empty new string
215 **/
216 @Override
217 public final String readLine() throws IOException
218 {
219 return "";
220 }
221
222 /**
223 * dont call this it is not implemented
224 * @return empty new string
225 **/
226 @Override
227 public final String readUTF() throws IOException
228 {
229 return "";
230 }
231
232 /**
233 * dont call this it is not implemented
234 * @return empty new string
235 **/
236 public final static String readUTF(final DataInput in) throws IOException
237 {
238 return "";
239 }
240}
241
final String readUTF()
dont call this it is not implemented
synchronized final int read(final byte b[], final int off, final int len)
final String readLine()
dont call this it is not implemented.
synchronized final int read(final byte b[])
static final String readUTF(final DataInput in)
dont call this it is not implemented
final void readFully(final byte b[], final int off, final int len)