Home / Function/ addContent() — netty Function Reference

addContent() — netty Function Reference

Architecture documentation for the addContent() function in AbstractDiskHttpData.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  ca0a2f7b_500d_bf2d_b3d5_ab79c81f8f40["addContent()"]
  a3bc8afe_67a4_7958_deb1_2411299eac70["AbstractDiskHttpData"]
  ca0a2f7b_500d_bf2d_b3d5_ab79c81f8f40 -->|defined in| a3bc8afe_67a4_7958_deb1_2411299eac70
  style ca0a2f7b_500d_bf2d_b3d5_ab79c81f8f40 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpData.java lines 151–208

    @Override
    public void addContent(ByteBuf buffer, boolean last)
            throws IOException {
        if (buffer != null) {
            try {
                int localsize = buffer.readableBytes();
                checkSize(size + localsize);
                if (definedSize > 0 && definedSize < size + localsize) {
                    throw new IOException("Out of size: " + (size + localsize) +
                            " > " + definedSize);
                }
                if (file == null) {
                    file = tempFile();
                }
                if (fileChannel == null) {
                    RandomAccessFile accessFile = new RandomAccessFile(file, "rw");
                    fileChannel = accessFile.getChannel();
                }
                int remaining = localsize;
                long position = fileChannel.position();
                int index = buffer.readerIndex();
                while (remaining > 0) {
                    int written = buffer.getBytes(index, fileChannel, position, remaining);
                    if (written < 0) {
                        break;
                    }
                    remaining -= written;
                    position += written;
                    index += written;
                }
                fileChannel.position(position);
                buffer.readerIndex(index);
                size += localsize - remaining;
            } finally {
                // Release the buffer as it was retained before and we not need a reference to it at all
                // See https://github.com/netty/netty/issues/1516
                buffer.release();
            }
        }
        if (last) {
            if (file == null) {
                file = tempFile();
            }
            if (fileChannel == null) {
                RandomAccessFile accessFile = new RandomAccessFile(file, "rw");
                fileChannel = accessFile.getChannel();
            }
            try {
                fileChannel.force(false);
            } finally {
                fileChannel.close();
            }
            fileChannel = null;
            setCompleted();
        } else {
            ObjectUtil.checkNotNull(buffer, "buffer");
        }
    }

Subdomains

Frequently Asked Questions

What does addContent() do?
addContent() is a function in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpData.java.
Where is addContent() defined?
addContent() is defined in codec-http/src/main/java/io/netty/handler/codec/http/multipart/AbstractDiskHttpData.java at line 151.

Analyze Your Own Codebase

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

Try Supermodel Free