应鬼子要求,压缩文件。编写java类。
需要的jar包:jlha.jar
具体需求的类:
import jp.gr.java_conf.dangan.util.lha.LhaHeader;
import jp.gr.java_conf.dangan.util.lha.LhaOutputStream;
代码和注释如下:
/* * DirectoryZip.java * * Created on 2008.7.8, pm4:48 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package mail; import java.io.InputStream; import java.io.OutputStream; import oracle.sql.*; import java.util.List; import java.sql.Blob; import jp.gr.java_conf.dangan.util.lha.LhaHeader; import jp.gr.java_conf.dangan.util.lha.LhaOutputStream; /** * * @author user */ public class DirectoryZip { //压缩文件,不一定要求是blob,只要是能提供输出流就行 public static BLOB zip(BLOB blob,String filename) throws Exception { BLOB returnBlob = blob;//重点在于blob的输出流 OutputStream returnStream = returnBlob.getBinaryOutputStream(); LhaOutputStream out = new LhaOutputStream(returnStream);//压缩声明 out.putNextEntry(new LhaHeader(filename)); InputStream in = blob.getBinaryStream(); int b; while ((b = in.read()) != -1) {//压缩过程 out.write(b); } out.close(); in.close(); return returnBlob; } //把字符串转化成流压缩 public static BLOB zipStringToBlob(String instring,String filename) throws Exception { /*LhaOutputStream out = new LhaOutputStream(returnBLob.getBinaryOutputStream()); out.putNextEntry(new LhaHeader(filename)); byte[] bytes = instring.getBytes(); int b; for(int i=0;i