Skip to content

Instantly share code, notes, and snippets.

@mbilokonsky
Created October 29, 2013 00:23
Show Gist options
  • Save mbilokonsky/7207199 to your computer and use it in GitHub Desktop.
Save mbilokonsky/7207199 to your computer and use it in GitHub Desktop.
@Test
public void test_int_to_long_stuff() {
int x = 10;
int y = 20;
ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.putInt(x).putInt(y);
Assert.assertFalse(buffer.hasRemaining()); // confirm I used all 8 bytes
buffer.position(0);
Assert.assertTrue(buffer.hasRemaining());
long xy = buffer.getLong();
Assert.assertFalse(buffer.hasRemaining()); // again, confirm I used all 8 bytes
buffer.position(0);
Assert.assertTrue(buffer.hasRemaining());
buffer.putLong(xy);
Assert.assertFalse(buffer.hasRemaining()); // again, confirm I used all 8 bytes...
buffer.position(0);
int x2 = buffer.getInt();
int y2 = buffer.getInt();
Assert.assertFalse(buffer.hasRemaining());
Assert.assertEquals(x, x2);
Assert.assertEquals(y, y2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment