public void onBlock(
        final DirectBuffer termBuffer, final int termOffset, final int length, final int sessionId, final int termId)
    {
        try
        {
            final boolean isPaddingFrame = termBuffer.getShort(typeOffset(termOffset)) == PADDING_FRAME_TYPE;
            final int dataLength = isPaddingFrame ? HEADER_LENGTH : length;
            final ByteBuffer byteBuffer;

            final long startNs = nanoClock.nanoTime();
            if (null == checksum || isPaddingFrame)
            {
                byteBuffer = termBuffer.byteBuffer();
                byteBuffer.limit(termOffset + dataLength).position(termOffset);
            }
            else
            {
                checksumBuffer.putBytes(0, termBuffer, termOffset, dataLength);
                computeChecksum(checksum, checksumBuffer, dataLength);
                byteBuffer = checksumBuffer.byteBuffer();
                byteBuffer.limit(dataLength).position(0);
            }

            int fileOffset = segmentOffset;
            do
            {
                fileOffset += recordingFileChannel.write(byteBuffer, fileOffset);
            }
            while (byteBuffer.remaining() > 0);

            if (forceWrites)
            {
                recordingFileChannel.force(forceMetadata);
            }

            final long writeTimeNs = nanoClock.nanoTime() - startNs;
            recorder.bytesWritten(dataLength);
            recorder.writeTimeNs(writeTimeNs);

            segmentOffset += length;
            if (segmentOffset >= segmentLength)
            {
                onFileRollOver();
            }
        }
        catch (final ClosedByInterruptException ex)
        {
            close();
            throw new ArchiveException("file closed by interrupt, recording aborted", ex, ArchiveException.GENERIC);
        }
        catch (final IOException ex)
        {
            close();
            checkErrorType(ex, length);
        }
        catch (final Exception ex)
        {
            close();
            LangUtil.rethrowUnchecked(ex);
        }
    }
@Test
    void onBlockThrowsNullPointerExceptionIfInitWasNotCalled()
    {
        final Image image = mockImage(0L);
        final RecordingWriter recordingWriter = new RecordingWriter(
            1,
            0,
            SEGMENT_LENGTH,
            image,
            new Context().archiveDir(archiveDir),
            mock(ArchiveConductor.Recorder.class));

        assertThrows(
            NullPointerException.class,
            () -> recordingWriter.onBlock(new UnsafeBuffer(allocate(32)), 0, 10, 5, 8));
    }