Apache Commons Compress はアーカイブ ファイルでのみ動作します (間違っていたら訂正してください)。次のようなものが必要です
MyDB.put(LibIAmLookingFor.compress("My long string to store"));
String getBack = LibIAmLookingFor.decompress(MyDB.get()));
LZW は単なる例であり、似たようなものである可能性があります。ありがとうございました。
Apache Commons Compress はアーカイブ ファイルでのみ動作します (間違っていたら訂正してください)。次のようなものが必要です
MyDB.put(LibIAmLookingFor.compress("My long string to store"));
String getBack = LibIAmLookingFor.decompress(MyDB.get()));
LZW は単なる例であり、似たようなものである可能性があります。ありがとうございました。
Java には、ZIP 圧縮用に組み込まれたライブラリがあります。
http://docs.oracle.com/javase/6/docs/api/java/util/zip/package-summary.html
それはあなたが必要とすることをしますか?
あなたにはたくさんの選択肢があります -
Deflate アルゴリズムにはjava.util.Deflaterを使用できます。
try {
// Encode a String into bytes
String inputString = "blahblahblah??";
byte[] input = inputString.getBytes("UTF-8");
// Compress the bytes
byte[] output = new byte[100];
Deflater compresser = new Deflater();
compresser.setInput(input);
compresser.finish();
int compressedDataLength = compresser.deflate(output);
// 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
}
ただし、 gzip とGZIPOutputStreamのようなストリーミング コンプレッサーを使用することをお勧めします。
(速度を犠牲にして)さらに優れた圧縮が必要な場合は、bzip2を使用することをお勧めします。
(圧縮を犠牲にして)さらに速度が必要な場合は、lzoを使用することをお勧めします。