public static ORDER fromInt(final int value) { try { return ORDER.values()[value]; } catch (final ArrayIndexOutOfBoundsException e) { throw new RuntimeException("Unknown rANS order: " + value); } } }
public static ORDER fromInt(final int value) { try { return ORDER.values()[value]; } catch (final ArrayIndexOutOfBoundsException e) { throw new RuntimeException("Unknown rANS order: " + value); } } }
@Test public void testBuffersMeetBoundaryExpectations() { int size = 1001; ByteBuffer raw = ByteBuffer.wrap(randomBytes_GD(size, 0.01)); for (RANS.ORDER order : RANS.ORDER.values()) { ByteBuffer compressed = RANS.compress(raw, order, null); Assert.assertFalse(raw.hasRemaining()); Assert.assertEquals(raw.limit(), size); Assert.assertEquals(compressed.position(), 0); Assert.assertTrue(compressed.limit() > 10); Assert.assertEquals(compressed.get(), (byte) order.ordinal()); Assert.assertEquals(compressed.getInt(), compressed.limit() - 1 - 4 - 4); Assert.assertEquals(compressed.getInt(), size); compressed.rewind(); ByteBuffer uncompressed = RANS.uncompress(compressed, null); Assert.assertFalse(compressed.hasRemaining()); Assert.assertEquals(uncompressed.limit(), size); Assert.assertEquals(uncompressed.position(), 0); raw.rewind(); } }
private static void roundTrip(byte[] data) { for (RANS.ORDER order : RANS.ORDER.values()) roundTrip(data, order); }
private static void roundTrip(ByteBuffer data) { for (RANS.ORDER order : RANS.ORDER.values()) { roundTrip(data, order); data.rewind(); } }
@Test public void testRANSRoundtrip() { for(RANS.ORDER order : RANS.ORDER.values()) { final byte[] compressed = ExternalCompression.rans(TEST_BYTES, order); final byte[] restored = ExternalCompression.unrans(compressed); Assert.assertEquals(TEST_BYTES, restored); } }