public static byte[] compress(byte[] data)
{
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream gzipStream = new GZIPOutputStream(baos, 6, GZIPOutputStream.MAX_LOG2_WINDOW_LENGTH);
gzipStream.write(data);
gzipStream.close();
}
catch(IOException ioe)
{
return null;
}
return baos.toByteArray();
}
樣品APIas但是,當我試圖用8900 OS 4.6大文件壓縮,我得到了一個「OutOfMemoryError異常」,所以我想知道如何壓縮爲一個塊小數據?
我已經使用此代碼如下嘗試,但它不工作,壓縮文件無法解壓縮......
file = (FileConnection)Connector.open(_fileOutputPath, Connector.READ_WRITE);
if (!file.exists()) {
file.create();
}
os = file.openOutputStream();
is = FileUtil.getInputStream(_fileInputPath, 0);
int tmpSize = 1024;
byte[] tmp = new byte[tmpSize];
int len = -1;
gzipStream = new GZIPOutputStream(os, 6, GZIPOutputStream.MAX_LOG2_WINDOW_LENGTH);
while((len = is.read(tmp, 0, tmpSize)) != -1) {
gzipStream.write(tmp, 0, len);
}
重新閱讀文檔,我認爲這是錯誤的 - RFC 1952指定了gzip文件格式。 –