Home / Class/ DefaultFileRegion Class — netty Architecture

DefaultFileRegion Class — netty Architecture

Architecture documentation for the DefaultFileRegion class in DefaultFileRegion.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  2525a814_0b60_9da3_6f4c_3129cbf6980c["DefaultFileRegion"]
  075a760a_dbb7_5a56_f984_1446102979da["DefaultFileRegion.java"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|defined in| 075a760a_dbb7_5a56_f984_1446102979da
  b2c3b4b7_5836_cf3e_1425_b311ad8b9c93["DefaultFileRegion()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| b2c3b4b7_5836_cf3e_1425_b311ad8b9c93
  7d3ce755_cb76_02a5_2e11_eab784990c4c["isOpen()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| 7d3ce755_cb76_02a5_2e11_eab784990c4c
  d2eb7a4d_3733_4ff5_7e43_5a10fed21f1a["open()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| d2eb7a4d_3733_4ff5_7e43_5a10fed21f1a
  73f7c4a7_5274_1361_07a7_093637f6747d["position()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| 73f7c4a7_5274_1361_07a7_093637f6747d
  01f724ba_a3da_a346_b043_b39a67106ab8["count()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| 01f724ba_a3da_a346_b043_b39a67106ab8
  6e2f2bda_333b_389a_a24a_bccf48591ef4["transfered()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| 6e2f2bda_333b_389a_a24a_bccf48591ef4
  b2a1b51e_8cae_61cc_f056_071691be5ba0["transferred()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| b2a1b51e_8cae_61cc_f056_071691be5ba0
  bae3c5c8_62a5_1c82_ede3_eb8ba7bb58ba["transferTo()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| bae3c5c8_62a5_1c82_ede3_eb8ba7bb58ba
  3f70c118_2f48_f95a_33f4_fdac156c3758["deallocate()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| 3f70c118_2f48_f95a_33f4_fdac156c3758
  ab83d724_a359_1112_4654_33e5c52c8f94["FileRegion()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| ab83d724_a359_1112_4654_33e5c52c8f94
  7cf04b92_1a1a_0e5e_312a_55f4e2c4f328["validate()"]
  2525a814_0b60_9da3_6f4c_3129cbf6980c -->|method| 7cf04b92_1a1a_0e5e_312a_55f4e2c4f328

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/DefaultFileRegion.java lines 38–192

public class DefaultFileRegion extends AbstractReferenceCounted implements FileRegion {

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultFileRegion.class);
    private final File f;
    private final long position;
    private final long count;
    private long transferred;
    private FileChannel file;

    /**
     * Create a new instance
     *
     * @param fileChannel      the {@link FileChannel} which should be transferred
     * @param position         the position from which the transfer should start
     * @param count            the number of bytes to transfer
     */
    public DefaultFileRegion(FileChannel fileChannel, long position, long count) {
        this.file = ObjectUtil.checkNotNull(fileChannel, "fileChannel");
        this.position = checkPositiveOrZero(position, "position");
        this.count = checkPositiveOrZero(count, "count");
        this.f = null;
    }

    /**
     * Create a new instance using the given {@link File}. The {@link File} will be opened lazily or
     * explicitly via {@link #open()}.
     *
     * @param file         the {@link File} which should be transferred
     * @param position     the position from which the transfer should start
     * @param count        the number of bytes to transfer
     */
    public DefaultFileRegion(File file, long position, long count) {
        this.f = ObjectUtil.checkNotNull(file, "file");
        this.position = checkPositiveOrZero(position, "position");
        this.count = checkPositiveOrZero(count, "count");
    }

    /**
     * Returns {@code true} if the {@link FileRegion} has a open file-descriptor
     */
    public boolean isOpen() {
        return file != null;
    }

    /**
     * Explicitly open the underlying file-descriptor if not done yet.
     */
    public void open() throws IOException {
        if (!isOpen() && refCnt() > 0) {
            // Only open if this DefaultFileRegion was not released yet.
            file = new RandomAccessFile(f, "r").getChannel();
        }
    }

    @Override
    public long position() {
        return position;
    }

    @Override
    public long count() {
        return count;
    }

    @Deprecated
    @Override
    public long transfered() {
        return transferred;
    }

    @Override
    public long transferred() {
        return transferred;
    }

    @Override
    public long transferTo(WritableByteChannel target, long position) throws IOException {
        long count = this.count - position;
        if (count < 0 || position < 0) {
            throw new IllegalArgumentException(
                    "position out of range: " + position +

Frequently Asked Questions

What is the DefaultFileRegion class?
DefaultFileRegion is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/DefaultFileRegion.java.
Where is DefaultFileRegion defined?
DefaultFileRegion is defined in transport/src/main/java/io/netty/channel/DefaultFileRegion.java at line 38.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free