-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackUnpack.java
More file actions
137 lines (91 loc) · 2.52 KB
/
PackUnpack.java
File metadata and controls
137 lines (91 loc) · 2.52 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
package Pack;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
class PackUnpack
{
FileOutputStream fobj1;
FileInputStream fobj2;
public int Unpack(String IPfile)
{
try
{
File obj1=new File(IPfile);
if(!obj1.exists())
{
return -1;
}
this.fobj2 = new FileInputStream(IPfile);
byte[] magic = new byte[10];
byte[] b1 = new byte[100];
int ret = 0;
this.fobj2.read(magic);
String str = new String(magic);
if (!str.equals("Deepraj"))
{
return -1;
}
while ((ret = this.fobj2.read(b1)) != -1)
{
str = new String(b1);
String[] strarr = str.split("\\s+");
int size = Integer.valueOf(strarr[1]).intValue();
File f1 = new File(strarr[0]);
f1.createNewFile();
this.fobj1 = new FileOutputStream(strarr[0]);
byte[] b2 = new byte[size];
this.fobj2.read(b2);
this.fobj1.write(b2);
this.fobj1.close();
}
this.fobj2.close();
}
catch (Exception exception) {}
return 1;
}
public int Pack(String Dir, String OPfile)
{
int k = 0;
String[] ext = { "txt", "cpp", "c", "java" };
//System.out.println("jeetshah11".length());
try
{
File obj = new File(Dir);
if (!obj.exists())
{
return -2;
}
this.fobj1 = new FileOutputStream(OPfile);
this.fobj1.write("Deepraj".getBytes());
File[] farr = obj.listFiles();
for (int j = 0; j < farr.length; j++)
{
String[] arr = farr[j].getName().split("\\.");
for (k = 0; k < ext.length; k++)
{
if (arr[1].equals(ext[k]))
{
break;
}
}
if (k != ext.length)
{
this.fobj2 = new FileInputStream(String.valueOf(Dir) + "\\" + farr[j].getName());
String str = String.format("%-99s\n", new Object[] { String.valueOf(farr[j].getName()) + " " + String.valueOf(farr[j].length()) });
this.fobj1.write(str.getBytes());
int i;
while ((i = this.fobj2.read()) != -1)
{
System.out.println((char)i);
this.fobj1.write(i);
}
this.fobj2.close();
}
} this.fobj1.close();
}
catch (Exception exception)
{
}
return 1;
}
}