通过jlha压缩文件

  应鬼子要求,压缩文件。编写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
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值