-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathTaFile.java
More file actions
99 lines (89 loc) · 2.53 KB
/
TaFile.java
File metadata and controls
99 lines (89 loc) · 2.53 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package flashsystem;
import java.io.*;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Vector;
/** Demonstrate using Scanner to read a file. **/
public class TaFile {
File _taf;
FileInputStream _in;
Scanner _scanner;
Vector<TaEntry> entries = new Vector<TaEntry>();
int _partition = 0;
public TaFile(File f) throws TaParseException, FileNotFoundException {
_taf = f;
TaEntry entry = new TaEntry();
_in = new FileInputStream(f);
_scanner = new Scanner (_in);
String partition="";
boolean beginentry=false;
while (_scanner.hasNextLine()) {
String line = _scanner.nextLine().trim();
if (line.startsWith("/")) continue;
if (!(line.length()<=4)) {
Scanner scanline = new Scanner(line);
scanline.useDelimiter(" ");
while (scanline.hasNext()) {
String elem = scanline.next();
if (elem.length()==8) {
if (entry.getPartition().length()==0) {
entry.setPartition(elem);
String size=scanline.next();
if (size.length()==4) entry.setSize(size);
else throw new TaParseException("Next to unit should be the size on 4 digits");
}
else {
entry.close();
entries.add(entry);
entry = new TaEntry();
entry.setPartition(elem);
String size=scanline.next();
if (size.length()==4) entry.setSize(size);
else throw new TaParseException("Next to unit should be the size on 4 digits");
}
}
else {
if (elem.length()==2)
entry.addData(elem);
}
}
}
if(_partition == 0 && line.length() == 2){
try {
_partition = Integer.parseInt(line);
if (_partition !=1 && _partition != 2) {
throw new TaParseException("TA partition should be 1 or 2");
}
} catch (NumberFormatException e) {
}
}
}
if(_partition == 0){
_partition = 2;
}
entry.close();
entries.add(entry);
try {
_in.close();
}
catch (Exception e) {}
}
public Vector<TaEntry> entries() {
return entries;
}
public String getName() {
return _taf.getName();
}
public int getPartition() {
return _partition;
}
public String toString() {
String result = "";
Iterator<TaEntry> i = entries().iterator();
while (i.hasNext()) {
TaEntry entry = i.next();
result=result + entry+"\n";
}
return result;
}
}