RandomAccessData { public OutputStream asOutputStream() { return outputStream; } RandomAccessData();  RandomAccessData(byte[] initialBuffer);  RandomAccessData(int initialBufferSize); RandomAccessData increment(); byte[] array(); int size(); void resetTo(int position); OutputStream asOutputStream(); InputStream asInputStream(final int offset, final int length); void writeTo(OutputStream out, int offset, int length); void readFrom(InputStream inStream, int offset, int length); RandomAccessData copy(); @Override boolean equals(@Nullable Object other); @Override int hashCode(); @Override String toString(); static final UnsignedLexicographicalComparator UNSIGNED_LEXICOGRAPHICAL_COMPARATOR; }
@Test public void testCoder() throws Exception { RandomAccessData streamA = new RandomAccessData(); streamA.asOutputStream().write(TEST_DATA_A); RandomAccessData streamB = new RandomAccessData(); streamB.asOutputStream().write(TEST_DATA_A); CoderProperties.coderDecodeEncodeEqual(RandomAccessDataCoder.of(), streamA); CoderProperties.coderDeterministic(RandomAccessDataCoder.of(), streamA, streamB); CoderProperties.coderConsistentWithEquals(RandomAccessDataCoder.of(), streamA, streamB); CoderProperties.coderSerializable(RandomAccessDataCoder.of()); CoderProperties.structuralValueConsistentWithEquals( RandomAccessDataCoder.of(), streamA, streamB); assertTrue(RandomAccessDataCoder.of().isRegisterByteSizeObserverCheap(streamA)); assertEquals(4, RandomAccessDataCoder.of().getEncodedElementByteSize(streamA)); }
@Test public void testLexicographicalComparator() throws Exception { RandomAccessData streamA = new RandomAccessData(); streamA.asOutputStream().write(TEST_DATA_A); RandomAccessData streamB = new RandomAccessData(); streamB.asOutputStream().write(TEST_DATA_B); RandomAccessData streamC = new RandomAccessData(); streamC.asOutputStream().write(TEST_DATA_C); assertTrue(RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.compare(streamA, streamB) < 0); assertTrue(RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.compare(streamB, streamA) > 0); assertTrue(RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.compare(streamB, streamB) == 0); assertEquals( 2, RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.commonPrefixLength(streamB, streamC)); assertTrue( RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.compare(streamB, streamC, 3) == 0); assertTrue( RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.compare( streamA, RandomAccessData.POSITIVE_INFINITY) < 0); assertTrue( RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.compare( RandomAccessData.POSITIVE_INFINITY, RandomAccessData.POSITIVE_INFINITY) == 0); assertTrue( RandomAccessData.UNSIGNED_LEXICOGRAPHICAL_COMPARATOR.compare( RandomAccessData.POSITIVE_INFINITY, streamA) > 0); }