@Test(expected = IllegalArgumentException.class) public void testCannotExceedRecordMaxSize() throws Exception { fileRecord.createEmptyPayload(JOURNAL_MAX_RECORD_SIZE + 1); }
public ByteBuffer createEmptyPayload(int payloadSize) { if (payloadSize < 0) throw new IllegalArgumentException("Cannot specify a negative capacity when creating the payload."); final int requiredCapacity = payloadSize + RECORD_HEADER_SIZE + RECORD_TRAILER_SIZE; if (requiredCapacity > JOURNAL_MAX_RECORD_SIZE) { throw new IllegalArgumentException("Exceeding the maximum allowed record size of " + JOURNAL_MAX_RECORD_SIZE + " bytes. Requested a size of " + requiredCapacity); } recordBuffer = NioBufferPool.getInstance().poll(requiredCapacity); writeRecordHeaderFor(payloadSize, delimiter, recordBuffer); payload = (ByteBuffer) recordBuffer.slice().limit(payloadSize); writeRecordTrailerFor(delimiter, (ByteBuffer) recordBuffer.position(recordBuffer.position() + payloadSize)); recordBuffer.flip(); return payload.duplicate(); }
NioJournalFileRecord implements NioJournalConstants { public ByteBuffer createEmptyPayload(int payloadSize) { if (payloadSize < 0) throw new IllegalArgumentException("Cannot specify a negative capacity when creating the payload."); final int requiredCapacity = payloadSize + RECORD_HEADER_SIZE + RECORD_TRAILER_SIZE; if (requiredCapacity > JOURNAL_MAX_RECORD_SIZE) { throw new IllegalArgumentException("Exceeding the maximum allowed record size of " + JOURNAL_MAX_RECORD_SIZE + " bytes. Requested a size of " + requiredCapacity); } recordBuffer = NioBufferPool.getInstance().poll(requiredCapacity); writeRecordHeaderFor(payloadSize, delimiter, recordBuffer); payload = (ByteBuffer) recordBuffer.slice().limit(payloadSize); writeRecordTrailerFor(delimiter, (ByteBuffer) recordBuffer.position(recordBuffer.position() + payloadSize)); recordBuffer.flip(); return payload.duplicate(); } }
NioJournalFileRecord implements NioJournalConstants { public ByteBuffer createEmptyPayload(int payloadSize) { if (payloadSize < 0) throw new IllegalArgumentException("Cannot specify a negative capacity when creating the payload."); final int requiredCapacity = payloadSize + RECORD_HEADER_SIZE + RECORD_TRAILER_SIZE; if (requiredCapacity > JOURNAL_MAX_RECORD_SIZE) { throw new IllegalArgumentException("Exceeding the maximum allowed record size of " + JOURNAL_MAX_RECORD_SIZE + " bytes. Requested a size of " + requiredCapacity); } recordBuffer = NioBufferPool.getInstance().poll(requiredCapacity); writeRecordHeaderFor(payloadSize, delimiter, recordBuffer); payload = (ByteBuffer) recordBuffer.slice().limit(payloadSize); writeRecordTrailerFor(delimiter, (ByteBuffer) recordBuffer.position(recordBuffer.position() + payloadSize)); recordBuffer.flip(); return payload.duplicate(); } NioJournalFileRecord(UUID delimiter);   NioJournalFileRecord(UUID delimiter, ByteBuffer payload, int payloadCrc32); }
NioJournalFileRecord implements NioJournalConstants { public ByteBuffer createEmptyPayload(int payloadSize) { if (payloadSize < 0) throw new IllegalArgumentException("Cannot specify a negative capacity when creating the payload."); final int requiredCapacity = payloadSize + RECORD_HEADER_SIZE + RECORD_TRAILER_SIZE; if (requiredCapacity > JOURNAL_MAX_RECORD_SIZE) { throw new IllegalArgumentException("Exceeding the maximum allowed record size of " + JOURNAL_MAX_RECORD_SIZE + " bytes. Requested a size of " + requiredCapacity); } recordBuffer = NioBufferPool.getInstance().poll(requiredCapacity); writeRecordHeaderFor(payloadSize, delimiter, recordBuffer); payload = (ByteBuffer) recordBuffer.slice().limit(payloadSize); writeRecordTrailerFor(delimiter, (ByteBuffer) recordBuffer.position(recordBuffer.position() + payloadSize)); recordBuffer.flip(); return payload.duplicate(); } NioJournalFileRecord(UUID delimiter);   NioJournalFileRecord(UUID delimiter, ByteBuffer payload, int payloadCrc32); static String bufferToString(ByteBuffer buffer); static FindResult findNextRecord(UUID delimiter, ByteBuffer source); static NioJournalFileRecord readRecord(UUID delimiter, ByteBuffer source); static Iterable<NioJournalFileRecord> readRecords(UUID delimiter, FileChannel channel, boolean includeInvalid); static int calculateRequiredBytes(Collection<NioJournalFileRecord> records); static void disposeAll(Collection<NioJournalFileRecord> records); void dispose(); ByteBuffer createEmptyPayload(int payloadSize); void writeRecord(UUID targetDelimiter, ByteBuffer target); int getRecordSize(); ByteBuffer getPayload(); UUID getDelimiter(); boolean isValid(); @Override String toString(); }
NioJournalFileRecord implements NioJournalConstants { public ByteBuffer createEmptyPayload(int payloadSize) { if (payloadSize < 0) throw new IllegalArgumentException("Cannot specify a negative capacity when creating the payload."); final int requiredCapacity = payloadSize + RECORD_HEADER_SIZE + RECORD_TRAILER_SIZE; if (requiredCapacity > JOURNAL_MAX_RECORD_SIZE) { throw new IllegalArgumentException("Exceeding the maximum allowed record size of " + JOURNAL_MAX_RECORD_SIZE + " bytes. Requested a size of " + requiredCapacity); } recordBuffer = NioBufferPool.getInstance().poll(requiredCapacity); writeRecordHeaderFor(payloadSize, delimiter, recordBuffer); payload = (ByteBuffer) recordBuffer.slice().limit(payloadSize); writeRecordTrailerFor(delimiter, (ByteBuffer) recordBuffer.position(recordBuffer.position() + payloadSize)); recordBuffer.flip(); return payload.duplicate(); } NioJournalFileRecord(UUID delimiter);   NioJournalFileRecord(UUID delimiter, ByteBuffer payload, int payloadCrc32); static String bufferToString(ByteBuffer buffer); static FindResult findNextRecord(UUID delimiter, ByteBuffer source); static NioJournalFileRecord readRecord(UUID delimiter, ByteBuffer source); static Iterable<NioJournalFileRecord> readRecords(UUID delimiter, FileChannel channel, boolean includeInvalid); static int calculateRequiredBytes(Collection<NioJournalFileRecord> records); static void disposeAll(Collection<NioJournalFileRecord> records); void dispose(); ByteBuffer createEmptyPayload(int payloadSize); void writeRecord(UUID targetDelimiter, ByteBuffer target); int getRecordSize(); ByteBuffer getPayload(); UUID getDelimiter(); boolean isValid(); @Override String toString(); static final int RECORD_LENGTH_OFFSET; static final int RECORD_CRC32_OFFSET; static final int RECORD_HEADER_SIZE; static final int RECORD_TRAILER_SIZE; static final int REVERSE_RECORD_CRC32_OFFSET; }