Skip to content

Commit

Permalink
Simplify JAppReader::decompressResource
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavo committed Jan 19, 2024
1 parent 1d73f51 commit 98af6f9
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions boot/src/main/java/org/glavo/japp/boot/JAppReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,26 +272,22 @@ 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;
return outputBuffer;
}
default: {
throw new IOException("Unsupported compression method: " + method);
}
}

return outputBuffer;
}

private int castArrayLength(long value) {
Expand All @@ -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());
Expand Down

0 comments on commit 98af6f9

Please sign in to comment.