From 8090d19af764ea2a0ae8a1ab2f1d295e33016e83 Mon Sep 17 00:00:00 2001 From: Glavo Date: Sat, 20 Jan 2024 02:51:10 +0800 Subject: [PATCH] Simplify JAppReader::decompressResource --- .../main/java/org/glavo/japp/boot/JAppReader.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/boot/src/main/java/org/glavo/japp/boot/JAppReader.java b/boot/src/main/java/org/glavo/japp/boot/JAppReader.java index ec8f4ad..18016ae 100644 --- a/boot/src/main/java/org/glavo/japp/boot/JAppReader.java +++ b/boot/src/main/java/org/glavo/japp/boot/JAppReader.java @@ -272,16 +272,14 @@ private ByteBuffer decompressResource( CompressionMethod method, ByteBuffer compressed, int size) throws IOException { - - byte[] output = new byte[size]; - ByteBuffer outputBuffer = ByteBuffer.wrap(output); - switch (method) { case CLASSFILE: { + byte[] output = new byte[size]; ClassFileDecompressor.decompress(this, compressed, output); - break; + return ByteBuffer.wrap(output); } case ZSTD: { + ByteBuffer outputBuffer = ByteBuffer.allocate(size); decompressZstd(compressed, outputBuffer); outputBuffer.flip(); break; @@ -290,8 +288,6 @@ private ByteBuffer decompressResource( throw new IOException("Unsupported compression method: " + method); } } - - return outputBuffer; } private int castArrayLength(long value) { @@ -316,7 +312,7 @@ public ByteBuffer readResource(JAppResource resource) throws IOException { if (mappedBuffer != null) { compressed = ByteBufferUtils.slice(mappedBuffer, offset, compressedSize); } else { - compressed = ByteBuffer.allocate(compressedSize); + compressed = ByteBuffer.allocateDirect(compressedSize); while (compressed.hasRemaining()) { int n = channel.read(compressed, offset + baseOffset + compressed.position());