public void writeSegment(
UUID segmentId, byte[] data, int offset, int length,
List<UUID> referencedSegmentIds) {
byte[] buffer = new byte[length];
System.arraycopy(data, offset, buffer, 0, length);
Segment segment = new Segment(
this, segmentId, ByteBuffer.wrap(buffer),
Lists.newArrayList(referencedSegmentIds));
if (segments.putIfAbsent(segment.getSegmentId(), segment) != null) {
throw new IllegalStateException(
"Segment override: " + segment.getSegmentId());
}
}