forked from MGundersen/Program
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathser.java
More file actions
217 lines (183 loc) · 7.42 KB
/
ser.java
File metadata and controls
217 lines (183 loc) · 7.42 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import Data.*;
import Distance.coordinate;
import Distance.readPaths;
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
/**
* Created by MGund on 4/24/2016.
*/
public class ser {
private Path output = null;
private Path input = null;
public ser (Path output) {
this.output = output;
}
public void serialize (Path input) {
File file = new File(input.toString());
//List af string med navne på filerne i vores directory
String[] names = file.list();
//Looper over listen
for (String name : names) {
File currentFile = new File(input.toString() + "\\" + name);
if (currentFile.isDirectory()) {
serialize(currentFile.toPath());
} else {
if (currentFile.getName().split("-").length == 3) {
System.out.println( "Route: " + currentFile.getName());
serializeWaypoints(currentFile);
} else if (currentFile.getName().equals("climb.csv")) {
System.out.println( "Climb: " + currentFile.getName());
serializeClimb(currentFile);
} else if (currentFile.getName().equals("cruise.csv")) {
System.out.println( "Cruise: " + currentFile.getName());
serializeCruise(currentFile);
} else if (currentFile.getName().equals("descent.csv")) {
System.out.println( "descent: " + currentFile.getName());
serializeDescent(currentFile);
} else if (currentFile.getName().equals("weightlimits.csv")) {
System.out.println( "Weightlimit: " + currentFile.getName());
serializeWeightlimits(currentFile);
} else {
System.out.println( "File: " + currentFile.getName());
serializeFile(currentFile);
}
}
}
}
public Object[][] deserializeData (String name) {
Object[][] f;
try
{
File file = new File(output.toString() + "\\" + name + ".ser");
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream in = new ObjectInputStream(fileIn);
f = (Object[][]) in.readObject();
in.close();
fileIn.close();
return f;
}catch(IOException i) { i.printStackTrace();}
catch(ClassNotFoundException c) {
System.out.println( name + " was not found");
c.printStackTrace();
}
return null;
}
public Object[] deserializeWeight (String name) {
Object[] f;
try
{
File file = new File(output.toString() + "\\" + name + ".ser");
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream in = new ObjectInputStream(fileIn);
f = (Object[]) in.readObject();
in.close();
fileIn.close();
return f;
}catch(IOException i) { i.printStackTrace();}
catch(ClassNotFoundException c) {
System.out.println( name + " was not found");
c.printStackTrace();
}
return null;
}
public List deserializeRoute (String name) {
List f;
try
{
File file = new File(output.toString() + "\\" + name + ".ser");
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream in = new ObjectInputStream(fileIn);
f = (List) in.readObject();
in.close();
fileIn.close();
return f;
}catch(IOException i) { i.printStackTrace();}
catch(ClassNotFoundException c) {
System.out.println( name + " was not found");
c.printStackTrace();
}
return null;
}
private void serializeClimb (File file) {
dataArrays d = new dataArrays();
climbData[][] array = d.climbFill(file);
System.out.println(array.length+"climb");
try {
FileOutputStream fileOut =
new FileOutputStream(output + "\\" + file.getName() + ".ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject( array );
out.flush();
fileOut.close();
} catch (IOException e) {e.printStackTrace();
System.out.println( "Was unable to serialize climb" );}
}
private void serializeCruise (File file) {
dataArrays d = new dataArrays();
cruiseData[][] array = d.cruiseFill(file);
System.out.println(array.length+"cruise");
try {
FileOutputStream fileOut =
new FileOutputStream(output + "\\" + file.getName() + ".ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(array);
out.flush();
fileOut.close();
} catch (IOException e) {e.printStackTrace();
System.out.println( "Was unable to serialize cruise" );}
}
private void serializeDescent (File file) {
dataArrays d = new dataArrays();
descentData[][] array = d.descentFill(file);
System.out.println(array.length+"descent");
try {
FileOutputStream fileOut =
new FileOutputStream(output + "\\" + file.getName() + ".ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(array);
out.flush();
fileOut.close();
} catch (IOException e) {e.printStackTrace();
System.out.println( "Was unable to serialize descent" );}
}
private void serializeWeightlimits (File file) {
dataArrays d = new dataArrays();
weightLimitsData[] array = d.weightLimitsFill(file);
try {
FileOutputStream fileOut =
new FileOutputStream(output + "\\" + file.getName() + ".ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(array);
out.flush();
fileOut.close();
} catch (IOException e) {e.printStackTrace();
System.out.println( "Was unable to serialize weightlimits" );}
}
private void serializeWaypoints (File file) {
readPaths rp = new readPaths();
List<coordinate> wp = rp.waypoints(file);
try {
FileOutputStream fileOut =
new FileOutputStream(output + "\\" + file.getName() + ".ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(wp);
out.flush();
fileOut.close();
} catch (IOException e) {e.printStackTrace();
System.out.println( "Was unable to serialize route: " + file.getName() );}
}
private void serializeFile (File file) {
try {
FileOutputStream fileOut =
new FileOutputStream(output + "\\" + file.getName() + ".ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(file);
out.flush();
fileOut.close();
} catch (IOException e) {e.printStackTrace();
System.out.println( "Was unable to serialize file: " + file.getName() );}
}
}