前提・実現したいこと
PHPでgzcompress圧縮されたテキストをjavaのinflaterを使って解凍したいです。
しかし、以下のソースコードでは解凍が上手くいきず空白のまま返ってきます。
余計な変換を避けるためPHPからjavaで圧縮されたデータを受け取る場合、UTF-8でない方が良いでしょうか?(ISO-8859-1型式あるいはバイナリデータのまま受け取る方がいいのか)
当方初心者ゆえ原因、対策もわからずアドバイス頂ければ幸いです。
該当のソースコード
try {
String zippedString = PHPString; //PHPから取得した圧縮テキスト
byte[] output = zippedString.getBytes("UTF-8");
int compressDataLength = zippedString.getBytes("UTF-8").length;
// Decompress the bytes Inflater decompresser = new Inflater(); decompresser.setInput(output, 0, compressedDataLength); byte[] result = new byte[100]; int resultLength = decompresser.inflate(result); decompresser.end(); // Decode the bytes into a String String outputString = new String(result, 0, resultLength, "UTF-8");
} catch(java.io.UnsupportedEncodingException ex) {
// handle
} catch (java.util.zip.DataFormatException ex) {
// handle
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/02/03 07:53
退会済みユーザー
2020/02/03 10:48
2020/02/06 08:54
退会済みユーザー
2020/02/06 10:21 編集
2020/02/06 12:59