WEB开发网
开发学院手机开发Android 开发 Android Java压缩Zlib,Gzip,Zip支持J2ME 阅读

Android Java压缩Zlib,Gzip,Zip支持J2ME

 2010-11-05 00:54:54 来源:WEB开发网   
核心提示:throw e;}}/*** GZip压缩数据** @param object* @return* @throws IOException*/public static byte[] gZip(byte[] bContent) throws IOException{byte[] data = null;try{Byte

throw e;

}

}

/**

* GZip压缩数据

*

* @param object

* @return

* @throws IOException

*/

public static byte[] gZip(byte[] bContent) throws IOException

{

byte[] data = null;

try

{

ByteArrayOutputStream out = new ByteArrayOutputStream();

GZIPOutputStream gOut = new GZIPOutputStream(out, bContent.length); // 压缩级别,缺省为1级

DataOutputStream objOut = new DataOutputStream(gOut);

objOut.write(bContent);

objOut.flush();

gOut.close();

data = out.toByteArray();

out.close();

}

catch (IOException e)

{

e.printStackTrace();

throw e;

}

return data;

}

/**

* GZip解压数据

*

* @param object

* @return

* @throws IOException

*/

public static byte[] unGZip(byte[] bContent) throws IOException

{

byte[] data = new byte[MAXLENGTH];

try

{

ByteArrayInputStream in = new ByteArrayInputStream(bContent);

GZIPInputStream pIn = new GZIPInputStream(in);

DataInputStream objIn = new DataInputStream(pIn);

int len = 0;

int count = 0;

while ((count = objIn.read(data, len, len + BUFFERSIZE)) != -1)

{

len = len + count;

}

byte[] trueData = new byte[len];

System.arraycopy(data, 0, trueData, 0, len);

objIn.close();

pIn.close();

in.close();

return trueData;

}

catch (IOException e)

{

e.printStackTrace();

throw e;

}

}

/***

* 压缩Zip

上一页  1 2 3 4 5 6  下一页

Tags:Android Java 压缩

编辑录入:coldstar [复制链接] [打 印]
赞助商链接