-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileList.java
89 lines (81 loc) · 2.33 KB
/
FileList.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
import java.io.*;
import java.text.*;
import java.util.Date;
import SevenZip.Compression.LZMA.Decoder;
public class FileList {
private byte[] data;
private int offset;
/** Creates a new FileList and reads a file list from an lzma compressed stream (lzma file format by lzma-utils)
* @param in input stream the list is read from
*/
public FileList(InputStream in) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Decoder decoder = new Decoder();
byte[] props = new byte[5];
in.read(props);
decoder.SetDecoderProperties(props);
//from LzmaAlone.java
int len = 0;
for (int i = 0; i < 8; i++)
{
int v = in.read();
len |= ((long)v) << (8 * i);
}
decoder.Code(in, out, len);
data = out.toByteArray();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/** Returns the next file information from the read list.
* @return a FileLoction with the read information or null if an error occurs (or the list is exhausted)
*/
public FileLocation nextFile(){
String read;
synchronized (this) {
int start = offset;
while (data[offset] != '\n') {
if (offset+1 == data.length)
return null;
offset++;
}
read = new String(data, start, offset-start);
offset++;
}
String[] line = read.split(";");
if (line.length != 8)
return null;
final DateFormat df = new SimpleDateFormat("yyyy.MM.dd kk:mm");
try {
FileLocation fl = new FileLocation();
fl.fileName = line[0];
fl.firstSlice = Integer.parseInt(line[2]);
fl.lastSlice = Integer.parseInt(line[3]);
fl.startOffset = Integer.parseInt(line[4]);
fl.originalSize = Integer.parseInt(line[6]);
fl.compressedSize = Integer.parseInt(line[7]);
fl.mtime = df.parse(line[1]);
return fl;
} catch (ParseException e) {
return null;
}
}
public static class FileLocation {
/** path and name of the file. */
public String fileName;
/** first slice which contains data of this file */
public int firstSlice;
/** last slice which contains data of this file */
public int lastSlice;
/** the data starts in the first Slice at this offset */
public int startOffset;
/** the decompressed size of the file */
public int originalSize;
/** the compressed size of the file */
public int compressedSize;
/** the modification time of the file */
public Date mtime;
}
}