Skip to content

Commit da1af8b

Browse files
authored
internal: let ByteBuffer read 4 bytes as int in single call (#594)
1 parent 1af05fe commit da1af8b

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/main/java/org/xerial/snappy/SnappyFramedInputStream.java

+5-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.io.InputStream;
1717
import java.io.OutputStream;
1818
import java.nio.ByteBuffer;
19+
import java.nio.ByteOrder;
1920
import java.nio.channels.Channels;
2021
import java.nio.channels.ClosedChannelException;
2122
import java.nio.channels.ReadableByteChannel;
@@ -669,17 +670,9 @@ private FrameMetaData getFrameMetaData(ByteBuffer frameHeader)
669670
private FrameData getFrameData(ByteBuffer content)
670671
throws IOException
671672
{
672-
return new FrameData(getCrc32c(content), 4);
673-
}
674-
675-
private int getCrc32c(ByteBuffer content)
676-
{
677-
678-
final int position = content.position();
679-
680-
return ((content.get(position + 3) & 0xFF) << 24)
681-
| ((content.get(position + 2) & 0xFF) << 16)
682-
| ((content.get(position + 1) & 0xFF) << 8)
683-
| (content.get(position) & 0xFF);
673+
// the first 4 bytes are the crc32c value in little endian order
674+
content.order(ByteOrder.LITTLE_ENDIAN);
675+
final int crc32c = content.getInt(content.position());
676+
return new FrameData(crc32c, 4);
684677
}
685678
}

0 commit comments

Comments
 (0)