/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param channel {@link SelectableChannel} * @param bb the ByteBuffer to write. * @return * @throws java.io.IOException */ public static long flushChannel(SelectableChannel channel, ByteBuffer bb) throws IOException{ return flushChannel(channel,bb,defaultWriteTimeout); }
/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param socketChannel {@link SocketChannel} * @param bb the ByteBuffer to write. * @return * @throws java.io.IOException */ public static long flushChannel(SocketChannel socketChannel, ByteBuffer[] bb) throws IOException{ return flushChannel(socketChannel,bb,defaultWriteTimeout); }
/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param channel {@link SelectableChannel} * @param bb the ByteBuffer to write. * @return * @throws java.io.IOException */ public static long flushChannel(SelectableChannel channel, ByteBuffer bb) throws IOException{ return flushChannel(channel,bb,defaultWriteTimeout); }
/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param socketChannel {@link SocketChannel} * @param bb the ByteBuffer to write. * @return * @throws java.io.IOException */ public static long flushChannel(SocketChannel socketChannel, ByteBuffer[] bb) throws IOException{ return flushChannel(socketChannel,bb,defaultWriteTimeout); }
/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param channel {@link SelectableChannel} * @param bb the ByteBuffer to write. * @return * @throws java.io.IOException */ public static long flushChannel(SelectableChannel channel, ByteBuffer bb) throws IOException{ return flushChannel(channel,bb,defaultWriteTimeout); }
/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param socketChannel {@link SocketChannel} * @param bb the ByteBuffer to write. * @return * @throws java.io.IOException */ public static long flushChannel(SocketChannel socketChannel, ByteBuffer[] bb) throws IOException{ return flushChannel(socketChannel,bb,defaultWriteTimeout); }
/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param datagramChannel * @param socketAddress * @param bb the ByteBuffer to write. * @return * @throws java.io.IOException */ public static long flushChannel(DatagramChannel datagramChannel, SocketAddress socketAddress, ByteBuffer bb) throws IOException{ return flushChannel(datagramChannel,socketAddress,bb,defaultWriteTimeout); }
/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param datagramChannel * @param socketAddress * @param bb the ByteBuffer to write. * @return * @throws java.io.IOException */ public static long flushChannel(DatagramChannel datagramChannel, SocketAddress socketAddress, ByteBuffer bb) throws IOException{ return flushChannel(datagramChannel,socketAddress,bb,defaultWriteTimeout); }
/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param datagramChannel * @param socketAddress * @param bb the ByteBuffer to write. * @return * @throws java.io.IOException */ public static long flushChannel(DatagramChannel datagramChannel, SocketAddress socketAddress, ByteBuffer bb) throws IOException{ return flushChannel(datagramChannel,socketAddress,bb,defaultWriteTimeout); }
/** * Flush the buffer by looping until the {@link ByteBuffer} is empty * @param bb the ByteBuffer to write. */ public void flushChannel(ByteBuffer bb) throws IOException{ OutputWriter.flushChannel(socketChannel, bb); bb.clear(); }
/** * Send the cached resource. */ protected void sendCache(SocketChannel socketChannel, FileCacheEntry entry, boolean keepAlive) throws IOException{ OutputWriter.flushChannel(socketChannel, entry.headerBuffer.slice()); ByteBuffer keepAliveBuf = keepAlive ? connectionKaBB.slice(): connectionCloseBB.slice(); OutputWriter.flushChannel(socketChannel, keepAliveBuf); OutputWriter.flushChannel(socketChannel, entry.bb.slice()); }
/** * Redirect a secure request (http) to http or https. * @param context {@link Context} of the current * {@link java.nio.channels.SelectionKey} event * @param httpHeaders HTTP headers, which will be sent with response */ private static void redirect(Context context, String httpHeaders) throws IOException{ final SocketChannel channel = (SocketChannel) context.getSelectionKey().channel(); final ByteBuffer[] byteBuffers = new ByteBuffer[2]; final ByteBuffer statusLineBuffer = SC_FOUND.slice(); final ByteBuffer headersBuffer = ByteBuffer.wrap((httpHeaders + new String((byte[]) context.getAttribute(HttpProtocolFinder.HTTP_REQUEST_URL)) + headers).getBytes()); byteBuffers[0] = statusLineBuffer; byteBuffers[1] = headersBuffer; OutputWriter.flushChannel(channel, byteBuffers); }
/** * Redirect a secure request (http) to http or https. * @param context {@link Context} of the occured * {@link SelectionKey} event * @param protocolRequest PortUnification protocol request information * @param httpHeaders HTTP headers, which will be sent with response */ private static final void redirect(Context context, PUProtocolRequest protocolRequest, String httpHeaders) throws IOException{ OutputWriter.flushChannel(protocolRequest.getChannel(), SC_FOUND.slice()); OutputWriter.flushChannel(protocolRequest.getChannel(), ByteBuffer.wrap((httpHeaders + context.getAttribute(HttpProtocolFinder.HTTP_REQUEST_URL) + headers).getBytes())); }
@Override public void writeResponseHead(Response response) throws IOException { final ByteArrayOutputStream headStream = new ByteArrayOutputStream(8192); writeResponseHead(response, headStream); final ByteBuffer buffer = ByteBuffer.wrap(headStream.toByteArray()); if (isConfidential()) { SSLOutputWriter.flushChannel(getSocketChannel(), buffer); } else { OutputWriter.flushChannel(getSocketChannel(), buffer); } buffer.clear(); }
nWrite += OutputWriter.flushChannel(channel,outputBB);
nWrite += OutputWriter.flushChannel(channel,outputBB);
try { if (ctx.getProtocol() == Controller.Protocol.TCP) { // TCP case OutputWriter.flushChannel(channel, buffer); } else if (ctx.getProtocol() == Controller.Protocol.UDP) { // UDP case DatagramChannel datagramChannel = (DatagramChannel) channel; SocketAddress address = (SocketAddress) ctx.getAttribute(ReadFilter.UDP_SOCKETADDRESS); OutputWriter.flushChannel(datagramChannel, address, buffer);
private boolean send( SocketAddress remoteAddress, SocketAddress localAddress, Message message ) throws IOException { if( controller == null ) throw new IOException( "grizzly controller must be initialized" ); if( remoteAddress == null ) throw new IOException( "remote address can not be null" ); if( message == null ) throw new IOException( "message can not be null" ); ConnectorHandler connectorHandler = null; try { connectorHandler = controller.acquireConnectorHandler( Controller.Protocol.UDP ); connectorHandler.connect( remoteAddress, localAddress ); OutputWriter.flushChannel( (DatagramChannel)connectorHandler.getUnderlyingChannel(), remoteAddress, message.getPlainByteBuffer(), writeTimeout ); } finally { if( connectorHandler != null ) { try { connectorHandler.close(); } catch( IOException e ) {} controller.releaseConnectorHandler( connectorHandler ); } } return true; } }
try { ByteBuffer byteBuffer = HtmlHelper.getErrorPage(message, code); OutputWriter.flushChannel(channel,byteBuffer); } catch (IOException ex){ SelectorThread.logger().log(Level.FINE,"CancelTask failed", ex);
/** * Send the cached resource. */ protected void sendCache(Request request, FileCacheEntry entry) throws IOException{ boolean flushBody = checkIfHeaders(request, entry); request.getResponse().setContentType(entry.contentType); request.getResponse().setContentLength(Integer.valueOf(entry.contentLength)); if (flushBody) { ByteBuffer sliced = entry.bb.slice(); ByteBuffer ob = ((SocketChannelOutputBuffer)request.getResponse() .getOutputBuffer()).getOutputByteBuffer(); int left = ob.remaining(); // It's better to execute a byte copy than two network operation. if (left > sliced.limit()){ request.getResponse().action(ActionCode.ACTION_COMMIT, null); ob.put(sliced); ((SocketChannelOutputBuffer)request.getResponse() .getOutputBuffer()).flushBuffer(); } else { request.getResponse().flush(); OutputWriter.flushChannel(request.getResponse().getChannel(),sliced); } } else { request.getResponse().flush(); } }