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

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

 2010-11-05 00:54:54 来源:WEB开发网   
核心提示:// /** Default compression */// public static final int COMPRESSION_DEFAULT =// JZlib.Z_DEFAULT_COMPRESSION;/*** ZLib压缩数据** @param object* @return* @throws IOEx

// /** Default compression */

// public static final int COMPRESSION_DEFAULT =

// JZlib.Z_DEFAULT_COMPRESSION;

/**

* ZLib压缩数据

*

* @param object

* @return

* @throws IOException

*/

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

{

byte[] data = null;

try

{

ByteArrayOutputStream out = new ByteArrayOutputStream();

ZOutputStream zOut = new ZOutputStream(out,

JZlib.Z_BEST_COMPRESSION); // 压缩级别,缺省为1级

DataOutputStream objOut = new DataOutputStream(zOut);

objOut.write(bContent);

objOut.flush();

zOut.close();

data = out.toByteArray();

out.close();

}

catch (IOException e)

{

e.printStackTrace();

throw e;

}

return data;

}

/**

* ZLib解压数据

*

* @param object

* @return

* @throws IOException

*/

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

{

byte[] data = new byte[MAXLENGTH];

try

{

ByteArrayInputStream in = new ByteArrayInputStream(bContent);

ZInputStream zIn = new ZInputStream(in);

DataInputStream objIn = new DataInputStream(zIn);

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();

zIn.close();

in.close();

return trueData;

}

catch (IOException e)

{

e.printStackTrace();

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

Tags:Android Java 压缩

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