/** * Writes a sequence of bytes to this channel from the given buffer. * * @param src The buffer from which bytes are to be retrieved * @return The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream * @throws IOException If some other I/O error occurs */ @Override public int write(ByteBuffer src) throws IOException { return socketChannel.write(src); }
/** * Writes a sequence of bytes to this channel from the given buffer. * * @param srcs The buffer from which bytes are to be retrieved * @return The number of bytes read, possibly zero, or -1 if the channel has reached end-of-stream * @throws IOException If some other I/O error occurs */ @Override public long write(ByteBuffer[] srcs) throws IOException { return socketChannel.write(srcs); }
/** * Writes the pending {@link ByteBuffer} to the underlying channel sending data to the intended * receiver of the packet. */ @Override protected void doWrite(Object pendingWrite, SelectionKey key) throws IOException { ByteBuffer pendingBuffer = (ByteBuffer) pendingWrite; ((SocketChannel) key.channel()).write(pendingBuffer); } }
/** * Writes a sequence of bytes to this channel from the subsequence of the given buffers. * * @param srcs The buffers from which bytes are to be retrieved * @param offset The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than srcs.length. * @param length - The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset. * @return returns no.of bytes written , possibly zero. * @throws IOException If some other I/O error occurs */ @Override public long write(ByteBuffer[] srcs, int offset, int length) throws IOException { return socketChannel.write(srcs, offset, length); }
/** * Flushes the buffer to the network, non blocking. * Visible for testing. * @param buf ByteBuffer * @return boolean true if the buffer has been emptied out, false otherwise * @throws IOException */ protected boolean flush(ByteBuffer buf) throws IOException { int remaining = buf.remaining(); if (remaining > 0) { int written = socketChannel.write(buf); return written >= remaining; } return true; }
@Override public int write(ByteBuffer src) throws IOException { return getChannel().write(src); }
private void writeToSocketChannel(SocketChannel socketChannel, ByteBuffer buffer) throws IOException { while (buffer.hasRemaining()) { socketChannel.write(buffer); } }
public void send(Object dest, byte[] buf, int offset, int length) throws Exception { ByteBuffer sbuf=ByteBuffer.wrap(buf, offset, length); client_channel.write(sbuf); }
@Override void sendPacket(Packet p) throws IOException { SocketChannel sock = (SocketChannel) sockKey.channel(); if (sock == null) { throw new IOException("Socket is null!"); } p.createBB(); ByteBuffer pbb = p.bb; sock.write(pbb); } }
private void write() throws IOException { while (this.proxy.write(this.buffer) > 0) {} if (this.buffer.remaining() == 0) { this.proxy.register(this.selector, SelectionKey.OP_READ, this); this.state = HandlerState.READING; this.buffer = ByteBuffer.allocate(1024); } }
private void write(SocketChannel socketChannel, ByteBuffer buffer) throws IOException { while (buffer.hasRemaining() && socketChannel.isConnected()) { if (-1 == socketChannel.write(buffer)) { // socket broken throw new IOException("write EOF"); } } }
public int write(final ByteBuffer src) throws IOException { int res = socketChannel.write(src); checkWriteTimeout(res > 0); return res; }
/** * Copies data from out net buffer and passes it to the underlying chain. * * @throws GridNioException If send failed. */ private void writeNetBuffer() throws IgniteCheckedException { try { ch.write(outNetBuf); } catch (IOException e) { throw new IgniteCheckedException("Failed to write byte to socket.", e); } }
private boolean reportSlaveMaxOffset(final long maxOffset) { this.reportOffset.position(0); this.reportOffset.limit(8); this.reportOffset.putLong(maxOffset); this.reportOffset.position(0); this.reportOffset.limit(8); for (int i = 0; i < 3 && this.reportOffset.hasRemaining(); i++) { try { this.socketChannel.write(this.reportOffset); } catch (IOException e) { log.error(this.getServiceName() + "reportSlaveMaxOffset this.socketChannel.write exception", e); return false; } } return !this.reportOffset.hasRemaining(); }
public void close() throws IOException { sslEngine.closeOutbound(); sslEngine.getSession().invalidate(); if( socketChannel.isOpen() ) socketChannel.write( wrap( emptybuffer ) );// FIXME what if not all bytes can be written socketChannel.close(); }
public SSLSocketChannel2( SocketChannel channel , SSLEngine sslEngine , ExecutorService exec , SelectionKey key ) throws IOException { if( channel == null || sslEngine == null || exec == null ) throw new IllegalArgumentException( "parameter must not be null" ); this.socketChannel = channel; this.sslEngine = sslEngine; this.exec = exec; readEngineResult = writeEngineResult = new SSLEngineResult( Status.BUFFER_UNDERFLOW, sslEngine.getHandshakeStatus(), 0, 0 ); // init to prevent NPEs tasks = new ArrayList<Future<?>>( 3 ); if( key != null ) { key.interestOps( key.interestOps() | SelectionKey.OP_WRITE ); this.selectionKey = key; } createBuffers( sslEngine.getSession() ); // kick off handshake socketChannel.write( wrap( emptybuffer ) );// initializes res processHandshake(); }
public int write( ByteBuffer src ) throws IOException { if( !isHandShakeComplete() ) { processHandshake(); return 0; } // assert ( bufferallocations > 1 ); //see #190 //if( bufferallocations <= 1 ) { // createBuffers( sslEngine.getSession() ); //} int num = socketChannel.write( wrap( src ) ); if (writeEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) { throw new EOFException("Connection is closed"); } return num; }
void newRemoteData() throws IOException { ByteBuffer buf = ByteBuffer.allocate(1024); if (remote.read(buf) == -1) throw new IOException("disconnected"); lastData = System.currentTimeMillis(); buf.flip(); client.write(buf); }
public long write(final ByteBuffer[] srcs, final int offset, final int length) throws IOException { if (length == 1) { return write(srcs[offset]); } long res = socketChannel.write(srcs, offset, length); checkWriteTimeout(res > 0L); return res; }
@Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); ByteBuffer buf = ByteBuffer.wrap(buffer, offset, byteCount); if (!channel.isBlocking()) { throw new IllegalBlockingModeException(); } channel.write(buf); }