RecordFile implements Iterable<byte[]> { public void append(byte[] bytes) throws IOException { if (readonly) { throw new UnsupportedOperationException(RO_MSG); } if (bytes.length != recordSize) { final String fmt = "invalid write of %d bytes, expected %d"; final String msg = format(fmt, bytes.length, recordSize); throw new InvalidArgument(msg); } raf.write(bytes); size += bytes.length; recordCt = size / recordSize - 1; } RecordFile(final File path, final RecordMode mode,
            final Column<?>... columns); byte[] read(long record); void read(long record, byte[] bytes); byte[] read(long record, int column); void read(long record, int column, byte[] bytes); void write(long record, byte[] bytes); void write(long record, int column, byte[] bytes); void append(byte[] bytes); byte[] readMetadata(); void readMetadata(byte[] bytes); @Deprecated void writeMetadata(byte[] bytes); @Override Iterator<byte[]> iterator(); final String getPath(); final Column<?>[] getColumns(); final int getRecordSize(); final boolean isReadOnly(); final boolean isReadWrite(); final long getRecordCount(); final long getSize();  }
@Test public void testAppend() { assertEquals(test.mocksize, test.size); byte[] buffer = new byte[test.recordSize]; random.nextBytes(buffer); try { test.append(buffer); } catch (IOException e) { e.printStackTrace(); fail("unexpected exception: " + e); } assertEquals(buffer.length + test.mocksize, test.size); assertTrue(test.recordCt == 1); }
@Test public void testForEach() { assertEquals(test.mocksize, test.size); final int records = 100; byte[] write = new byte[test.recordSize]; for (int i = 0; i < records; i++) { random.nextBytes(write); try { test.append(write); } catch (IOException e) { e.printStackTrace(); fail("unexpected exception: " + e); } } int count = 0; for (byte[] buffer : test) { assertNotNull(buffer); count++; } assertTrue((records * test.recordSize + test.mocksize) == test.size); assertEquals(records, count); }
@Test(expected = ConcurrentModificationException.class) public void testConcurrentModification() { assertEquals(test.mocksize, test.size); final int records = 2; byte[] write = new byte[test.recordSize]; for (int i = 0; i < records; i++) { random.nextBytes(write); try { test.append(write); } catch (IOException e) { e.printStackTrace(); fail("unexpected exception: " + e); } } int count = 0; for (byte[] buffer : test) { assertNotNull(buffer); try { test.append(write); } catch (IOException e) { e.printStackTrace(); fail("unexpected exception: " + e); } count++; } assertTrue((records * test.recordSize) == test.size); assertEquals(records, count); }