1 /
14
15 package util;
16
17 import java.io.*;
18
19
26 public class dataRead {
27 private static int bytesRead = 0;
28
29 public final int getBytesRead() { return bytesRead; }
30
31 public final int readU1( DataInputStream dStream ) {
39 int byteVal = -1;
40
41 try {
42 byteVal = dStream.readUnsignedByte();
43 bytesRead++;
44 } catch (Exception e) {
45 if (e instanceof IOException) {
46 if (! (e instanceof EOFException)) {
47 errorMessage.errorPrint( "(readU1): " + e.getMessage() );
48 }
49 else {
50 errorMessage.errorPrint( "(readU1): unexpected end of file" +
51 e.getMessage() );
52 }
53 }
54 else {
55 errorMessage.errorPrint("(readU1): " + e.toString() +
56 "unexpected exception" );
57 }
58 }
60 return byteVal;
61 }
63
64 public final int readU2( DataInputStream dStream ) {
68 int shortVal = -1;
69
70 try {
71 shortVal = dStream.readUnsignedShort();
72 bytesRead += 2;
73 } catch (Exception e) {
74 if (e instanceof IOException) {
75 if (! (e instanceof EOFException)) {
76 errorMessage.errorPrint( "(readU2): " + e.getMessage() );
77 }
78 else {
79 errorMessage.errorPrint( "(readU2): unexpected end of file" +
80 e.getMessage() );
81 }
82 }
83 else {
84 errorMessage.errorPrint("(readU2): " + e.toString() +
85 "unexpected exception" );
86 }
87 } return shortVal;
89 }
91
92 public final int readU4( DataInputStream dStream ) {
96 int intVal = -1;
97
98 try {
99 intVal = dStream.readInt();
100 bytesRead += 4;
101 } catch (Exception e) {
102 if (e instanceof IOException) {
103 if (! (e instanceof EOFException)) {
104 errorMessage.errorPrint( "(readU4): " + e.getMessage() );
105 }
106 else {
107 errorMessage.errorPrint( "(readU4): unexpected end of file" +
108 e.getMessage() );
109 }
110 }
111 else {
112 errorMessage.errorPrint("(readU4): " + e.toString() +
113 "unexpected exception" );
114 }
115 } return intVal;
117 }
119 }
121