📄 gszip.java
字号:
package jp.co.sjts.gsession.tools.archive;
import java.io.File;
import java.io.FileInputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.CRC32;
import java.util.zip.ZipOutputStream;
import java.util.zip.CheckedOutputStream;
public class GSZip {
private String dirname = null;
private String zipname = null;
private String pathname = null;
public GSZip(String dirname,String zipname,String pathname) {
this.dirname = dirname;
this.zipname = zipname;
this.pathname = pathname;
}
public GSZip(File dir,File zip,File path) {
this.dirname = dir.getPath();
this.zipname = zip.getPath();
this.pathname = path.getPath();
}
public void write() throws IOException,Exception {
try {
byte[] buf = new byte[1024*8];
Vector vec = new Vector();
if(dirname.lastIndexOf(File.separator) == dirname.length() - 1)
dirname = dirname.substring(0,dirname.length() - 1);
FileDetect top = new FileDetect( new File( dirname ));
top.path = dirname;
top.getfile(vec);
int length = dirname.length();
FileOutputStream f = new FileOutputStream(pathname + zipname);
CheckedOutputStream csum = new CheckedOutputStream(f,new CRC32());
ByteArrayOutputStream bao = new ByteArrayOutputStream();
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum));
out.setComment("GSDATA Backup to Zipping");
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("ziplog")));
for(int i=0; i<vec.size(); i++) {
bao.reset();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream((String)vec.get(i)));
int result;
do {
result = bis.read(buf,0,buf.length);
if(result != -1)
bao.write(buf,0,result);
}while (result == buf.length);
String o = ("GSDATA" + ((String)vec.get(i)).substring(length));
out.putNextEntry(new ZipEntry(o));
pw.println(vec.get(i));
byte[] data = bao.toByteArray();
out.write(data);
bis.close();
}
out.close();
}
catch( IOException ie ) {
throw new IOException(ie.toString());
}
catch( Exception e ) {
throw new Exception(e.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -