Home / Function/ testBinaryStreamUpload() — netty Function Reference

testBinaryStreamUpload() — netty Function Reference

Architecture documentation for the testBinaryStreamUpload() function in HttpPostRequestDecoderTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  112fcd5b_618f_8555_ad55_5311bffa0b94["testBinaryStreamUpload()"]
  d3dadcbe_07b1_86dc_3f34_5a56e9d1367e["HttpPostRequestDecoderTest"]
  112fcd5b_618f_8555_ad55_5311bffa0b94 -->|defined in| d3dadcbe_07b1_86dc_3f34_5a56e9d1367e
  d908db45_2339_97de_ef92_b48161642fb3["testBinaryStreamUploadWithSpace()"]
  d908db45_2339_97de_ef92_b48161642fb3 -->|calls| 112fcd5b_618f_8555_ad55_5311bffa0b94
  445a1fc6_faad_ab3a_cf84_51d1bd35a4d2["testBinaryStreamUploadWithoutSpace()"]
  445a1fc6_faad_ab3a_cf84_51d1bd35a4d2 -->|calls| 112fcd5b_618f_8555_ad55_5311bffa0b94
  style 112fcd5b_618f_8555_ad55_5311bffa0b94 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoderTest.java lines 67–114

    private static void testBinaryStreamUpload(boolean withSpace) throws Exception {
        final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
        final String contentTypeValue;
        if (withSpace) {
            contentTypeValue = "multipart/form-data; boundary=" + boundary;
        } else {
            contentTypeValue = "multipart/form-data;boundary=" + boundary;
        }
        final DefaultHttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");

        req.setDecoderResult(DecoderResult.SUCCESS);
        req.headers().add(HttpHeaderNames.CONTENT_TYPE, contentTypeValue);
        req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);

        // Force to use memory-based data.
        final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);

        for (String data : Arrays.asList("", "\r", "\r\r", "\r\r\r")) {
            final String body =
                    "--" + boundary + "\r\n" +
                            "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" +
                            "Content-Type: image/gif\r\n" +
                            "\r\n" +
                            data + "\r\n" +
                            "--" + boundary + "--\r\n";

            // Create decoder instance to test.
            final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);

            ByteBuf buf = Unpooled.copiedBuffer(body, CharsetUtil.UTF_8);
            decoder.offer(new DefaultHttpContent(buf));
            decoder.offer(new DefaultHttpContent(Unpooled.EMPTY_BUFFER));

            // Validate it's enough chunks to decode upload.
            assertTrue(decoder.hasNext());

            // Decode binary upload.
            MemoryFileUpload upload = (MemoryFileUpload) decoder.next();

            // Validate data has been parsed correctly as it was passed into request.
            assertEquals(data, upload.getString(CharsetUtil.UTF_8),
                    "Invalid decoded data [data=" + data.replaceAll("\r", "\\\\r") + ", upload=" + upload + ']');
            upload.release();
            decoder.destroy();
            buf.release();
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does testBinaryStreamUpload() do?
testBinaryStreamUpload() is a function in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoderTest.java.
Where is testBinaryStreamUpload() defined?
testBinaryStreamUpload() is defined in codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoderTest.java at line 67.
What calls testBinaryStreamUpload()?
testBinaryStreamUpload() is called by 2 function(s): testBinaryStreamUploadWithSpace, testBinaryStreamUploadWithoutSpace.

Analyze Your Own Codebase

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

Try Supermodel Free