001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.mina.core.file;
021
022import java.nio.channels.FileChannel;
023
024/**
025 * Indicates the region of a file to be sent to the remote host.
026 *
027 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
028 */
029public interface FileRegion {
030
031    /**
032     * The open <tt>FileChannel</tt> from which data will be read to send to
033     * remote host.
034     *
035     * @return  An open <tt>FileChannel</tt>.
036     */
037    FileChannel getFileChannel();
038
039    /**
040     * The current file position from which data will be read.
041     *
042     * @return  The current file position.
043     */
044    long getPosition();
045
046    /**
047     * Updates the current file position based on the specified amount. This
048     * increases the value returned by {@link #getPosition()} and
049     * {@link #getWrittenBytes()} by the given amount and decreases the value
050     * returned by {@link #getRemainingBytes()} by the given {@code amount}.
051     * 
052     * @param amount
053     *            The new value for the file position.
054     */
055    void update(long amount);
056
057    /**
058     * The number of bytes remaining to be written from the file to the remote
059     * host.
060     *
061     * @return  The number of bytes remaining to be written.
062     */
063    long getRemainingBytes();
064
065    /**
066     * The total number of bytes already written.
067     *
068     * @return  The total number of bytes already written.
069     */
070    long getWrittenBytes();
071
072    /**
073     * Provides an absolute filename for the underlying FileChannel.
074     * 
075     * @return  the absolute filename, or <tt>null</tt> if the FileRegion
076     *   does not know the filename
077     */
078    String getFilename();
079}