@Override
  public int appendFrom(ByteBuffer buffer) throws StoreException {
    int bytesWritten = 0;
    validateAppendSize(buffer.remaining());
    try {
      while (buffer.hasRemaining()) {
        bytesWritten += fileChannel.write(buffer, endOffset.get() + bytesWritten);
      }
    } catch (ClosedChannelException e) {
      throw new StoreException("Channel closed while writing into the log segment", e, StoreErrorCodes.ChannelClosed);
    } catch (IOException e) {
      StoreErrorCodes errorCode = StoreException.resolveErrorCode(e);
      throw new StoreException(errorCode.toString() + " while writing into the log segment", e, errorCode);
    }
    endOffset.addAndGet(bytesWritten);
    return bytesWritten;
  }
{@inheritDoc}
<p/>
Attempts to write the {@code buffer} 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 buffer The buffer from which data needs to be written from
@return the number of bytes written.
@throws IllegalArgumentException if there is not enough space for {@code buffer}
@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