void concat(StreamSegmentData other, long offset) throws BadOffsetException, StreamSegmentSealedException {
synchronized (this.context.syncRoot) {
synchronized (other.lock) {
Preconditions.checkState(other.sealed, "Cannot concat segment '%s' into '%s' because it is not sealed.", other.name, this.name);
other.checkOpened();
synchronized (this.lock) {
checkOpened();
if (offset != this.length) {
throw new BadOffsetException(this.name, this.length, offset);
}
long bytesCopied = 0;
int currentBlockIndex = 0;
while (bytesCopied < other.length) {
byte[] currentBlock = other.data.get(currentBlockIndex);
int length = (int) Math.min(currentBlock.length, other.length - bytesCopied);
ByteArrayInputStream bis = new ByteArrayInputStream(currentBlock, 0, length);
writeInternal(this.length, bis, length);
bytesCopied += length;
currentBlockIndex++;
}
}
}
}
}