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 8090d19
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions boot/src/main/java/org/glavo/japp/boot/JAppReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -290,8 +288,6 @@ private ByteBuffer decompressResource(
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 8090d19

Please sign in to comment.