-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLittleEndianDataInput.java
More file actions
79 lines (67 loc) · 1.49 KB
/
LittleEndianDataInput.java
File metadata and controls
79 lines (67 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.io.*;
final class LittleEndianDataInput {
private InputStream stream;
private int cpos;
public LittleEndianDataInput (InputStream stream)
{
assert(stream != null);
this.stream = stream;
this.cpos = 0;
}
public void close () throws IOException
{
stream.close();
}
public void read (byte[] data) throws IOException
{
int i = 0;
int n = data.length;
while (n != 0) {
int r = stream.read(data, i, n);
if (r == -1) {
throw new EOFException();
} else {
i += r;
n -= r;
cpos += r;
}
}
}
public byte readByte () throws IOException
{
int x = stream.read();
if (x == -1) throw new EOFException();
cpos += 1;
return (byte)x;
}
public int readUnsignedByte () throws IOException
{
return readByte() & 0xff;
}
public int readShort () throws IOException
{
return readUnsignedByte() | (readByte() << 8);
}
public int readUnsignedShort () throws IOException
{
return readUnsignedByte() | (readUnsignedByte() << 8);
}
public int readInt () throws IOException
{
return readUnsignedByte() | (readUnsignedByte() << 8) | (readUnsignedByte() << 16) | (readByte() << 24);
}
public void skipBytes (int n) throws IOException
{
if (stream.skip(n) != n)
throw new EOFException();
cpos += n;
}
public int position ()
{
return cpos;
}
public void setPosition (int pos) throws IOException
{
skipBytes(pos - cpos);
}
}