java对xml压缩

java 复制代码
import java.util.*;
import java.util.zip.GZIPOutputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.codec.binary.Base64;

/**
     * 模板压缩
     *
     * @param xml 模板xml
     * @return
     * @throws Exception
     */
    public static String businessData(String xml) throws Exception {
        if (StringUtils.isBlank(xml)) {
            return "";
        }
        // xml报文压缩
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (GZIPOutputStream gzip = new GZIPOutputStream(out)) {
            gzip.write(xml.getBytes(StandardCharsets.UTF_8));
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 压缩后转base64字符串
        return Base64.encodeBase64String(out.toByteArray());
    }
相关推荐
m5655bj1 天前
C# 在 PDF 文档中添加电子签名
开发语言·pdf·c#
虾说羊1 天前
java中的代理详解
java
LinHenrY12271 天前
初识C语言(预处理详解)
c语言·开发语言
Larry_Yanan1 天前
Qt多进程(四)QTcpSocket
开发语言·c++·qt·ui
野生技术架构师1 天前
2025年Java面试八股文大全(附PDF版)
java·面试·pdf
Coder_Boy_1 天前
SpringAI与LangChain4j的智能应用-(实践篇4)
java·人工智能·spring boot·langchain
CC.GG1 天前
【Qt】常用控件----QWidget属性
java·数据库·qt
hqwest1 天前
码上通QT实战02--登录设计
开发语言·qt·登录·ui设计·qt控件·qt布局·qt登录
superman超哥1 天前
仓颉Actor模型的实现机制深度解析
开发语言·后端·python·c#·仓颉