public class DefaultFileRegion extends AbstractReferenceCounted implements FileRegion
FileRegion
implementation which transfer data from a FileChannel
or File
.
Be aware that the FileChannel
will be automatically closed once AbstractReferenceCounted.refCnt()
returns
0
.Constructor and Description |
---|
DefaultFileRegion(FileChannel file,
long position,
long count)
Create a new instance
|
DefaultFileRegion(File f,
long position,
long count)
Create a new instance using the given
File . |
Modifier and Type | Method and Description |
---|---|
long |
count()
Returns the number of bytes to transfer.
|
protected void |
deallocate()
Called once
AbstractReferenceCounted.refCnt() is equals 0. |
boolean |
isOpen()
Returns
true if the FileRegion has a open file-descriptor |
void |
open()
Explicitly open the underlying file-descriptor if not done yet.
|
long |
position()
Returns the offset in the file where the transfer began.
|
FileRegion |
retain()
Increases the reference count by
1 . |
FileRegion |
retain(int increment)
Increases the reference count by the specified
increment . |
FileRegion |
touch()
Records the current access location of this object for debugging purposes.
|
FileRegion |
touch(Object hint)
Records the current access location of this object with an additional arbitrary information for debugging
purposes.
|
long |
transfered()
Deprecated.
|
long |
transferred()
Returns the bytes which was transfered already.
|
long |
transferTo(WritableByteChannel target,
long position)
Transfers the content of this file region to the specified channel.
|
refCnt, release, release, setRefCnt
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
refCnt, release, release
public DefaultFileRegion(FileChannel file, long position, long count)
file
- the FileChannel
which should be transferedposition
- the position from which the transfer should startcount
- the number of bytes to transferpublic DefaultFileRegion(File f, long position, long count)
File
. The File
will be opened lazily or
explicitly via open()
.f
- the File
which should be transferedposition
- the position from which the transfer should startcount
- the number of bytes to transferpublic boolean isOpen()
true
if the FileRegion
has a open file-descriptorpublic void open() throws IOException
IOException
public long position()
FileRegion
position
in interface FileRegion
public long count()
FileRegion
count
in interface FileRegion
@Deprecated public long transfered()
FileRegion
transfered
in interface FileRegion
public long transferred()
FileRegion
transferred
in interface FileRegion
public long transferTo(WritableByteChannel target, long position) throws IOException
FileRegion
transferTo
in interface FileRegion
target
- the destination of the transferposition
- the relative offset of the file where the transfer
begins from. For example, 0 will make the
transfer start from FileRegion.position()
th byte and
FileRegion.count()
- 1 will make the last
byte of the region transferred.IOException
protected void deallocate()
AbstractReferenceCounted
AbstractReferenceCounted.refCnt()
is equals 0.deallocate
in class AbstractReferenceCounted
public FileRegion retain()
ReferenceCounted
1
.retain
in interface FileRegion
retain
in interface ReferenceCounted
retain
in class AbstractReferenceCounted
public FileRegion retain(int increment)
ReferenceCounted
increment
.retain
in interface FileRegion
retain
in interface ReferenceCounted
retain
in class AbstractReferenceCounted
public FileRegion touch()
ReferenceCounted
ResourceLeakDetector
. This method is a shortcut to touch(null)
.touch
in interface FileRegion
touch
in interface ReferenceCounted
touch
in class AbstractReferenceCounted
public FileRegion touch(Object hint)
ReferenceCounted
ResourceLeakDetector
.touch
in interface FileRegion
touch
in interface ReferenceCounted
Copyright © 2008–2017 The Netty Project. All rights reserved.