-
Notifications
You must be signed in to change notification settings - Fork 0
/
FEDataSaver.pde
47 lines (39 loc) · 1.42 KB
/
FEDataSaver.pde
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
import java.io.*;
class FEDataSaver
{
FileWriter fstream;
BufferedWriter buf;
public FEDataSaver(String date, String tag) throws IOException
{
try {
File dir = new File(cacheDir+date);
if (!dir.exists() && dir.mkdir()){
System.out.println("Making dir");
}
fstream = new FileWriter(cacheDir + date + "/" + tag + ".txt");
System.out.println("Write to: " + date + "/" + tag + ".txt");
buf = new BufferedWriter(fstream);
} catch (Exception e){
System.out.println(e.getMessage());
}
}
public synchronized void writePhoto(Photo p) throws IOException
{
String tags = "", photoString;
Object[] tagArray = p.getTags().toArray();
for(int i = 0; i < p.getTags().size(); i++){
tags += ((Tag)tagArray[i]).getValue() + ",";
}
photoString = "<photo id=\""+p.getId()+"\" owner=\""+p.getOwner().getId()+"\" owner_name=\""+p.getOwner().getUsername()+"\" secret=\""+p.getSecret()+"\" server=\""+p.getServer()+"\" farm=\""+p.getFarm()+"\" latitude=\""+p.getGeoData().getLatitude()+"\" longitude=\""+p.getGeoData().getLongitude()+"\" tags=\""+tags+"\"/>\n";
writeString(photoString);
}
public synchronized void writeString(String string) throws IOException
{
buf.write(string);
//System.out.println("Write string: " + string);
}
public synchronized void closeBuffer() throws IOException
{
buf.close();
}
}