當前位置: 首頁>>代碼示例>>Java>>正文


Java ChunkedWriteHandler類代碼示例

本文整理匯總了Java中io.netty.handler.stream.ChunkedWriteHandler的典型用法代碼示例。如果您正苦於以下問題:Java ChunkedWriteHandler類的具體用法?Java ChunkedWriteHandler怎麽用?Java ChunkedWriteHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ChunkedWriteHandler類屬於io.netty.handler.stream包,在下文中一共展示了ChunkedWriteHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: appendHttpPipeline

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
public final ChannelPipeline appendHttpPipeline(ChannelPipeline channelPipeline) {
    // 服務端,對響應編碼。屬於ChannelOutboundHandler,逆序執行
    channelPipeline.addLast("encoder", new HttpResponseEncoder());

    // 服務端,對請求解碼。屬於ChannelIntboundHandler,按照順序執行
    channelPipeline.addLast("decoder", new HttpRequestDecoder());
    //即通過它可以把 HttpMessage 和 HttpContent 聚合成一個 FullHttpRequest,並定義可以接受的數據大小,在文件上傳時,可以支持params+multipart
    channelPipeline.addLast("aggregator", new HttpObjectAggregator(maxConentLength));
    //塊寫入寫出Handler
    channelPipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    // 對傳輸數據進行壓縮,這裏在客戶端需要解壓縮處理
    // channelPipeline.addLast("deflater", new HttpContentCompressor());

    HttpServletHandler servletHandler = new HttpServletHandler();
    servletHandler.addInterceptor(new ChannelInterceptor());
    //servletHandler.addInterceptor(new HttpSessionInterceptor(getHttpSessionStore()));
    // 自定義Handler
    channelPipeline.addLast("handler", servletHandler);
    // 異步
    // channelPipeline.addLast(businessExecutor, new AsyncHttpServletHandler());
    return channelPipeline;
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:24,代碼來源:HttpChannelInitializer.java

示例2: initChannel

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast("codec", new HttpClientCodec());

    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());

    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpUploadClientHandler());
}
 
開發者ID:cowthan,項目名稱:JavaAyo,代碼行數:19,代碼來源:HttpUploadClientIntializer.java

示例3: initChannel

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
@Override
protected void initChannel(Channel ch) throws Exception {
	ChannelPipeline pipeline = ch.pipeline();
	//編解碼http請求
	pipeline.addLast(new HttpServerCodec());
	//聚合解碼HttpRequest/HttpContent/LastHttpContent到FullHttpRequest
	//保證接收的Http請求的完整性
	pipeline.addLast(new HttpObjectAggregator(64 *1024));
	//寫文件內容
	pipeline.addLast(new ChunkedWriteHandler());
	//處理FullHttpRequest
	pipeline.addLast(new HttpRequestHandler("/ws"));
	//處理其他的WebSocketFrame
	pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
	//處理TextWebSocketFrame
	pipeline.addLast(new TextWebSocketFrameHandler(group));
}
 
開發者ID:janzolau1987,項目名稱:study-netty,代碼行數:18,代碼來源:ChatServerInitializer.java

示例4: preparePipeline

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
/**
 * {@inheritDoc}
 * <p>
 * This adds a ChunkedWriter to the pipeline to extract chunks from the
 * {@link io.netty.handler.stream.ChunkedInput} that the strategy produces. This step
 * is skipped if the handler is already present, and the placement of the handler
 * depends on the presence of the ReactiveBridge handler (see {@link NettyPipeline}).
 *
 * @param context the context from which to obtain the channel and pipeline
 */
@Override
public final void preparePipeline(NettyContext context) {
	this.addHandler = context.channel()
	                         .pipeline()
	                         .get(NettyPipeline.ChunkedWriter) == null;
	if (addHandler) {
		boolean hasReactiveBridge = context.channel()
		                                   .pipeline()
		                                   .get(NettyPipeline.ReactiveBridge) != null;

		if (hasReactiveBridge) {
			context.channel()
			       .pipeline()
			       .addBefore(NettyPipeline.ReactiveBridge,
					       NettyPipeline.ChunkedWriter,
					       new ChunkedWriteHandler());
		}
		else {
			context.channel()
			       .pipeline()
			       .addLast(NettyPipeline.ChunkedWriter, new ChunkedWriteHandler());
		}
	}
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:35,代碼來源:AbstractFileChunkedStrategy.java

示例5: start

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
public void start(int port) throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast("http-decoder", new HttpRequestDecoder());
                ch.pipeline().addLast("http-aggregator", new HttpObjectAggregator(65536));
                ch.pipeline().addLast("http-encoder", new HttpResponseEncoder());
                ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler());
                ch.pipeline().addLast("serverHandler", new HttpServerHandler());
            }
        }).option(ChannelOption.SO_BACKLOG, 1024).childOption(ChannelOption.SO_KEEPALIVE, true);

        ChannelFuture f = b.bind(port).sync();

        f.channel().closeFuture().sync();
    } finally {
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}
 
開發者ID:weibocom,項目名稱:yar-java,代碼行數:25,代碼來源:NettyYarServer.java

示例6: addHttpServerCodec

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
public static void addHttpServerCodec(@NotNull ChannelPipeline pipeline) {
  pipeline.addLast("httpRequestEncoder", new HttpResponseEncoder());
  // https://jetbrains.zendesk.com/agent/tickets/68315
  pipeline.addLast("httpRequestDecoder", new HttpRequestDecoder(16 * 1024, 16 * 1024, 8192));
  pipeline.addLast("httpObjectAggregator", new HttpObjectAggregator(MAX_CONTENT_LENGTH));
  // could be added earlier if HTTPS
  if (pipeline.get(ChunkedWriteHandler.class) == null) {
    pipeline.addLast("chunkedWriteHandler", new ChunkedWriteHandler());
  }
  pipeline.addLast("corsHandler", new CorsHandlerDoNotUseOwnLogger(CorsConfig
                                                                     .withAnyOrigin()
                                                                     .allowCredentials()
                                                                     .allowNullOrigin()
                                                                     .allowedRequestMethods(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.HEAD, HttpMethod.PATCH)
                                                                     .allowedRequestHeaders("origin", "accept", "authorization", "content-type")
                                                                     .build()));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:18,代碼來源:NettyUtil.java

示例7: main

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
public static void main(String[] args) {
	String ip = "127.0.0.1";
	int port = 8080;
	ChannelInitializer<SocketChannel> channelInit = new ChannelInitializer<SocketChannel>() {
		@Override
		protected void initChannel(SocketChannel ch) throws Exception {
			ChannelPipeline p = ch.pipeline();
			
			CorsConfig corsConfig = CorsConfig.withAnyOrigin()
					.allowedRequestHeaders("content-type","accept","MyCustomHeader")
					.allowedRequestMethods(PUT,POST,GET,DELETE)
					.build();
			
			p.addLast(new HttpResponseEncoder());
			p.addLast(new HttpRequestDecoder());
			p.addLast(new HttpObjectAggregator(65536));
			p.addLast(new ChunkedWriteHandler());
			p.addLast(new CorsHandler(corsConfig));
			p.addLast(new SimpleCORSHandler());
		}
	};
	NettyServerUtil.newHttpServerBootstrap(ip, port, channelInit);
}
 
開發者ID:duchien85,項目名稱:netty-cookbook,代碼行數:24,代碼來源:NettyHttpServerWithCORS.java

示例8: initializerFactory

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
@Bean(name = "channelInitializer")
public ChannelInitializer<SocketChannel> initializerFactory(final ApplicationContext contxt) {
	return new ChannelInitializer<SocketChannel>() {
		@Override
		public void initChannel(SocketChannel ch) throws Exception {
			SimpleChannelInboundHandler<?> channelInboundHandler = contxt.getBean(NettyHttpChannelHandler.class);
			ChannelPipeline pipeline = ch.pipeline();
			// HTTP
			pipeline.addLast(new HttpRequestDecoder());
			pipeline.addLast(new HttpResponseEncoder());
			pipeline.addLast(new HttpContentCompressor());
			pipeline.addLast(new ChunkedWriteHandler());
			// 設置處理的Handler
			pipeline.addLast(channelInboundHandler);
		}
	};
}
 
開發者ID:bleast,項目名稱:netty-http-server,代碼行數:18,代碼來源:ServerConfig.java

示例9: configNewChannel

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
@Override
public void configNewChannel(NioSocketChannel channel) {
    super.configNewChannel(channel);
    ChannelPipeline pipeline = channel.pipeline();
    // 添加 SSL 數據支持
    if (requestConfig.https()) {
        SslContext sslContent = NettyCenter.singleInstance().getSimpleClientSslContext();
        SSLEngine engine = sslContent.newEngine(channel.alloc());
        pipeline.addLast("ssl", new SslHandler(engine));
    }
    // 客戶端接收到的是httpResponse響應,所以要使用HttpResponseDecoder進行解碼
    pipeline.addLast("decoder", new HttpResponseDecoder());
    // 客戶端發送的是httprequest,所以要使用HttpRequestEncoder進行編碼
    pipeline.addLast("encoder", new HttpRequestEncoder());
    // 接收的請求累計器
    pipeline.addLast("aggegator", new HttpObjectAggregator(0x30000));
    // mime 類型寫出
    pipeline.addLast("streamew", new ChunkedWriteHandler());
    // 添加解壓器
    pipeline.addLast("decompressor", new HttpContentDecompressor());
    // add new handler
    pipeline.addLast("handler", new NettyHttpRequestChannelHandler());
}
 
開發者ID:316181444,項目名稱:GameServerFramework,代碼行數:24,代碼來源:NHttpRequest.java

示例10: createInitializer

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
protected ChannelInitializer<Channel> createInitializer() {

	return new ChannelInitializer<Channel>() {

		@Override
		protected void initChannel(Channel ch) throws Exception {
			ChannelPipeline p = ch.pipeline();
			p.addLast(new HttpServerCodec() );
			p.addLast(new ChunkedWriteHandler());
			p.addLast(new HttpObjectAggregator(64 * 1024));
			p.addLast(new EchoServerHttpRequestHandler("/ws"));
			p.addLast(new WebSocketServerProtocolHandler("/ws"));
			p.addLast(new EchoServerWSHandler());
		}
	};
}
 
開發者ID:bekwam,項目名稱:examples-javafx-repos1,代碼行數:17,代碼來源:EchoServerWS.java

示例11: HttpAPIServer

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
public HttpAPIServer(Holder holder) {
    super(holder.props.getProperty("listen.address"),
            holder.props.getIntProperty("http.port"), holder.transportTypeHolder);

    String adminRootPath = holder.props.getProperty("admin.rootPath", "/admin");

    final HttpAndWebSocketUnificatorHandler httpAndWebSocketUnificatorHandler =
            new HttpAndWebSocketUnificatorHandler(holder, port, adminRootPath);
    final LetsEncryptHandler letsEncryptHandler = new LetsEncryptHandler(holder.sslContextHolder.contentHolder);

    channelInitializer = new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline()
            .addLast("HttpServerCodec", new HttpServerCodec())
            .addLast("HttpServerKeepAlive", new HttpServerKeepAliveHandler())
            .addLast("HttpObjectAggregator", new HttpObjectAggregator(holder.limits.webRequestMaxSize, true))
            .addLast(letsEncryptHandler)
            .addLast("HttpChunkedWrite", new ChunkedWriteHandler())
            .addLast("HttpUrlMapper", new UrlReWriterHandler("/favicon.ico", "/static/favicon.ico"))
            .addLast("HttpStaticFile", new StaticFileHandler(holder.props, new StaticFile("/static"),
                    new StaticFileEdsWith(CSVGenerator.CSV_DIR, ".csv.gz")))
            .addLast("HttpWebSocketUnificator", httpAndWebSocketUnificatorHandler);
        }
    };
}
 
開發者ID:blynkkk,項目名稱:blynk-server,代碼行數:27,代碼來源:HttpAPIServer.java

示例12: initWebSocketPipeline

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
private void initWebSocketPipeline(ChannelHandlerContext ctx, String websocketPath) {
    ChannelPipeline pipeline = ctx.pipeline();

    //websockets specific handlers
    pipeline.addLast("WSWebSocketServerProtocolHandler", new WebSocketServerProtocolHandler(websocketPath, true));
    pipeline.addLast("WSWebSocket", new WebSocketHandler(stats));
    pipeline.addLast("WSMessageDecoder", new MessageDecoder(stats));
    pipeline.addLast("WSSocketWrapper", new WebSocketWrapperEncoder());
    pipeline.addLast("WSMessageEncoder", new MessageEncoder(stats));
    pipeline.addLast("WSWebSocketGenericLoginHandler", genericLoginHandler);
    pipeline.remove(this);
    pipeline.remove(ChunkedWriteHandler.class);
    pipeline.remove(UrlReWriterHandler.class);
    pipeline.remove(StaticFileHandler.class);
    pipeline.remove(LetsEncryptHandler.class);
}
 
開發者ID:blynkkk,項目名稱:blynk-server,代碼行數:17,代碼來源:HttpAndWebSocketUnificatorHandler.java

示例13: initChannel

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }
    if (enableGzip) {
        p.addLast(new HttpContentCompressor());
    }
    p.addLast(new HttpServerCodec(36192 * 2, 36192 * 8, 36192 * 16, false));
    p.addLast(new HttpServerExpectContinueHandler());
    p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
    p.addLast(new ChunkedWriteHandler());
    if (enableCors) {
        CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
        p.addLast(new CorsHandler(corsConfig));
    }
    if (null != blade.webSocketPath()) {
        p.addLast(new WebSocketServerProtocolHandler(blade.webSocketPath(), null, true));
        p.addLast(new WebSockerHandler(blade));
    }
    service.scheduleWithFixedDelay(() -> date = new AsciiString(DateKit.gmtDate(LocalDateTime.now())), 1000, 1000, TimeUnit.MILLISECONDS);
    p.addLast(new HttpServerHandler());
}
 
開發者ID:lets-blade,項目名稱:blade,代碼行數:25,代碼來源:HttpServerInitializer.java

示例14: initChannel

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
@Override
 protected void initChannel(Channel channel) throws Exception {
// Create a default pipeline implementation.
   ChannelPipeline pipeline = channel.pipeline();

   // Uncomment the following line if you want HTTPS
   // SSLEngine engine =
   // SecureChatSslContextFactory.getServerContext().createSSLEngine();
   // engine.setUseClientMode(false);
   // pipeline.addLast("ssl", new SslHandler(engine));

   pipeline.addLast("decoder", new HttpRequestDecoder());
   //pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
   pipeline.addLast("encoder", new HttpResponseEncoder());
   pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
   pipeline.addLast("deflater", new HttpContentCompressor());
   pipeline.addLast("handler", new HttpDataServerHandler(userName, appId));
 }
 
開發者ID:apache,項目名稱:tajo,代碼行數:19,代碼來源:HttpDataServerChannelInitializer.java

示例15: initChannel

import io.netty.handler.stream.ChunkedWriteHandler; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel channel) throws Exception {
  ChannelPipeline pipeline = channel.pipeline();
  if (sslFactory != null) {
    pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
  }

  int maxChunkSize = getConfig().getInt(ConfVars.SHUFFLE_FETCHER_CHUNK_MAX_SIZE.varname,
      ConfVars.SHUFFLE_FETCHER_CHUNK_MAX_SIZE.defaultIntVal);
  pipeline.addLast("codec", new HttpServerCodec(maxUrlLength, 8192, maxChunkSize));
  pipeline.addLast("aggregator", new HttpObjectAggregator(1 << 16));
  pipeline.addLast("chunking", new ChunkedWriteHandler());
  pipeline.addLast("shuffle", PullServer);
  // TODO factor security manager into pipeline
  // TODO factor out encode/decode to permit binary shuffle
  // TODO factor out decode of index to permit alt. models
}
 
開發者ID:apache,項目名稱:tajo,代碼行數:18,代碼來源:TajoPullServerService.java


注:本文中的io.netty.handler.stream.ChunkedWriteHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。