-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarvellousPacker.java
More file actions
120 lines (91 loc) · 2.97 KB
/
MarvellousPacker.java
File metadata and controls
120 lines (91 loc) · 2.97 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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Stream;
import javax.swing.event.SwingPropertyChangeSupport;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
public class MarvellousPacker
{
FileOutputStream outstream = null;
String ValidExt[] = {".txt",".c",".java",".cpp"};
public MarvellousPacker(String src,String Dest) throws Exception
{
String Magic = "Marvellous11";
byte arr[] = Magic.getBytes();
File outfile = new File(Dest);
File infile = null;
outstream = new FileOutputStream(Dest);
outstream.write(arr,0,arr.length);
File folder = new File(src);
System.setProperty("user.dir",src);
listAllFiles(src);
}
public void listAllFiles(String path)
{
try
(Stream<Path> paths = Files.walk(Paths.get(path)))
{
paths.forEach(filePath ->
{
if (Files.isRegularFile(filePath))
{
try
{
String name = filePath.getFileName().toString();
String ext = name.substring(name.lastIndexOf("."));
List<String> list = Arrays.asList(ValidExt);
if(list.contains(ext))
{
File file = new File(filePath.getFileName().toString());
Pack(file.getAbsolutePath());
}
}
catch(Exception e)
{
System.out.println(e);
}
}
});
}
catch(Exception e)
{
System.out.println(e);
}
}
public void Pack(String filePath)
{
FileInputStream instream = null;
try
{
byte[] buffer = new byte[1024];
int length;
byte temp[] = new byte[100];
File fobj = new File(filePath);
String Header = filePath+" "+fobj.length();
for(int i = Header.length(); i < 100;i++)
Header+=" ";
temp = Header.getBytes();
instream = new FileInputStream(filePath);
outstream .write(temp,0,temp.length);
while((length = instream.read(buffer)) > 0)
{
outstream.write(buffer,0,length);
}
instream.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}