hutool系列教材 (三十二)- 其他 - Java 压缩工具

时间:2025-03-10 15:17:46

package cn.;

import static ;

import static ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

import ;

public class TestZip {

    @Test

    @Comment("压缩字符串")

    public void test1(){

        String str = "hello!!!!!!!!!!!!!!!";

        byte[] bs= (str, "utf-8"4);

        String str2 = (bs, "utf-8");

         

        p3("源字符串",str);

        p3("长度是",());

        p3("zlib压缩后,长度是",);

        p3("unzip后得到",str2);

         

    }

    @Test

    @Comment("压缩文件")

    public void test2(){

        ("\t因为是压缩文件,不好演示,主要就是使用 zip和unzip方法,很好用,都挨个试试就知道了");

    }

     

    private String preComment = null

    private void c(String msg) {

        ("\t备注:%s%n",msg);

    }

    private void p1(String type1, Object value1, String type2, Object value2) {

        p(type1, value1, type2, value2, "format1");

    }

    private void p2(String type1, Object value1, String type2, Object value2) {

        p(type1, value1, type2, value2, "format2");

    }

    private void p3(String type1, Object value1) {

        p(type1, value1, """""format3");

    }

  

    private void p(String type1, Object value1, String type2, Object value2, String format) {

        try {

            throw new Exception();

        catch (Exception e) {

              

            String methodName = getTestMethodName(());

            Method m =(this.getClass(), methodName);

            Comment annotation = (Comment.class);

            if(null!=annotation) {

                String comment= ();

                if(!(preComment)) {

                    ("%n%s 例子: %n%n",comment);

                    preComment = comment;

                }

                  

            }

        }

        int padLength = 12;

        type1=(type1,padLength,(" ").charAt(0));

        type2=(type2,padLength,(" ").charAt(0));

        if("format1".equals(format)) {

            ("\t%s的:\t\"%s\" %n\t被转换为----->%n\t%s的 :\t\"%s\" %n%n",type1,value1, type2, value2);

        }

        if("format2".equals(format)) {

            ("\t基于 %s:\t\"%s\" %n\t获取 %s:\t\"%s\"%n%n",type1,value1, type2, value2);

        }

        if("format3".equals(format)) {

            ("\t%s:\t\"%s\" %n\t%n",type1,value1);

  

        }

    }

      

    private String getTestMethodName(StackTraceElement[] stackTrace) {

        for (StackTraceElement se : stackTrace) {

            String methodName = ();

            if(("test"))

                return methodName;

        }

        return null;

    }

  

    @Target({METHOD,TYPE})

    @Retention()

    @Inherited

    @Documented

    public @interface Comment {

         String value();

    }

}