-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.java
128 lines (107 loc) · 2.8 KB
/
Test.java
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
package com.support;
//ûÓÐÓÃ
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.util.Log;
public class Test {
String trainDirPath;
String authDirPath;
String authFileName;
String authLog;
FileOutputStream fos = null;
public Test() {
trainDirPath = null;
authDirPath = authFileName = null;
authLog = null;
}
/**
* initial a new train directory
* @param root sdcard/.../raw
*/
public void startBackupTrain(String root) {
trainDirPath = root + File.separator + "Train_" + getTimeStamp();
File dir = new File( trainDirPath );
if ( !dir.exists() ) {
dir.mkdir();
}
}
/**
* inital a new authenticate file name
* @param root
*/
public void startBackupAuth(String root) {
authFileName = "Auth_" + getTimeStamp();
authDirPath = root + File.separator + authFileName;
Log.v("auth",authDirPath + " " + authFileName);
File dir = new File( authDirPath );
if ( !dir.exists() ) {
dir.mkdir();
}
authLog = root + File.separator + "auth.log";
}
public String getTrainDirPath() {
return trainDirPath;
}
public String getAuthDirPath() {
return authDirPath;
}
public void backupLog(double score) {
try {
fos = new FileOutputStream(authLog, true);
PrintWriter writer = new PrintWriter(fos);
writer.println(authFileName + ": " + score);
writer.close();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void backupShortData(String fileName, short[] data, int len) {
try {
fos = new FileOutputStream(fileName, true);
byte[] tmp = new byte[2];
for (int i=0; i<len; i++) {
for (int j=0; j<2; j++) {
tmp[j] = (byte) (data[i] >> (8*j) & 0xff);
}
fos.write(tmp);
}
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void backupFloatData(String fileName, float[] data, int len) {
try {
fos = new FileOutputStream(fileName, true);
byte[] tmp = new byte[4];
for (int i=0; i<len; i++) {
int dataInt = Float.floatToIntBits(data[i]);
for (int j=0; j<4; j++) {
tmp[j] = (byte) ((dataInt >> (8*j)) & 0xff);
}
fos.write(tmp);
}
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @return time stamp
*/
private String getTimeStamp() {
return new SimpleDateFormat("MMdd_HHmmss").format(Calendar.getInstance().getTime());
}
}