/** * Reads exactly bytes from {@code in} until end-of-input into the {@code buffer} and then runs {@code finished}. */ private static void read( final ReadableByteChannel in, final Multiplexer multiplexer, final OutputStream os, final RunnableWhichThrows<IOException> finished ) throws IOException { multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, new RunnableWhichThrows<IOException>() { final ByteBuffer buffer = ByteBuffer.allocate(8192); @Override public void run() throws IOException { this.buffer.rewind(); int r = in.read(this.buffer); if (r == -1) { finished.run(); return; } os.write(this.buffer.array(), 0, r); multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, this); } }); }
@Override public void run() { try { NioTcpServer.this.multiplexer.run(); } catch (ClosedChannelException cce) { if (LOGGER.isLoggable(FINE)) LOGGER.log(FINE, "Terminating (ChannelClosedException)"); return; } catch (IOException ioe) { if (LOGGER.isLoggable(FINE)) LOGGER.log(FINE, "Terminating", ioe); return; } catch (RuntimeException re) { if (LOGGER.isLoggable(FINE)) LOGGER.log(FINE, "Terminating", re); return; } } });
@Override public void stop() { this.multiplexer.stop(); } }
runnables = Multiplexer.get2(this.timers, expiry); runnables.add(runnable);
runnables = Multiplexer.get2(this.timers, expiry); runnables.add(runnable);
/** * Reads exactly bytes from <var>in</var> until end-of-input into the <var>buffer</var> and then runs * <var>finished</var>. */ private static void read( final ReadableByteChannel in, final Multiplexer multiplexer, final OutputStream os, final RunnableWhichThrows<IOException> finished ) throws IOException { multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, new RunnableWhichThrows<IOException>() { final ByteBuffer buffer = ByteBuffer.allocate(8192); @Override public void run() throws IOException { this.buffer.rewind(); int r = in.read(this.buffer); if (r == -1) { finished.run(); return; } os.write(this.buffer.array(), 0, r); multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, this); } }); }
@Override public void stop() { this.multiplexer.stop(); } }
@Override public void run() { try { NioTcpServer.this.multiplexer.run(); } catch (ClosedChannelException cce) { if (LOGGER.isLoggable(FINE)) LOGGER.log(FINE, "Terminating (ChannelClosedException)"); return; } catch (IOException ioe) { if (LOGGER.isLoggable(FINE)) LOGGER.log(FINE, "Terminating", ioe); return; } catch (RuntimeException re) { if (LOGGER.isLoggable(FINE)) LOGGER.log(FINE, "Terminating", re); return; } } });
@Override public void run() throws IOException { this.buffer.rewind(); int r = in.read(this.buffer); if (r == -1) { finished.run(); return; } os.write(this.buffer.array(), 0, r); multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, this); } });
@Override public void run() throws IOException { this.buffer.rewind(); int r = in.read(this.buffer); if (r == -1) { finished.run(); return; } os.write(this.buffer.array(), 0, r); multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, this); } });
@Override public void run() throws IOException { this.buffer.rewind(); this.buffer.limit(Math.min(this.count, this.buffer.capacity())); int r = in.read(this.buffer); if (r == -1) throw new EOFException(); os.write(this.buffer.array(), 0, r); this.count -= r; if (this.count == 0) { finished.run(); return; } multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, this); } });
@Override public void run() throws IOException { this.buffer.rewind(); this.buffer.limit(Math.min(this.count, this.buffer.capacity())); int r = in.read(this.buffer); if (r == -1) throw new EOFException(); os.write(this.buffer.array(), 0, r); this.count -= r; if (this.count == 0) { finished.run(); return; } multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, this); } });
FileBufferedChannel.this.multiplexer.register( FileBufferedChannel.this.delegate, SelectionKey.OP_WRITE,
FileBufferedChannel.this.multiplexer.register( FileBufferedChannel.this.delegate, SelectionKey.OP_WRITE,
multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, lineParser);
multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, lineParser);
@Override public void run() throws IOException { this.buffer.rewind(); in.read(this.buffer); byte b = this.buffer.get(0); switch (this.state) { case 0: // Start. if (b == '\r') { this.state = 1; break; } this.line.write(b); break; case 1: // After CR if (b != '\n') { throw new InvalidHttpMessageException( "HTTP header line: CR is not followed by LF, but '" + (0xff & b) + "'" ); } lineConsumer.consume(new String(this.line.toByteArray(), "ISO-8859-1")); return; } multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, this); } };
multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, new RunnableWhichThrows<IOException>() {
multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, new RunnableWhichThrows<IOException>() {
@Override public void run() throws IOException { this.buffer.rewind(); in.read(this.buffer); byte b = this.buffer.get(0); switch (this.state) { case 0: // Start. if (b == '\r') { this.state = 1; break; } this.line.write(b); break; case 1: // After CR if (b != '\n') { throw new InvalidHttpMessageException( "HTTP header line: CR is not followed by LF, but '" + (0xff & b) + "'" ); } lineConsumer.consume(new String(this.line.toByteArray(), "ISO-8859-1")); return; } multiplexer.register((SelectableChannel) in, SelectionKey.OP_READ, this); } };