- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathType.java
More file actions
Latest commit
63 lines (54 loc) · 1.71 KB
/
Copy pathType.java
File metadata and controls
63 lines (54 loc) · 1.71 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
packagesimpledb;
importjava.text.ParseException;
importjava.io.*;
/**
* Class representing a type in SimpleDB.
* Types are static objects defined by this class; hence, the Type
* constructor is private.
*/
publicenumType {
INT_TYPE() {
@Override
publicintgetLen() {
return4;
}
@Override
publicFieldparse(DataInputStreamdis) throwsParseException {
try {
returnnewIntField(dis.readInt());
} catch (IOExceptione) {
thrownewParseException("couldn't parse", 0);
}
}
}, STRING_TYPE() {
@Override
publicintgetLen() {
returnSTRING_LEN+4;
}
@Override
publicFieldparse(DataInputStreamdis) throwsParseException {
try {
intstrLen = dis.readInt();
bytebs[] = newbyte[strLen];
dis.read(bs);
dis.skipBytes(STRING_LEN-strLen);
returnnewStringField(newString(bs), STRING_LEN);
} catch (IOExceptione) {
thrownewParseException("couldn't parse", 0);
}
}
};
publicstaticfinalintSTRING_LEN = 128;
/**
* @return the number of bytes required to store a field of this type.
*/
publicabstractintgetLen();
/**
* @return a Field object of the same type as this object that has contents
* read from the specified DataInputStream.
* @param dis The input stream to read from
* @throws ParseException if the data read from the input stream is not
* of the appropriate type.
*/
publicabstractFieldparse(DataInputStreamdis) throwsParseException;
}