-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unpack.java
67 lines (52 loc) · 1.67 KB
/
Unpack.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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Unpack
{
FileOutputStream outstream = null;
public Unpack(String src)throws Exception
{
unpack(src);
}
public void unpack(String filePath)throws Exception
{
try
{
FileInputStream instream = new FileInputStream(filePath);
byte header[] = new byte[100];
int length = 0;
byte Magic[] = new byte[12];
instream.read(Magic,0,Magic.length);
String Magicstr = new String(Magic);
if(!Magicstr.equals("FilePackerV1"))
{
throw new InvalidFileException("Invalid packed file format");
}
while((length = instream.read(header,0,100)) > 0)
{
String str = new String(header);
String ext = str.substring(str.lastIndexOf("/"));
ext = ext.substring(1);
String[] words = ext.split("\\s");
String filename = words[0];
int size = Integer.parseInt(words[1]);
byte arr[] = new byte[size];
instream.read(arr,0,size);
FileOutputStream fout = new FileOutputStream(filename);
fout.write(arr,0,size);
}
}
catch(InvalidFileException obj)
{
throw new InvalidFileException("Invalid packed file format");
}
catch(Exception e)
{}
}
}