Home / Function/ sendResource() — netty Function Reference

sendResource() — netty Function Reference

Architecture documentation for the sendResource() function in StompWebSocketClientPageHandler.java from the netty codebase.

Function java Buffer Search calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  1347a6f5_daf3_a657_75a5_08dccb979171["sendResource()"]
  b42dfc71_9168_e756_15f4_7d0276b026db["StompWebSocketClientPageHandler"]
  1347a6f5_daf3_a657_75a5_08dccb979171 -->|defined in| b42dfc71_9168_e756_15f4_7d0276b026db
  a2c90322_aea7_93db_a3b3_6c785b6a2668["channelRead0()"]
  a2c90322_aea7_93db_a3b3_6c785b6a2668 -->|calls| 1347a6f5_daf3_a657_75a5_08dccb979171
  f59e6f53_60f4_c71f_4c56_9c745733d169["sendResponse()"]
  1347a6f5_daf3_a657_75a5_08dccb979171 -->|calls| f59e6f53_60f4_c71f_4c56_9c745733d169
  style 1347a6f5_daf3_a657_75a5_08dccb979171 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

example/src/main/java/io/netty/example/stomp/websocket/StompWebSocketClientPageHandler.java lines 76–129

    private static boolean sendResource(FullHttpRequest request, ChannelHandlerContext ctx) {
        if (request.uri().isEmpty() || !request.uri().startsWith("/")) {
            return false;
        }

        String requestResource = request.uri().substring(1);
        if (requestResource.isEmpty()) {
            requestResource = "index.html";
        }

        URL resourceUrl = INSTANCE.getClass().getResource(requestResource);
        if (resourceUrl == null) {
            return false;
        }

        RandomAccessFile raf = null;
        long fileLength = -1L;
        try {
            raf = new RandomAccessFile(resourceUrl.getFile(), "r");
            fileLength = raf.length();
        } catch (FileNotFoundException fne) {
            System.out.println("File not found " + fne.getMessage());
            return false;
        } catch (IOException io) {
            System.out.println("Cannot read file length " + io.getMessage());
            return false;
        } finally {
            if (fileLength < 0 && raf != null) {
                try {
                    raf.close();
                } catch (IOException io) {
                    // Nothing to do
                }
            }
        }

        HttpResponse response = new DefaultHttpResponse(request.protocolVersion(), OK);
        HttpUtil.setContentLength(response, fileLength);

        String contentType = "application/octet-stream";
        if (requestResource.endsWith("html")) {
            contentType = "text/html; charset=UTF-8";
        } else if (requestResource.endsWith("css")) {
            contentType = "text/css; charset=UTF-8";
        } else if (requestResource.endsWith("js")) {
            contentType = "application/javascript";
        }

        response.headers().set(CONTENT_TYPE, contentType);
        sendResponse(response, ctx, false);
        ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength));
        ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
        return true;
    }

Domain

Subdomains

Called By

Frequently Asked Questions

What does sendResource() do?
sendResource() is a function in the netty codebase, defined in example/src/main/java/io/netty/example/stomp/websocket/StompWebSocketClientPageHandler.java.
Where is sendResource() defined?
sendResource() is defined in example/src/main/java/io/netty/example/stomp/websocket/StompWebSocketClientPageHandler.java at line 76.
What does sendResource() call?
sendResource() calls 1 function(s): sendResponse.
What calls sendResource()?
sendResource() is called by 1 function(s): channelRead0.

Analyze Your Own Codebase

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

Try Supermodel Free