public void write(byte[] b, int off, int len) throws IOException { final ByteBuffer buf = ByteBuffer.wrap(b, off, len); while (buf.hasRemaining()) { try { if (write(buf) < 0) { throw new IOException("The stream is closed"); } } catch (IOException e) { /* * Unlike read, write can not inform user of partial writes. * So will close this if there was a partial write. */ if (buf.capacity() > buf.remaining()) { writer.close(); } throw e; } } }
public void write(byte[] b, int off, int len) throws IOException { final ByteBuffer buf = ByteBuffer.wrap(b, off, len); while (buf.hasRemaining()) { try { if (write(buf) < 0) { throw new IOException("The stream is closed"); } } catch (IOException e) { /* * Unlike read, write can not inform user of partial writes. * So will close this if there was a partial write. */ if (buf.capacity() > buf.remaining()) { writer.close(); } throw e; } } }
/** * Create a new ouput stream with the given timeout. If the timeout * is zero, it will be treated as infinite timeout. The socket's * channel will be configured to be non-blocking. * * @param channel * Channel for writing, should also be a {@link SelectableChannel}. * The channel will be configured to be non-blocking. * @param timeout * timeout in milliseconds. must not be negative. * @throws IOException */ public SocketOutputStream(WritableByteChannel channel, long timeout) throws IOException { SocketIOWithTimeout.checkChannelValidity(channel); writer = new Writer(channel, timeout); }
/** * Create a new ouput stream with the given timeout. If the timeout * is zero, it will be treated as infinite timeout. The socket's * channel will be configured to be non-blocking. * * @param channel * Channel for writing, should also be a {@link SelectableChannel}. * The channel will be configured to be non-blocking. * @param timeout * timeout in milliseconds. must not be negative. * @throws IOException */ public SocketOutputStream(WritableByteChannel channel, long timeout) throws IOException { SocketIOWithTimeout.checkChannelValidity(channel); writer = new Writer(channel, timeout); }
public int write(ByteBuffer src) throws IOException { return writer.doIO(src, SelectionKey.OP_WRITE); }
public int write(ByteBuffer src) throws IOException { return writer.doIO(src, SelectionKey.OP_WRITE); }
public boolean isOpen() { return writer.isOpen(); }
public synchronized void close() throws IOException { /* * close the channel since Socket.getOuputStream().close() * closes the socket. */ writer.channel.close(); writer.close(); }
/** * waits for the underlying channel to be ready for writing. * The timeout specified for this stream applies to this wait. * * @throws SocketTimeoutException * if select on the channel times out. * @throws IOException * if any other I/O error occurs. */ public void waitForWritable() throws IOException { writer.waitForIO(SelectionKey.OP_WRITE); }
public boolean isOpen() { return writer.isOpen(); }
/** * waits for the underlying channel to be ready for writing. * The timeout specified for this stream applies to this wait. * * @throws SocketTimeoutException * if select on the channel times out. * @throws IOException * if any other I/O error occurs. */ public void waitForWritable() throws IOException { writer.waitForIO(SelectionKey.OP_WRITE); }
public synchronized void close() throws IOException { /* * close the channel since Socket.getOuputStream().close() * closes the socket. */ writer.channel.close(); writer.close(); }