@Override public int available() throws IOException { if (bufferedByte != null) { return 1; } isDataAvailable(); // attempt to read from socket return (bufferedByte == null) ? 0 : 1; }
public void setTimeout(final int millis) { socketIn.setTimeout(millis); }
@Override public void consume() throws IOException { socketIn.consume(); } }
public StandardCommsSession(final String hostname, final int port, final int timeoutMillis) throws IOException { socketChannel = SocketChannel.open(); socketChannel.socket().connect(new InetSocketAddress(hostname, port), timeoutMillis); socketChannel.configureBlocking(false); in = new SocketChannelInputStream(socketChannel); bufferedIn = new InterruptableInputStream(new BufferedInputStream(in)); out = new SocketChannelOutputStream(socketChannel); bufferedOut = new InterruptableOutputStream(new BufferedOutputStream(out)); this.hostname = hostname; this.port = port; }
@Override public int read(final byte[] b) throws IOException { return read(b, 0, b.length); }
public SocketChannelInput(final SocketChannel socketChannel) throws IOException { this.socketIn = new SocketChannelInputStream(socketChannel); countingIn = new ByteCountingInputStream(socketIn); bufferedIn = new BufferedInputStream(countingIn); interruptableIn = new InterruptableInputStream(bufferedIn); }
@Override public int read(final byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public boolean isClosed() { boolean closed = !socketChannel.isConnected(); if (!closed) { try { this.in.isDataAvailable(); } catch (IOException e) { try { close(); } catch (IOException e1) { } closed = true; } } return closed; }
@Override public void setTimeout(final long value, final TimeUnit timeUnit) { in.setTimeout((int) TimeUnit.MILLISECONDS.convert(value, timeUnit)); out.setTimeout((int) TimeUnit.MILLISECONDS.convert(value, timeUnit)); timeoutMillis = TimeUnit.MILLISECONDS.convert(value, timeUnit); }
public StandardCommsSession(final String hostname, final int port, final int timeoutMillis) throws IOException { socketChannel = SocketChannel.open(); socketChannel.socket().connect(new InetSocketAddress(hostname, port), timeoutMillis); socketChannel.configureBlocking(false); in = new SocketChannelInputStream(socketChannel); bufferedIn = new InterruptableInputStream(new BufferedInputStream(in)); out = new SocketChannelOutputStream(socketChannel); bufferedOut = new InterruptableOutputStream(new BufferedOutputStream(out)); this.hostname = hostname; this.port = port; }
@Override public int available() throws IOException { if (bufferedByte != null) { return 1; } isDataAvailable(); // attempt to read from socket return (bufferedByte == null) ? 0 : 1; }
@Override public void setTimeout(final long value, final TimeUnit timeUnit) { in.setTimeout((int) TimeUnit.MILLISECONDS.convert(value, timeUnit)); out.setTimeout((int) TimeUnit.MILLISECONDS.convert(value, timeUnit)); timeoutMillis = TimeUnit.MILLISECONDS.convert(value, timeUnit); }
@Override public boolean isClosed() { boolean closed = !socketChannel.isConnected(); if (!closed) { try { this.in.isDataAvailable(); } catch (IOException e) { try { close(); } catch (IOException e1) { } closed = true; } } return closed; }