這是我在Android的壓縮使用deflater數據代碼如何計算字節大小deflater壓縮輸出的Android
String inputString = "kjhdf948w37fh4ifh34789fh34789fh3489fh7348fh84f8h4f3";
byte[] input = inputString.getBytes("UTF-8");
// Compress the bytes
byte[] output = new byte[100];
Deflater compresser = new Deflater(Deflater.BEST_COMPRESSION);
compresser.setInput(input);
compresser.finish();
int compressedDataLength = compresser.deflate(output);
現在我想修復「輸出」字節數組的大小,我該怎麼設置輸出字節數組的大小。請幫我從這個問題出來。
byte[] output = new byte[100];
當前我設置了100我如何根據輸入字節動態計算輸出字節數組大小。
簡單地說,你不能...做一些像'class TheData { public lenghtOfThisStructureInBytes;/* 4 + 4 +壓縮數組長度*/public int lenghtOfTheDataBeforeCompression; byte [] theDataAfterCompression; }(我的假設是你wana把這個字節數組發送到某處 - 所以發送純字節數組發送這個結構...現在fx:如果你使用套接字,你可以讀取4個字節將它們轉換爲int(len),然後讀取len - 4)字節,你會得到結構 – Selvin 2014-09-03 11:16:57