FileServerHandler Class — netty Architecture
Architecture documentation for the FileServerHandler class in FileServerHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD bfe8a22c_48cc_17d2_2d18_ebe39ee40e8f["FileServerHandler"] 9d542aa2_09b2_2a2b_4ed0_93086430b72f["FileServerHandler.java"] bfe8a22c_48cc_17d2_2d18_ebe39ee40e8f -->|defined in| 9d542aa2_09b2_2a2b_4ed0_93086430b72f 3ef91b1a_f1f0_ec9f_ef59_aca55645e968["channelActive()"] bfe8a22c_48cc_17d2_2d18_ebe39ee40e8f -->|method| 3ef91b1a_f1f0_ec9f_ef59_aca55645e968 67d32c29_a386_1165_f49f_f518e28eb45b["channelRead0()"] bfe8a22c_48cc_17d2_2d18_ebe39ee40e8f -->|method| 67d32c29_a386_1165_f49f_f518e28eb45b 5e5d62b0_fe15_27cf_64eb_7b9de2721c3c["exceptionCaught()"] bfe8a22c_48cc_17d2_2d18_ebe39ee40e8f -->|method| 5e5d62b0_fe15_27cf_64eb_7b9de2721c3c
Relationship Graph
Source Code
example/src/main/java/io/netty/example/file/FileServerHandler.java lines 28–72
public class FileServerHandler extends SimpleChannelInboundHandler<String> {
@Override
public void channelActive(ChannelHandlerContext ctx) {
ctx.writeAndFlush("HELLO: Type the path of the file to retrieve.\n");
}
@Override
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
RandomAccessFile raf = null;
long length = -1;
try {
raf = new RandomAccessFile(msg, "r");
length = raf.length();
} catch (Exception e) {
ctx.writeAndFlush("ERR: " + e.getClass().getSimpleName() + ": " + e.getMessage() + '\n');
return;
} finally {
if (length < 0 && raf != null) {
raf.close();
}
}
ctx.write("OK: " + raf.length() + '\n');
if (ctx.pipeline().get(SslHandler.class) == null) {
// SSL not enabled - can use zero-copy file transfer.
ctx.write(new DefaultFileRegion(raf.getChannel(), 0, length));
} else {
// SSL enabled - cannot use zero-copy file transfer.
ctx.write(new ChunkedFile(raf));
}
ctx.writeAndFlush("\n");
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
if (ctx.channel().isActive()) {
ctx.writeAndFlush("ERR: " +
cause.getClass().getSimpleName() + ": " +
cause.getMessage() + '\n').addListener(ChannelFutureListener.CLOSE);
}
}
}
Source
Frequently Asked Questions
What is the FileServerHandler class?
FileServerHandler is a class in the netty codebase, defined in example/src/main/java/io/netty/example/file/FileServerHandler.java.
Where is FileServerHandler defined?
FileServerHandler is defined in example/src/main/java/io/netty/example/file/FileServerHandler.java at line 28.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free