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());
    }
相关推荐
hsjiasb2 小时前
FreeRTOS学习(二十七)——任务栈与栈溢出检测
开发语言·stm32·学习·学习笔记·freertos
丰锋ff3 小时前
3.1 Qt事件之事件处理器
开发语言·qt
多弗朗皮卡丘3 小时前
C语言梦开始的地方7:函数
c语言·开发语言
mldong3 小时前
"applicant" 契约:退回发起人的闭环设计
java·架构
月华路3 小时前
G1 垃圾回收:脏卡队列、记忆集与并发精化线程机制
java·开发语言
gugucoding4 小时前
47. 【Java】Java内存模型(JMM)与可见性
java·开发语言
m0_380743874 小时前
从零调用 Claude 教程
开发语言·python·node.js
起床学FPGA4 小时前
AI回答问题之后,会自动跳到最下面的问题
开发语言·javascript·ecmascript
zww89491114 小时前
校园跑腿系统开发实战指南:从需求分析到上线部署全流程解析
java
Fluxart.ai5 小时前
电商商品图审核怎么自动化?规则引擎、人工复核与发布门禁
java·前端·自动化