zhujt20 commented on code in PR #213:
URL: https://github.com/apache/tsfile/pull/213#discussion_r1732980408
##########
java/tsfile/src/main/java/org/apache/tsfile/read/TsFileSequenceReader.java:
##########
@@ -1774,14 +1820,45 @@ public ByteBuffer readCompressedPage(PageHeader header)
throws IOException {
public ByteBuffer readPage(PageHeader header, CompressionType type) throws
IOException {
ByteBuffer buffer = readData(-1, header.getCompressedSize());
- if (header.getUncompressedSize() == 0 || type ==
CompressionType.UNCOMPRESSED) {
+ IDecryptor decryptor = getDecryptor();
+ if (header.getUncompressedSize() == 0) {
return buffer;
- } // FIXME if the buffer is not array-implemented.
- IUnCompressor unCompressor = IUnCompressor.getUnCompressor(type);
- ByteBuffer uncompressedBuffer =
ByteBuffer.allocate(header.getUncompressedSize());
- unCompressor.uncompress(
- buffer.array(), buffer.position(), buffer.remaining(),
uncompressedBuffer.array(), 0);
- return uncompressedBuffer;
+ }
+ if (decryptor == null || decryptor.getEncryptionType() ==
EncryptionType.UNENCRYPTED) {
+ if (type == CompressionType.UNCOMPRESSED) {
+ return buffer;
+ } else {
+ IUnCompressor unCompressor = IUnCompressor.getUnCompressor(type);
+ ByteBuffer uncompressedBuffer =
ByteBuffer.allocate(header.getUncompressedSize());
+ unCompressor.uncompress(
+ buffer.array(), buffer.position(), buffer.remaining(),
uncompressedBuffer.array(), 0);
+ return uncompressedBuffer;
+ }
+ } else {
+ if (type == CompressionType.UNCOMPRESSED) {
+ ByteBuffer decryptedBuffer =
ByteBuffer.allocate(header.getUncompressedSize());
+ System.arraycopy(
+ decryptor.decrypt(buffer.array(), buffer.position(),
buffer.remaining()),
+ 0,
+ decryptedBuffer.array(),
+ 0,
+ buffer.remaining());
+ return decryptedBuffer;
+ } else {
+ ByteBuffer decryptedBuffer =
ByteBuffer.allocate(header.getCompressedSize());
+ System.arraycopy(
+ decryptor.decrypt(buffer.array(), buffer.position(),
buffer.remaining()),
+ 0,
+ decryptedBuffer.array(),
+ 0,
+ buffer.remaining());
+ IUnCompressor unCompressor = IUnCompressor.getUnCompressor(type);
+ ByteBuffer uncompressedBuffer =
ByteBuffer.allocate(header.getUncompressedSize());
+ unCompressor.uncompress(
+ decryptedBuffer.array(), 0, buffer.remaining(),
uncompressedBuffer.array(), 0);
+ return uncompressedBuffer;
+ }
+ }
Review Comment:
codes here mainly for not copying data when unencrypted and uncompressed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]