完成了我的代码,但经过多次调试,我仍然无法成功编译它。问题就在这里,但我似乎找不到正确的方法来纠正它。
private static class ByteConversionUtil {
private static ByteBuffer longBuffer = ByteBuffer.allocate(Long.BYTES);
private static ByteBuffer intBuffer = ByteBuffer
.allocate(Integer.BYTES);
private static byte[] longToByteArray(long value) {
longBuffer.putLong(0, value);
return longBuffer.array();
}
private static int byteArrayToInt(byte[] array) {
intBuffer.put(array, 0, array.length);
intBuffer.flip();
return intBuffer.getInt();
}
据我所知,您可能想更改中的代码
private static ByteBuffer longBuffer = ByteBuffer.allocate(Long.BYTES);
private static ByteBuffer intBuffer = ByteBuffer.allocate(Integer.BYTES);
至
private static ByteBuffer longBuffer = ByteBuffer.allocate(Long.SIZE);
private static ByteBuffer intBuffer = ByteBuffer.allocate(Integer.SIZE);
Long.SIZE为缓冲区分配64个字节
Integer.SIZE为缓冲区分配32个字节。