@Override public ChannelProgressivePromise newProgressivePromise() { return ctx.newProgressivePromise(); }
@Override public ChannelProgressivePromise newProgressivePromise() { return ctx.newProgressivePromise(); }
@Override public ChannelProgressivePromise newProgressivePromise() { return ctx.newProgressivePromise(); }
@Override public ChannelProgressivePromise newProgressivePromise() { return ctx.newProgressivePromise(); }
@Override public ChannelProgressivePromise newProgressivePromise() { return context.newProgressivePromise(); }
@Override public void close() throws IOException { try { this.flush(); FileChannel file = new FileInputStream(this.file).getChannel(); long fileLength = file.size(); HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); httpResponse.headers().set(HttpConst.CONTENT_LENGTH, fileLength); httpResponse.headers().set(HttpConst.DATE, DateKit.gmtDate()); httpResponse.headers().set(HttpConst.SERVER, "blade/" + Const.VERSION); boolean keepAlive = WebContext.request().keepAlive(); if (keepAlive) { httpResponse.headers().set(HttpConst.CONNECTION, HttpConst.KEEP_ALIVE); } // Write the initial line and the header. ctx.write(httpResponse); ctx.write(new DefaultFileRegion(file, 0, fileLength), ctx.newProgressivePromise()); // Write the end marker. ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); } finally { if(null != outputStream){ outputStream.close(); } } }
@Override public void close() throws IOException { try { this.flush(); FileChannel file = new FileInputStream(this.file).getChannel(); long fileLength = file.size(); HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); httpResponse.headers().set(HttpConst.CONTENT_LENGTH, fileLength); httpResponse.headers().set(HttpConst.DATE, DateKit.gmtDate()); httpResponse.headers().set(HttpConst.SERVER, "blade/" + Const.VERSION); boolean keepAlive = WebContext.request().keepAlive(); if (keepAlive) { httpResponse.headers().set(HttpConst.CONNECTION, HttpConst.KEEP_ALIVE); } // Write the initial line and the header. ctx.write(httpResponse); ctx.write(new DefaultFileRegion(file, 0, fileLength), ctx.newProgressivePromise()); // Write the end marker. ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); } finally { if(null != outputStream){ outputStream.close(); } } }
sendFileFuture = context.write(new DefaultFileRegion(raf.getChannel(), 0, getLength()), context.newProgressivePromise()); context.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); } else { context.newProgressivePromise()); } catch (IOException e) { throw new CustomizableResponseTypeException("Could not read file", e);
ChannelFuture lastContentFuture; if (ctx.pipeline().get(SslHandler.class) == null) { ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise()); sendFileFuture = ctx.writeAndFlush(new HttpChunkedInput(new ChunkedFile(raf, 128 * 1024)), ctx.newProgressivePromise());
sendFileFuture = ctx.write( new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise() ); new ChunkedFile(raf, 0, fileLength, 8192) ), ctx.newProgressivePromise());
sendFileFuture = ctx.write( new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise() ); new ChunkedFile(raf, 0, fileLength, 8192) ), ctx.newProgressivePromise());
@Override public ChannelProgressivePromise newProgressivePromise() { return ctx.newProgressivePromise(); }
if (ctx.pipeline().get(SslHandler.class) == null) { sendFileFuture = ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise()); sendFileFuture = ctx.writeAndFlush(new HttpChunkedInput(new ChunkedFile(raf, 0, fileLength, 8192)), ctx.newProgressivePromise());
request.context().write(defaultFileRegion, request.context().newProgressivePromise()); ChannelFuture lastContentFuture = request.context().writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { this.queryPromise = ctx.newProgressivePromise(); this.opPromise = ctx.newProgressivePromise(); this.ctx = ctx; }
@Override public ChannelProgressivePromise newProgressivePromise() { return ctx.newProgressivePromise(); }
@Override public ChannelProgressivePromise newProgressivePromise() { return ctx.newProgressivePromise(); }
@Override public ChannelProgressivePromise newProgressivePromise() { return base.newProgressivePromise(); }
@Override public ChannelProgressivePromise newProgressivePromise() { return ctx.newProgressivePromise(); }
/** * 发送文件 * * @param file 文件 * @return ChannelFuture * @throws IOException */ private ChannelFuture sendFile(File file) throws IOException { final RandomAccessFile raf = new RandomAccessFile(file, "r"); // 内容长度 long fileLength = raf.length(); this.setContentLength(fileLength); //文件类型 String contentType = HttpUtil.getMimeType(file.getName()); if(StrUtil.isBlank(contentType)){ //无法识别默认使用数据流 contentType = "application/octet-stream"; } this.setContentType(contentType); ctx.write(this.toDefaultHttpResponse()); ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise()) .addListener(FileProgressiveFutureListener.build(raf)); return sendEmptyLast(); }