FileRegion

cc.otavia.core.channel.FileRegion
trait FileRegion extends ReferenceCounted

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

=== Upgrade your JDK / JRE ===

java.nio.channels.FileChannel.transferTo 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.

  • 5103988
    • FileChannel.transferTo() should return -1 for EAGAIN instead throws IOException
  • 6253145
    • FileChannel.transferTo() on Linux fails when going beyond 2GB boundary
  • 6427312
    • FileChannel.transferTo() throws IOException "system call interrupted"
  • 6470086
    • FileChannel.transferTo(2147483647, 1, channel) causes "Value too large" exception

=== 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 ===

Attributes

Graph
Supertypes
trait ReferenceCounted
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def count: Long

Returns the number of bytes to transfer.

Returns the number of bytes to transfer.

Attributes

def countBytes: Array[Byte]
def isOpen: Boolean

Returns true if the FileRegion has a open file-descriptor

Returns true if the FileRegion has a open file-descriptor

Attributes

def position: Long

Returns the offset in the file where the transfer began.

Returns the offset in the file where the transfer began.

Attributes

def transferTo(target: WritableByteChannel, position: Long): Long

Transfers the content of this file region to the specified channel.

Transfers the content of this file region to the specified channel.

Value parameters

position

the relative offset of the file where the transfer begins from. For example, 0 will make the transfer start from positionth byte and count - 1 will make the last byte of the region transferred.

target

the destination of the transfer

Attributes

def transferred: Long

Returns the bytes which was transferred already.

Returns the bytes which was transferred already.

Attributes

Inherited methods

def refCnt: Int

Returns the reference count of this object. If 0, it means this object has been deallocated.

Returns the reference count of this object. If 0, it means this object has been deallocated.

Attributes

Inherited from:
ReferenceCounted
def release(decrement: Int): Boolean

Decreases the reference count by the specified decrement and deallocates this object if the reference count reaches at 0.

Decreases the reference count by the specified decrement and deallocates this object if the reference count reaches at 0.

Value parameters

decrement

decrement reference count

Attributes

Returns

true if and only if the reference count became 0 and this object has been deallocated

Inherited from:
ReferenceCounted
def release: Boolean

Decreases the reference count by 1 and deallocates this object if the reference count reaches at 0.

Decreases the reference count by 1 and deallocates this object if the reference count reaches at 0.

Attributes

Returns

true if and only if the reference count became 0 and this object has been deallocated

Inherited from:
ReferenceCounted
def retain(increment: Int): ReferenceCounted.this.type

Increases the reference count by the specified increment.

Increases the reference count by the specified increment.

Attributes

Inherited from:
ReferenceCounted
def retain: ReferenceCounted.this.type

Increases the reference count by 1.

Increases the reference count by 1.

Attributes

Inherited from:
ReferenceCounted