@Override
  public void appendFrom(ReadableByteChannel channel, long size) throws StoreException {
    validateAppendSize(size);
    if (!fileChannel.isOpen()) {
      throw new StoreException("Channel is closed when trying to write into log segment",
          StoreErrorCodes.ChannelClosed);
    }
    int bytesWritten = 0;
    while (bytesWritten < size) {
      byteBufferForAppend.position(0);
      if (byteBufferForAppend.capacity() > size - bytesWritten) {
        byteBufferForAppend.limit((int) size - bytesWritten);
      } else {
        byteBufferForAppend.limit(byteBufferForAppend.capacity());
      }
      try {
        if (channel.read(byteBufferForAppend) < 0) {
          throw new StoreException("ReadableByteChannel length less than requested size!",
              StoreErrorCodes.UnknownError);
        }
        byteBufferForAppend.flip();
        while (byteBufferForAppend.hasRemaining()) {
          bytesWritten += fileChannel.write(byteBufferForAppend, endOffset.get() + bytesWritten);
        }
      } catch (IOException e) {
        StoreErrorCodes errorCode = StoreException.resolveErrorCode(e);
        throw new StoreException(errorCode.toString() + " while writing into the log segment", e, errorCode);
      }
    }
    endOffset.addAndGet(bytesWritten);
  }
{@inheritDoc}
<p/>
Attempts to write the {@code channel} in its entirety in this segment. To guarantee that the write is persisted,
{@link #flush()} has to be called.
<p/>
The write is not started if it cannot be completed.
@param channel The channel from which data needs to be written from
@param size The amount of data in bytes to be written from the channel
@throws IllegalArgumentException if there is not enough space for data of size {@code size}.
@throws StoreException if data could not be written to the file because of store exception
ambry-store/src/main/java/com/github/ambry/store/LogSegment.java