@Override public int write( ByteBuffer src ) throws IOException { return channel.write( src ); }
_chan.write(_bb); if( RANDOM_TCP_DROP != null &&_chan instanceof SocketChannel && RANDOM_TCP_DROP.nextInt(100) == 0 ) throw new IOException("Random TCP Write Fail");
@Override public DataProcessor processAndGetNext(ByteChannel socketChannel) throws IOException { Peer self = myContext.getPeersStorage().getSelf(); Handshake handshake = Handshake.craft(myTorrentHash.getInfoHash(), self.getPeerIdArray()); if (handshake == null) { logger.warn("can not craft handshake message. Self peer id is {}, torrent hash is {}", Arrays.toString(self.getPeerIdArray()), Arrays.toString(myTorrentHash.getInfoHash())); return new ShutdownProcessor(); } ByteBuffer messageToSend = ByteBuffer.wrap(handshake.getData().array()); logger.trace("try send handshake {} to {}", handshake, socketChannel); while (messageToSend.hasRemaining()) { socketChannel.write(messageToSend); } return new HandshakeReceiver( myContext, myRemotePeerIp, myRemotePeerPort, true); }
/*int written = */sockchannel.write( buffer ); if( buffer.remaining() > 0 ) { return false;
try { final Handshake craft = Handshake.craft(hs.getInfoHash(), myContext.getPeersStorage().getSelf().getPeerIdArray()); socketChannel.write(craft.getData()); } catch (IOException e) { LoggerUtils.warnAndDebugDetails(logger, "error in sending handshake to {}", socketChannel, e);
@Override public int write( ByteBuffer src ) throws IOException { return channel.write( src ); }
public final void writeTo(ByteChannel channel) throws IOException { while (buffer.hasRemaining()) { channel.write(buffer); } } }
public final void writeTo(ByteChannel channel) throws IOException { while (buffer.hasRemaining()) { channel.write(buffer); } } }
public final void writeTo(ByteChannel channel) throws IOException { while (buffer.hasRemaining()) { channel.write(buffer); } } }
@Override public int write(byte[] buf) throws IOException { return channel.write(ByteBuffer.wrap(buf)); } }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { final ByteBuffer buf = ByteBuffer.wrap(b, off, len); mChannel.write(buf); }
private boolean writeBuffer(final ByteChannel channel) throws IOException { if (this.buffer.hasRemaining()) { channel.write(this.buffer); } return !this.buffer.hasRemaining(); }
public synchronized void flush() { try { channel.write(buf); buf.reset(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } };
public Object readObject() throws IOException { ByteArrayOutputStream baout = new ByteArrayOutputStream(); ObjectOutputStream outobj = new ObjectOutputStream(baout); // outobj.writeObject(obj); outobj.flush(); byte[] buf = baout.toByteArray(); channel.write(ByteBuffer.wrap(buf)); return null; }
public void writeObject(Object obj) throws IOException { ByteArrayOutputStream baout = new ByteArrayOutputStream(); ObjectOutputStream outobj = new ObjectOutputStream(baout); outobj.writeObject(obj); outobj.flush(); byte[] buf = baout.toByteArray(); channel.write(ByteBuffer.wrap(buf)); }
/** * ByteChannelへ書き込む * @param channel * @param value * @throws IOException */ public static void write(@NonNull final ByteChannel channel, @NonNull final String value) throws IOException { final byte[] buf = value.getBytes(UTF8); write(channel, buf.length); channel.write(ByteBuffer.wrap(buf)); }
private void writeOutPreface(final IOSession session) throws IOException { if (preface.hasRemaining()) { final ByteChannel channel = session.channel(); channel.write(preface); } if (!preface.hasRemaining()) { session.clearEvent(SelectionKey.OP_WRITE); startHttp2(session); } else { session.setEvent(SelectionKey.OP_WRITE); } }
@Test @Category( { Writable.class, Delete.class, MoveWhile.class } ) public void testDeleteWhileWriting() throws IOException { Path file = fileTA(); try( ByteChannel ch = Files.newByteChannel( file, Sets.asSet( WRITE ) ) ) { Files.delete( file ); assertThat( file ).doesNotExist(); ch.write( ByteBuffer.wrap( CONTENT_OTHER ) ); } assertThat( file ).doesNotExist(); }
@Test @Category( { Writable.class, Delete.class, MoveWhile.class } ) public void testMoveWhileWriting() throws IOException { Path file = fileTA(); try( ByteChannel ch = Files.newByteChannel( file, Sets.asSet( WRITE ) ) ) { Files.move( file, absTB() ); assertThat( file ).doesNotExist(); ByteBuffer bb = ByteBuffer.wrap( CONTENT_OTHER ); ch.write( bb ); } assertThat( Files.readAllBytes( absTB() ) ).isEqualTo( CONTENT_OTHER ); }
@Override protected int write(NioSession session, IoBuffer buf, int length) throws IOException { if (buf.remaining() <= length) { return session.getChannel().write(buf.buf()); } int oldLimit = buf.limit(); buf.limit(buf.position() + length); try { return session.getChannel().write(buf.buf()); } finally { buf.limit(oldLimit); } }