-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReader.java
More file actions
66 lines (56 loc) · 1.64 KB
/
Copy pathReader.java
File metadata and controls
66 lines (56 loc) · 1.64 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
package compresseur;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;
public class Reader {
private String fileName;
public Reader(String fileName) {
this.fileName = fileName;
}
public Vector<Integer> read() {
Vector<Integer> vector = new Vector<Integer>();
try{
File file = new File (this.fileName);
FileReader fileReader = new FileReader (file);
BufferedReader bufferedReader = new BufferedReader (fileReader);
int character = fileReader.read();
int index = 0;
while (character != 10 && character != 13) {
if(character != 48 && character != 49) {
throw new IOException("Bad file content");
}
vector.add(character);
character = fileReader.read();
}
}
catch (IOException exception)
{
System.out.println ("Error while reading file : " + exception.getMessage());
}
return vector;
}
public static int readAByte(Vector<Integer> source, int index) throws IOException {
int result = 0;
for(int i = 0; i < 8; i++) {
if((index + i) >= source.size()) {
throw new IOException("File not big enough to read a byte at this index");
}
result = result * 2 + Character.getNumericValue(source.get(index + i));
}
return result;
}
public static int getMinimumSizeOfAByte(Vector<Integer> source, int index) throws IOException {
int result = 1;
for(int i = 0; i < 8; i++) {
if((index + i) >= source.size()) {
throw new IOException("File not big enough to read a byte at this index");
}
if(Character.getNumericValue(source.get(index + i)) == 1) {
result = i + 1;
}
}
return result;
}
}