class FileMultipartPart extends FileLikeMultipartPart<FilePart> {

    private final long length;
    private FileChannel channel;
    private long position;

    public FileMultipartPart(FilePart part, byte[] boundary) {
        super(part, boundary);
        File file = part.getFile();
        if (!file.exists()) {
            throw new IllegalArgumentException("File part doesn't exist: " + file.getAbsolutePath());
        }
        if (!file.canRead()) {
            throw new IllegalArgumentException("File part can't be read: " + file.getAbsolutePath());
        }
        length = file.length();
    }

    private FileChannel getChannel() throws IOException {
        if (channel == null) {
            channel = new RandomAccessFile(part.getFile(), "r").getChannel();
        }
        return channel;
    }

    @Override
    protected long getContentLength() {
        return length;
    }

    @Override
    protected long transferContentTo(ByteBuf target) throws IOException {
        // can return -1 if file is empty or FileChannel was closed
        int transferred = target.writeBytes(getChannel(), target.writableBytes());
        if (transferred > 0) {
            position += transferred;
        }
        if (position == length || transferred < 0) {
            state = MultipartState.POST_CONTENT;
            if (channel.isOpen()) {
                channel.close();
            }
        }
        return transferred;
    }

    @Override
    protected long transferContentTo(WritableByteChannel target) throws IOException {<FILL_FUNCTION_BODY>}

    @Override
    public void close() {
        super.close();
        closeSilently(channel);
    }
}

        // WARN: don't use channel.position(), it's always 0 here
        // from FileChannel javadoc: "This method does not modify this channel's
        // position."
        long transferred = getChannel().transferTo(position, BodyChunkedInput.DEFAULT_CHUNK_SIZE, target);
        if (transferred > 0) {
            position += transferred;
        }
        if (position == length || transferred < 0) {
            state = MultipartState.POST_CONTENT;
            if (channel.isOpen()) {
                channel.close();
            }
        } else {
            slowTarget = true;
        }
        return transferred;
    
<methods><variables>private static final byte[] FILE_NAME_BYTES