Java中关于超长字符串压缩,解压缩问题

问题:数据库中varchar类型的长度设置为5000,通过一个富文本编辑器编辑了通知内容,接收到了内容字段长度为8000多,unruly数据库时候,数据库报错(字段太长,显示下标越界异常)

解决办法:通过将得到的内容压缩后存入数据库中,取数据时候,将数据解压缩即可

代码案例如下所示:(一个字符串长度为一万以上,通过压缩后,长度仅为800左右,完全满足存库条件)

package vaadin.demo;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class VaadinDemo {
	/**
     * 字符串的压缩
     */
    public static String compress(String str) throws IOException {
        if (null == str || str.length() <= 0) {
            return str;
        }
        // 创建一个新的 byte 数组输出流
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        // 使用默认缓冲区大小创建新的输出流
        GZIPOutputStream gzip = new GZIPOutputStream(out);
        // 将 b.length 个字节写入此输出流
        gzip.write(str.getBytes());
        gzip.close();
        // 使用指定的 charsetName,通过解码字节将缓冲区内容转换为字符串
        return out.toString("ISO-8859-1");
    }

    /**
     * 字符串的解压
     */
    public static String unCompress(String str) throws IOException {
        if (null == str || str.length() <= 0) {
            return str;
        }
        // 创建一个新的 byte 数组输出流
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        // 创建一个 ByteArrayInputStream,使用 buf 作为其缓冲区数组
        ByteArrayInputStream in = new ByteArrayInputStream(str
                .getBytes("ISO-8859-1"));
        // 使用默认缓冲区大小创建新的输入流
        GZIPInputStream gzip = new GZIPInputStream(in);
        byte[] buffer = new byte[256];
        int n = 0;
        while ((n = gzip.read(buffer)) >= 0) {// 将未压缩数据读入字节数组
            // 将指定 byte 数组中从偏移量 off 开始的 len 个字节写入此 byte数组输出流
            out.write(buffer, 0, n);
        }
        // 使用指定的 charsetName,通过解码字节将缓冲区内容转换为字符串
        return out.toString("GBK");
    }
	public static void main(String[] args) throws IOException {

		String content = "<p style='text-align: right;'><span style='text-decoration: underline; color: rgb(255, 0, 0);'"
				+ "><em><strong>Dear All,&nbsp;&nbsp;</strong></em></span></p><p><br/></p><p>近期Jerry Shih会来到AGS。"
				+ "</p><p><br/></p><p>作为AGS的一员,请大家配合以下事项,让我们共同展现出AGS的专业风貌!</p><p><b"
				+ "r/></p><p>时间:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请按时上、下班,避免"
				+ "迟到或早退。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中午按时吃饭(12:00),"
				+ "请不要提前。</p><p><br/></p><p>公共设施:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &n"
				+ "bsp;中午请大家在就餐区吃午饭,请不要在会议室或座位上就餐。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp;"
				+ " &nbsp; &nbsp;带饭的同仁请不要把饭盒放在吧台上,请放在冰箱。</p><p><br/></p><p>·&nbsp; &nbsp; &"
				+ "nbsp; &nbsp; &nbsp;最后下班的同事请确认所有空调、灯等设备电源是否关闭。</p><p><br/></p><p st"
				+ "yle='text-align: justify;'>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VIP厕所请不要使用(哺乳期"
				+ "员工除外)。</p><p><br/></p><p>仪表:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbs"
				+ "p;着装需正式,颜色庄重、款式大方,请不要穿着休闲装。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp"
				+ "; &nbsp; &nbsp;请避免大声喧哗。</p><p><br/></p><p>办公环境:</p><p><br/></p><p>·&nbsp; &nbsp"
				+ "; &nbsp; &nbsp; &nbsp;请保证办公桌桌面的整洁。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp"
				+ "; &nbsp;外套、围巾等服饰请挂在衣架或收进柜子里,请不要搭在椅背或放在桌面上。</p><p><br/></p><p>信息"
				+ "安全:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;离开座位时请锁掉电脑。</p><p><br/>"
				+ "</p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;涉及保密信息的文件请不要放在桌面上。</p><p><br/></"
				+ "p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请不要把信息留在白板上。</p><p><br/></p><p>HR &amp; A"
				+ "dmin</p><p><br/></p><p>AMAX Global Services</p><p><br/></p>"
				+"<p style='text-align: right;'><span style='text-decoration: underline; color: rgb(255, 0, 0);'"
				+ "><em><strong>Dear All,&nbsp;&nbsp;</strong></em></span></p><p><br/></p><p>近期Jerry Shih会来到AGS。"
				+ "</p><p><br/></p><p>作为AGS的一员,请大家配合以下事项,让我们共同展现出AGS的专业风貌!</p><p><b"
				+ "r/></p><p>时间:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请按时上、下班,避免"
				+ "迟到或早退。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中午按时吃饭(12:00),"
				+ "请不要提前。</p><p><br/></p><p>公共设施:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &n"
				+ "bsp;中午请大家在就餐区吃午饭,请不要在会议室或座位上就餐。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp;"
				+ " &nbsp; &nbsp;带饭的同仁请不要把饭盒放在吧台上,请放在冰箱。</p><p><br/></p><p>·&nbsp; &nbsp; &"
				+ "nbsp; &nbsp; &nbsp;最后下班的同事请确认所有空调、灯等设备电源是否关闭。</p><p><br/></p><p st"
				+ "yle='text-align: justify;'>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VIP厕所请不要使用(哺乳期"
				+ "员工除外)。</p><p><br/></p><p>仪表:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbs"
				+ "p;着装需正式,颜色庄重、款式大方,请不要穿着休闲装。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp"
				+ "; &nbsp; &nbsp;请避免大声喧哗。</p><p><br/></p><p>办公环境:</p><p><br/></p><p>·&nbsp; &nbsp"
				+ "; &nbsp; &nbsp; &nbsp;请保证办公桌桌面的整洁。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp"
				+ "; &nbsp;外套、围巾等服饰请挂在衣架或收进柜子里,请不要搭在椅背或放在桌面上。</p><p><br/></p><p>信息"
				+ "安全:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;离开座位时请锁掉电脑。</p><p><br/>"
				+ "</p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;涉及保密信息的文件请不要放在桌面上。</p><p><br/></"
				+ "p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请不要把信息留在白板上。</p><p><br/></p><p>HR &amp; A"
				+ "dmin</p><p><br/></p><p>AMAX Global Services</p><p><br/></p>"
				+"><em><strong>Dear All,&nbsp;&nbsp;</strong></em></span></p><p><br/></p><p>近期Jerry Shih会来到AGS。"
				+ "</p><p><br/></p><p>作为AGS的一员,请大家配合以下事项,让我们共同展现出AGS的专业风貌!</p><p><b"
				+ "r/></p><p>时间:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请按时上、下班,避免"
				+ "迟到或早退。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中午按时吃饭(12:00),"
				+ "请不要提前。</p><p><br/></p><p>公共设施:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &n"
				+ "bsp;中午请大家在就餐区吃午饭,请不要在会议室或座位上就餐。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp;"
				+ " &nbsp; &nbsp;带饭的同仁请不要把饭盒放在吧台上,请放在冰箱。</p><p><br/></p><p>·&nbsp; &nbsp; &"
				+ "nbsp; &nbsp; &nbsp;最后下班的同事请确认所有空调、灯等设备电源是否关闭。</p><p><br/></p><p st"
				+ "yle='text-align: justify;'>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VIP厕所请不要使用(哺乳期"
				+ "员工除外)。</p><p><br/></p><p>仪表:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbs"
				+ "p;着装需正式,颜色庄重、款式大方,请不要穿着休闲装。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp"
				+ "; &nbsp; &nbsp;请避免大声喧哗。</p><p><br/></p><p>办公环境:</p><p><br/></p><p>·&nbsp; &nbsp"
				+ "; &nbsp; &nbsp; &nbsp;请保证办公桌桌面的整洁。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp"
				+ "; &nbsp;外套、围巾等服饰请挂在衣架或收进柜子里,请不要搭在椅背或放在桌面上。</p><p><br/></p><p>信息"
				+ "安全:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;离开座位时请锁掉电脑。</p><p><br/>"
				+ "</p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;涉及保密信息的文件请不要放在桌面上。</p><p><br/></"
				+ "p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请不要把信息留在白板上。</p><p><br/></p><p>HR &amp; A"
				+ "dmin</p><p><br/></p><p>AMAX Global Services</p><p><br/></p>"
				+"<p style='text-align: right;'><span style='text-decoration: underline; color: rgb(255, 0, 0);'"
				+ "><em><strong>Dear All,&nbsp;&nbsp;</strong></em></span></p><p><br/></p><p>近期Jerry Shih会来到AGS。"
				+ "</p><p><br/></p><p>作为AGS的一员,请大家配合以下事项,让我们共同展现出AGS的专业风貌!</p><p><b"
				+ "r/></p><p>时间:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请按时上、下班,避免"
				+ "迟到或早退。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中午按时吃饭(12:00),"
				+ "请不要提前。</p><p><br/></p><p>公共设施:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &n"
				+ "bsp;中午请大家在就餐区吃午饭,请不要在会议室或座位上就餐。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp;"
				+ " &nbsp; &nbsp;带饭的同仁请不要把饭盒放在吧台上,请放在冰箱。</p><p><br/></p><p>·&nbsp; &nbsp; &"
				+ "nbsp; &nbsp; &nbsp;最后下班的同事请确认所有空调、灯等设备电源是否关闭。</p><p><br/></p><p st"
				+ "yle='text-align: justify;'>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VIP厕所请不要使用(哺乳期"
				+ "员工除外)。</p><p><br/></p><p>仪表:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbs"
				+ "p;着装需正式,颜色庄重、款式大方,请不要穿着休闲装。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp"
				+ "; &nbsp; &nbsp;请避免大声喧哗。</p><p><br/></p><p>办公环境:</p><p><br/></p><p>·&nbsp; &nbsp"
				+ "; &nbsp; &nbsp; &nbsp;请保证办公桌桌面的整洁。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp"
				+ "; &nbsp;外套、围巾等服饰请挂在衣架或收进柜子里,请不要搭在椅背或放在桌面上。</p><p><br/></p><p>信息"
				+ "安全:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;离开座位时请锁掉电脑。</p><p><br/>"
				+ "</p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;涉及保密信息的文件请不要放在桌面上。</p><p><br/></"
				+ "p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请不要把信息留在白板上。</p><p><br/></p><p>HR &amp; A"
				+ "dmin</p><p><br/></p><p>AMAX Global Services</p><p><br/></p>"+"><em><strong>Dear All,&nbsp;&nbsp;</strong></em></span></p><p><br/></p><p>近期Jerry Shih会来到AGS。"
				+ "</p><p><br/></p><p>作为AGS的一员,请大家配合以下事项,让我们共同展现出AGS的专业风貌!</p><p><b"
				+ "r/></p><p>时间:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请按时上、下班,避免"
				+ "迟到或早退。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中午按时吃饭(12:00),"
				+ "请不要提前。</p><p><br/></p><p>公共设施:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &n"
				+ "bsp;中午请大家在就餐区吃午饭,请不要在会议室或座位上就餐。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp;"
				+ " &nbsp; &nbsp;带饭的同仁请不要把饭盒放在吧台上,请放在冰箱。</p><p><br/></p><p>·&nbsp; &nbsp; &"
				+ "nbsp; &nbsp; &nbsp;最后下班的同事请确认所有空调、灯等设备电源是否关闭。</p><p><br/></p><p st"
				+ "yle='text-align: justify;'>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VIP厕所请不要使用(哺乳期"
				+ "员工除外)。</p><p><br/></p><p>仪表:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbs"
				+ "p;着装需正式,颜色庄重、款式大方,请不要穿着休闲装。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp"
				+ "; &nbsp; &nbsp;请避免大声喧哗。</p><p><br/></p><p>办公环境:</p><p><br/></p><p>·&nbsp; &nbsp"
				+ "; &nbsp; &nbsp; &nbsp;请保证办公桌桌面的整洁。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp"
				+ "; &nbsp;外套、围巾等服饰请挂在衣架或收进柜子里,请不要搭在椅背或放在桌面上。</p><p><br/></p><p>信息"
				+ "安全:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;离开座位时请锁掉电脑。</p><p><br/>"
				+ "</p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;涉及保密信息的文件请不要放在桌面上。</p><p><br/></"
				+ "p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请不要把信息留在白板上。</p><p><br/></p><p>HR &amp; A"
				+ "dmin</p><p><br/></p><p>AMAX Global Services</p><p><br/></p>"
				+"<p style='text-align: right;'><span style='text-decoration: underline; color: rgb(255, 0, 0);'"
				+ "><em><strong>Dear All,&nbsp;&nbsp;</strong></em></span></p><p><br/></p><p>近期Jerry Shih会来到AGS。"
				+ "</p><p><br/></p><p>作为AGS的一员,请大家配合以下事项,让我们共同展现出AGS的专业风貌!</p><p><b"
				+ "r/></p><p>时间:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请按时上、下班,避免"
				+ "迟到或早退。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中午按时吃饭(12:00),"
				+ "请不要提前。</p><p><br/></p><p>公共设施:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &n"
				+ "bsp;中午请大家在就餐区吃午饭,请不要在会议室或座位上就餐。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp;"
				+ " &nbsp; &nbsp;带饭的同仁请不要把饭盒放在吧台上,请放在冰箱。</p><p><br/></p><p>·&nbsp; &nbsp; &"
				+ "nbsp; &nbsp; &nbsp;最后下班的同事请确认所有空调、灯等设备电源是否关闭。</p><p><br/></p><p st"
				+ "yle='text-align: justify;'>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VIP厕所请不要使用(哺乳期"
				+ "员工除外)。</p><p><br/></p><p>仪表:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbs"
				+ "p;着装需正式,颜色庄重、款式大方,请不要穿着休闲装。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp"
				+ "; &nbsp; &nbsp;请避免大声喧哗。</p><p><br/></p><p>办公环境:</p><p><br/></p><p>·&nbsp; &nbsp"
				+ "; &nbsp; &nbsp; &nbsp;请保证办公桌桌面的整洁。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp"
				+ "; &nbsp;外套、围巾等服饰请挂在衣架或收进柜子里,请不要搭在椅背或放在桌面上。</p><p><br/></p><p>信息"
				+ "安全:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;离开座位时请锁掉电脑。</p><p><br/>"
				+ "</p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;涉及保密信息的文件请不要放在桌面上。</p><p><br/></"
				+ "p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请不要把信息留在白板上。</p><p><br/></p><p>HR &amp; A"
				+ "dmin</p><p><br/></p><p>AMAX Global Services</p><p><br/></p>"
				+"><em><strong>Dear All,&nbsp;&nbsp;</strong></em></span></p><p><br/></p><p>近期Jerry Shih会来到AGS。"
				+ "</p><p><br/></p><p>作为AGS的一员,请大家配合以下事项,让我们共同展现出AGS的专业风貌!</p><p><b"
				+ "r/></p><p>时间:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请按时上、下班,避免"
				+ "迟到或早退。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中午按时吃饭(12:00),"
				+ "请不要提前。</p><p><br/></p><p>公共设施:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &n"
				+ "bsp;中午请大家在就餐区吃午饭,请不要在会议室或座位上就餐。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp;"
				+ " &nbsp; &nbsp;带饭的同仁请不要把饭盒放在吧台上,请放在冰箱。</p><p><br/></p><p>·&nbsp; &nbsp; &"
				+ "nbsp; &nbsp; &nbsp;最后下班的同事请确认所有空调、灯等设备电源是否关闭。</p><p><br/></p><p st"
				+ "yle='text-align: justify;'>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VIP厕所请不要使用(哺乳期"
				+ "员工除外)。</p><p><br/></p><p>仪表:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbs"
				+ "p;着装需正式,颜色庄重、款式大方,请不要穿着休闲装。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp"
				+ "; &nbsp; &nbsp;请避免大声喧哗。</p><p><br/></p><p>办公环境:</p><p><br/></p><p>·&nbsp; &nbsp"
				+ "; &nbsp; &nbsp; &nbsp;请保证办公桌桌面的整洁。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp"
				+ "; &nbsp;外套、围巾等服饰请挂在衣架或收进柜子里,请不要搭在椅背或放在桌面上。</p><p><br/></p><p>信息"
				+ "安全:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;离开座位时请锁掉电脑。</p><p><br/>"
				+ "</p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;涉及保密信息的文件请不要放在桌面上。</p><p><br/></"
				+ "p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请不要把信息留在白板上。</p><p><br/></p><p>HR &amp; A"
				+ "dmin</p><p><br/></p><p>AMAX Global Services</p><p><br/></p>"
				+"<p style='text-align: right;'><span style='text-decoration: underline; color: rgb(255, 0, 0);'"
				+ "><em><strong>Dear All,&nbsp;&nbsp;</strong></em></span></p><p><br/></p><p>近期Jerry Shih会来到AGS。"
				+ "</p><p><br/></p><p>作为AGS的一员,请大家配合以下事项,让我们共同展现出AGS的专业风貌!</p><p><b"
				+ "r/></p><p>时间:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请按时上、下班,避免"
				+ "迟到或早退。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;中午按时吃饭(12:00),"
				+ "请不要提前。</p><p><br/></p><p>公共设施:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &n"
				+ "bsp;中午请大家在就餐区吃午饭,请不要在会议室或座位上就餐。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp;"
				+ " &nbsp; &nbsp;带饭的同仁请不要把饭盒放在吧台上,请放在冰箱。</p><p><br/></p><p>·&nbsp; &nbsp; &"
				+ "nbsp; &nbsp; &nbsp;最后下班的同事请确认所有空调、灯等设备电源是否关闭。</p><p><br/></p><p st"
				+ "yle='text-align: justify;'>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;VIP厕所请不要使用(哺乳期"
				+ "员工除外)。</p><p><br/></p><p>仪表:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbs"
				+ "p;着装需正式,颜色庄重、款式大方,请不要穿着休闲装。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp"
				+ "; &nbsp; &nbsp;请避免大声喧哗。</p><p><br/></p><p>办公环境:</p><p><br/></p><p>·&nbsp; &nbsp"
				+ "; &nbsp; &nbsp; &nbsp;请保证办公桌桌面的整洁。</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp"
				+ "; &nbsp;外套、围巾等服饰请挂在衣架或收进柜子里,请不要搭在椅背或放在桌面上。</p><p><br/></p><p>信息"
				+ "安全:</p><p><br/></p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;离开座位时请锁掉电脑。</p><p><br/>"
				+ "</p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;涉及保密信息的文件请不要放在桌面上。</p><p><br/></"
				+ "p><p>·&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;请不要把信息留在白板上。</p><p><br/></p><p>HR &amp; A"
				+ "dmin</p><p><br/></p><p>AMAX Global Services</p><p><br/></p>";
		System.out.println(content);
		System.out.println("字符串长度为:" + content.length());
		
		
		String ysStr = compress(content);
        System.out.println("\n压缩后的字符串为----->" + ysStr);
        float len1 = ysStr.length();
        System.out.println("压缩后的字符串长度为----->" + len1);

        String jyStr = unCompress(ysStr);
        System.out.println("\n解压缩后的字符串为--->" + jyStr);
        System.out.println("解压缩后的字符串长度为--->" + jyStr.length());

        //判断
        if(jyStr.equals(content)){
        	System.out.println("解压后的字符串是一样的。。。。");
        }else{
        	System.out.println("解压后的字符串不是一样的。。。。");
        }
        
	}

}

/**
* 字符串gzip压缩
*/
 @SuppressWarnings("restriction")
	public static String gzip(String primStr) {
    	if (primStr == null || primStr.length() == 0) {
    		return primStr;
    	}
    	ByteArrayOutputStream out = new ByteArrayOutputStream();
    	GZIPOutputStream gzip=null;
    	try {
    		gzip = new GZIPOutputStream(out);
    		gzip.write(primStr.getBytes());
    	} catch (IOException e) {
    		e.printStackTrace();
    	}finally{
	    	if(gzip!=null){
		    	try {
		    		gzip.close();
		    	} catch (IOException e) {
		    		e.printStackTrace();
		    	}
	    	}
    	}
    	return new sun.misc.BASE64Encoder().encode(out.toByteArray());
    }
/**
     * 字符串的解压
     * Aaron Wang
     * 2019-06-03
     */
    @SuppressWarnings("restriction")
	public static String jyZip(String compressedStr){
    	if(compressedStr == null){
    	return null;
    	}

    	ByteArrayOutputStream out = new ByteArrayOutputStream();
    	ByteArrayInputStream in = null;
    	GZIPInputStream ginzip = null;
    	byte[] compressed = null;
    	String decompressed = null;
    	try {
    		compressed = new sun.misc.BASE64Decoder().decodeBuffer(compressedStr);
    		in=new ByteArrayInputStream(compressed);
    		ginzip=new GZIPInputStream(in);

	    	byte[] buffer = new byte[1024];
	    	int offset = -1;
	    	while ((offset = ginzip.read(buffer)) != -1) {
	    	out.write(buffer, 0, offset);
	    	}
	    	decompressed=out.toString();
    	} catch (IOException e) {
    		e.printStackTrace();
		} finally {
			if (ginzip != null) {
				try {
					ginzip.close();
				} catch (IOException e) {
				}
			}
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
				}
			}
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {
				}
			}
		}
    	return decompressed;
    }

 

 

 

 

  • 5
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是王小贱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值