2023-03-04 12:19:01 +00:00
|
|
|
package nu.marginalia.bigstring;
|
2023-01-30 08:29:14 +00:00
|
|
|
|
2023-06-12 15:42:28 +00:00
|
|
|
import java.nio.ByteBuffer;
|
2023-01-30 08:29:14 +00:00
|
|
|
|
|
|
|
public class CompressedBigString implements BigString {
|
|
|
|
private final int originalSize;
|
|
|
|
private final int length;
|
2023-06-12 15:42:28 +00:00
|
|
|
private final ByteBuffer encoded;
|
2023-01-30 08:29:14 +00:00
|
|
|
|
2023-06-12 15:42:28 +00:00
|
|
|
private final static CompressionBufferPool bufferPool = new CompressionBufferPool();
|
2023-01-30 08:29:14 +00:00
|
|
|
|
|
|
|
public CompressedBigString(String stringValue) {
|
2023-06-12 15:42:28 +00:00
|
|
|
encoded = bufferPool.bufferForThread().compress(stringValue);
|
|
|
|
originalSize = encoded.position();
|
2023-01-30 08:29:14 +00:00
|
|
|
length = stringValue.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String decode() {
|
2023-06-12 15:42:28 +00:00
|
|
|
return bufferPool.bufferForThread().decompress(encoded, length, originalSize);
|
2023-01-30 08:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int length() {
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
}
|