Interface FileRegion

All Superinterfaces:
All Known Implementing Classes:

public interface FileRegion
extends ExternalResourceReleasable

A region of a file that is sent via a Channel which supports zero-copy file transfer.

Upgrade your JDK / JRE

FileChannel.transferTo(long, long, WritableByteChannel) has at least four known bugs in the old versions of Sun JDK and perhaps its derived ones. Please upgrade your JDK to 1.6.0_18 or later version if you are going to use zero-copy file transfer.

Check your operating system and JDK / JRE

If your operating system (or JDK / JRE) does not support zero-copy file transfer, sending a file with FileRegion might fail or yield worse performance. For example, sending a large file doesn't work well in Windows.

Not all transports support it

Currently, the NIO transport is the only transport that supports FileRegion. Attempting to write a FileRegion to non-NIO Channel will trigger a ClassCastException or a similar exception.

$Rev: 2080 $, $Date: 2010-01-26 18:04:19 +0900 (Tue, 26 Jan 2010) $
The Netty Project, Trustin Lee

Method Summary
 long getCount()
          Returns the number of bytes to transfer.
 long getPosition()
          Returns the offset in the file where the transfer began.
 long transferTo(WritableByteChannel target, long position)
          Transfers the content of this file region to the specified channel.
Methods inherited from interface org.jboss.netty.util.ExternalResourceReleasable

Method Detail


long getPosition()
Returns the offset in the file where the transfer began.


long getCount()
Returns the number of bytes to transfer.


long transferTo(WritableByteChannel target,
                long position)
                throws IOException
Transfers the content of this file region to the specified channel.

target - the destination of the transfer
position - the relative offset of the file where the transfer begins from. For example, 0 will make the transfer start from getPosition()th byte and getCount() - 1 will make the last byte of the region transferred.

Copyright © 2008-2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.