Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let ByteBuffer read 4 bytes as int in single call #594

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/main/java/org/xerial/snappy/SnappyFramedInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.Channels;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ReadableByteChannel;
Expand Down Expand Up @@ -669,17 +670,9 @@ private FrameMetaData getFrameMetaData(ByteBuffer frameHeader)
private FrameData getFrameData(ByteBuffer content)
throws IOException
{
return new FrameData(getCrc32c(content), 4);
}

private int getCrc32c(ByteBuffer content)
{

final int position = content.position();

return ((content.get(position + 3) & 0xFF) << 24)
| ((content.get(position + 2) & 0xFF) << 16)
| ((content.get(position + 1) & 0xFF) << 8)
| (content.get(position) & 0xFF);
// the first 4 bytes are the crc32c value in little endian order
content.order(ByteOrder.LITTLE_ENDIAN);
final int crc32c = content.getInt(content.position());
return new FrameData(crc32c, 4);
}
}
Loading