package com.flight.inter.otaadapter.manage;
import com.flight.inter.otaadapter.commons.util.Base64Util;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class MessageZIPManage {
/**
* 压缩
* @param encode
* @return
*/
public static String zipEncode(String encode){
byte[] pureResult;
try {
pureResult = encode.getBytes("UTF-8");
ByteArrayInputStream inputStream =
new ByteArrayInputStream(pureResult);
ByteArrayOutputStream miwenOutput=new ByteArrayOutputStream();
GZIPOutputStream outStream =
new GZIPOutputStream ( miwenOutput);
byte[] buf = new byte[10000];
while (true) {
int size = inputStream.read(buf);
if (size <= 0)
break;
outStream.write(buf, 0, size);
}
outStream.close();
byte[] miwenbytes=miwenOutput.toByteArray();
String pursf= Base64Util.encode2Str(miwenbytes);
return pursf;
} catch (Exception e) {
return null;
}
}
/**
* 解压缩
* @param decode
* @return
*/
public static String zipDecode(String decode){
byte[] pureResult;
try {
pureResult = Base64Util.decode2ByteArray(decode);
ByteArrayOutputStream outStream =
new ByteArrayOutputStream(10 * pureResult.length);
GZIPInputStream inStream =
new GZIPInputStream ( new ByteArrayInputStream(pureResult) );
byte[] buf = new byte[10000];
while (true) {
int size = inStream.read(buf);
if (size <= 0)
break;
outStream.write(buf, 0, size);
}
outStream.close();
String pursf=new String(outStream.toByteArray());
return pursf;
} catch (Exception e) {
return null;
}
}
}