AbstractMemoryHttpDataTest Class — netty Architecture
Architecture documentation for the AbstractMemoryHttpDataTest class in AbstractMemoryHttpDataTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 3b2d0623_5311_2698_e2c8_4ff0f0e583b8["AbstractMemoryHttpDataTest"] 2328324c_b02a_ae11_439a_8425604f4ff4["AbstractMemoryHttpDataTest.java"] 3b2d0623_5311_2698_e2c8_4ff0f0e583b8 -->|defined in| 2328324c_b02a_ae11_439a_8425604f4ff4 437d1625_b451_a488_7de2_a1cd75813c10["testSetContentFromFile()"] 3b2d0623_5311_2698_e2c8_4ff0f0e583b8 -->|method| 437d1625_b451_a488_7de2_a1cd75813c10 fdc5e253_7006_e873_2db6_b22045254ef9["testRenameTo()"] 3b2d0623_5311_2698_e2c8_4ff0f0e583b8 -->|method| fdc5e253_7006_e873_2db6_b22045254ef9 ef875a46_31e7_9a01_f78a_3896ddf5e359["testSetContentFromStream()"] 3b2d0623_5311_2698_e2c8_4ff0f0e583b8 -->|method| ef875a46_31e7_9a01_f78a_3896ddf5e359
Relationship Graph
Source Code
codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpDataTest.java lines 44–207
public class AbstractMemoryHttpDataTest {
@Test
public void testSetContentFromFile() throws Exception {
TestHttpData test = new TestHttpData("test", UTF_8, 0);
try {
File tmpFile = PlatformDependent.createTempFile(UUID.randomUUID().toString(), ".tmp", null);
tmpFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tmpFile);
byte[] bytes = new byte[4096];
ThreadLocalRandom.current().nextBytes(bytes);
try {
fos.write(bytes);
fos.flush();
} finally {
fos.close();
}
test.setContent(tmpFile);
ByteBuf buf = test.getByteBuf();
assertEquals(buf.readerIndex(), 0);
assertEquals(buf.writerIndex(), bytes.length);
assertArrayEquals(bytes, test.get());
assertArrayEquals(bytes, ByteBufUtil.getBytes(buf));
} finally {
//release the ByteBuf
test.delete();
}
}
@Test
public void testRenameTo() throws Exception {
TestHttpData test = new TestHttpData("test", UTF_8, 0);
try {
File tmpFile = PlatformDependent.createTempFile(UUID.randomUUID().toString(), ".tmp", null);
tmpFile.deleteOnExit();
final int totalByteCount = 4096;
byte[] bytes = new byte[totalByteCount];
ThreadLocalRandom.current().nextBytes(bytes);
ByteBuf content = Unpooled.wrappedBuffer(bytes);
test.setContent(content);
boolean succ = test.renameTo(tmpFile);
assertTrue(succ);
try (FileInputStream fis = new FileInputStream(tmpFile)) {
byte[] buf = new byte[totalByteCount];
int count = 0;
int offset = 0;
int size = totalByteCount;
while ((count = fis.read(buf, offset, size)) > 0) {
offset += count;
size -= count;
if (offset >= totalByteCount || size <= 0) {
break;
}
}
assertArrayEquals(bytes, buf);
assertEquals(0, fis.available());
}
} finally {
//release the ByteBuf in AbstractMemoryHttpData
test.delete();
}
}
/**
* Provide content into HTTP data with input stream.
*
* @throws Exception In case of any exception.
*/
@Test
public void testSetContentFromStream() throws Exception {
// definedSize=0
TestHttpData test = new TestHttpData("test", UTF_8, 0);
String contentStr = "foo_test";
ByteBuf buf = Unpooled.wrappedBuffer(contentStr.getBytes(UTF_8));
buf.markReaderIndex();
try (ByteBufInputStream is = new ByteBufInputStream(buf)) {
test.setContent(is);
assertFalse(buf.isReadable());
assertEquals(contentStr, test.getString(UTF_8));
buf.resetReaderIndex();
assertTrue(ByteBufUtil.equals(buf, test.getByteBuf()));
}
Defined In
Source
Frequently Asked Questions
What is the AbstractMemoryHttpDataTest class?
AbstractMemoryHttpDataTest is a class in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpDataTest.java.
Where is AbstractMemoryHttpDataTest defined?
AbstractMemoryHttpDataTest is defined in codec-http/src/test/java/io/netty/handler/codec/http/multipart/AbstractMemoryHttpDataTest.java at line 44.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free