commonTestFileDelimiterLFLastChunk() — netty Function Reference
Architecture documentation for the commonTestFileDelimiterLFLastChunk() function in HttpPostMultiPartRequestDecoderTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 523c0890_ba6c_c7dc_ca77_3d00b84a4bf8["commonTestFileDelimiterLFLastChunk()"] 8ca6727e_4177_9097_12de_7bccb17e5dea["HttpPostMultiPartRequestDecoderTest"] 523c0890_ba6c_c7dc_ca77_3d00b84a4bf8 -->|defined in| 8ca6727e_4177_9097_12de_7bccb17e5dea 9a1cdf90_d657_c3fd_6a11_831826b58e84["testFileDelimiterLFLastChunkDecoderDiskFactory()"] 9a1cdf90_d657_c3fd_6a11_831826b58e84 -->|calls| 523c0890_ba6c_c7dc_ca77_3d00b84a4bf8 a0e1cf46_2569_dd6a_5039_2dbba86049ed["testFileDelimiterLFLastChunkDecoderMemoryFactory()"] a0e1cf46_2569_dd6a_5039_2dbba86049ed -->|calls| 523c0890_ba6c_c7dc_ca77_3d00b84a4bf8 b4c4a770_82b2_a78b_e8f1_e3dad89a9963["testFileDelimiterLFLastChunkDecoderMixedFactory()"] b4c4a770_82b2_a78b_e8f1_e3dad89a9963 -->|calls| 523c0890_ba6c_c7dc_ca77_3d00b84a4bf8 style 523c0890_ba6c_c7dc_ca77_3d00b84a4bf8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostMultiPartRequestDecoderTest.java lines 393–487
private static void commonTestFileDelimiterLFLastChunk(HttpDataFactory factory, boolean inMemory)
throws IOException {
int nbChunks = 2;
int bytesPerChunk = 100000;
int bytesLastChunk = 10000;
int fileSize = bytesPerChunk * nbChunks + bytesLastChunk; // set Xmx to a number lower than this and it crashes
String delimiter = "--861fbeab-cd20-470c-9609-d40a0f704466";
String prefix = delimiter + "\n" +
"Content-Disposition: form-data; name=\"image\"; filename=\"guangzhou.jpeg\"\n" +
"Content-Type: image/jpeg\n" +
"Content-Length: " + fileSize + "\n" +
"\n";
String suffix = "--861fbeab-cd20-470c-9609-d40a0f704466--";
byte[] bsuffix = suffix.getBytes(CharsetUtil.UTF_8);
byte[] bsuffixReal = new byte[bsuffix.length + 2];
for (int i = 0; i < bsuffix.length; i++) {
bsuffixReal[1 + i] = bsuffix[i];
}
bsuffixReal[0] = HttpConstants.LF;
bsuffixReal[bsuffixReal.length - 1] = HttpConstants.CR;
byte[] lastbody = {HttpConstants.LF};
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/upload");
request.headers().set("content-type", "multipart/form-data; boundary=861fbeab-cd20-470c-9609-d40a0f704466");
// +4 => 2xCRLF (beginning, end)
request.headers().set("content-length", prefix.length() + fileSize + suffix.length() + 4);
HttpPostMultipartRequestDecoder decoder = new HttpPostMultipartRequestDecoder(factory, request);
ByteBuf buf = Unpooled.wrappedBuffer(prefix.getBytes(CharsetUtil.UTF_8));
DefaultHttpContent httpContent = new DefaultHttpContent(buf);
decoder.offer(httpContent);
assertNotNull(((HttpData) decoder.currentPartialHttpData()).content());
httpContent.release();
byte[] body = new byte[bytesPerChunk];
Arrays.fill(body, (byte) 1);
// Set first bytes as CRLF to ensure it is correctly getting the last CRLF
body[0] = HttpConstants.CR;
body[1] = HttpConstants.LF;
for (int i = 0; i < nbChunks; i++) {
ByteBuf content = Unpooled.wrappedBuffer(body, 0, bytesPerChunk);
httpContent = new DefaultHttpContent(content);
decoder.offer(httpContent); // **OutOfMemory previously here**
assertNotNull(((HttpData) decoder.currentPartialHttpData()).content());
httpContent.release();
}
// Last -2 body = content + CR but no delimiter
byte[] previousLastbody = new byte[bytesLastChunk + 1];
Arrays.fill(previousLastbody, (byte) 1);
previousLastbody[bytesLastChunk] = HttpConstants.CR;
ByteBuf content2 = Unpooled.wrappedBuffer(previousLastbody, 0, previousLastbody.length);
httpContent = new DefaultHttpContent(content2);
decoder.offer(httpContent);
assertNotNull(decoder.currentPartialHttpData());
httpContent.release();
// Last -1 body = LF+delimiter+CR but no LF
content2 = Unpooled.wrappedBuffer(bsuffixReal, 0, bsuffixReal.length);
httpContent = new DefaultHttpContent(content2);
decoder.offer(httpContent);
assertNull(decoder.currentPartialHttpData());
httpContent.release();
// Last (LF)
content2 = Unpooled.wrappedBuffer(lastbody, 0, lastbody.length);
httpContent = new DefaultHttpContent(content2);
decoder.offer(httpContent);
assertNull(decoder.currentPartialHttpData());
httpContent.release();
// End
decoder.offer(new DefaultLastHttpContent());
FileUpload data = (FileUpload) decoder.getBodyHttpDatas().get(0);
assertEquals(data.length(), fileSize);
assertEquals(inMemory, data.isInMemory());
if (data.isInMemory()) {
// To be done only if not inMemory: assertEquals(data.get().length, fileSize);
assertFalse(data.getByteBuf().capacity() < fileSize,
"Capacity should be at least file size");
}
assertTrue(decoder.getCurrentAllocatedCapacity() < fileSize,
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does commonTestFileDelimiterLFLastChunk() do?
commonTestFileDelimiterLFLastChunk() is a function in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostMultiPartRequestDecoderTest.java.
Where is commonTestFileDelimiterLFLastChunk() defined?
commonTestFileDelimiterLFLastChunk() is defined in codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostMultiPartRequestDecoderTest.java at line 393.
What calls commonTestFileDelimiterLFLastChunk()?
commonTestFileDelimiterLFLastChunk() is called by 3 function(s): testFileDelimiterLFLastChunkDecoderDiskFactory, testFileDelimiterLFLastChunkDecoderMemoryFactory, testFileDelimiterLFLastChunkDecoderMixedFactory.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free