-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPixmapReader.java
More file actions
62 lines (48 loc) · 1.35 KB
/
Copy pathPixmapReader.java
File metadata and controls
62 lines (48 loc) · 1.35 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
import java.io.*;
//code de https://www.enseignement.polytechnique.fr/informatique/profs/Philippe.Chassignet/PGM/pgm_java.html
//et légèrement modifié
class PixmapReader extends FileInputStream {
private char c;
public PixmapReader(String fileName) throws FileNotFoundException {
super(fileName);
}
public boolean matchKey(String key) throws IOException {
byte[] buf = new byte[key.length()];
read(buf, 0, key.length());
return key.compareTo(new String(buf)) == 0;
}
public void getChar() throws IOException {
c = (char)read();
}
public int getInt() throws IOException {
String s = "";
while ( (c != '\n') && Character.isSpaceChar(c) )
getChar();
while ( (c != '\n') && !Character.isSpaceChar(c) ) {
s = s + c;
getChar();
}
return Integer.parseInt(s);
}
public void skipLine() throws IOException {
while ( c != '\n' )
getChar();
}
public void skipComment(char code) throws IOException {
getChar();
while ( c == code ) {
skipLine();
getChar();
}
}
public byte[] loadData(int size) throws IOException {
byte[] data = new byte[size];
read(data, 0, size);
return data;
}
public void close() {
try {
super.close();
} catch (IOException e) {}
}
}