@Override public int read(final byte[] b, final int off, final int len) throws IOException { if(Thread.currentThread() == channel.getIoThread()) { throw UndertowMessages.MESSAGES.blockingIoFromIOThread(); } if (anyAreSet(state, FLAG_CLOSED)) { throw UndertowMessages.MESSAGES.streamIsClosed(); } readIntoBuffer(); if (anyAreSet(state, FLAG_FINISHED)) { return -1; } if (len == 0) { return 0; } ByteBuffer buffer = pooled.getBuffer(); int copied = Buffers.copy(ByteBuffer.wrap(b, off, len), buffer); if (!buffer.hasRemaining()) { pooled.close(); pooled = null; } return copied; }
@Override public void close() throws IOException { if (anyAreSet(state, FLAG_CLOSED)) { return; } state |= FLAG_CLOSED; try { while (allAreClear(state, FLAG_FINISHED)) { readIntoBuffer(); if (pooled != null) { pooled.close(); pooled = null; } } } finally { if (pooled != null) { pooled.close(); pooled = null; } channel.shutdownReads(); state |= FLAG_FINISHED; } } }
@Override public int read(final byte[] b, final int off, final int len) throws IOException { if(Thread.currentThread() == channel.getIoThread()) { throw UndertowMessages.MESSAGES.blockingIoFromIOThread(); } if (anyAreSet(state, FLAG_CLOSED)) { throw UndertowMessages.MESSAGES.streamIsClosed(); } readIntoBuffer(); if (anyAreSet(state, FLAG_FINISHED)) { return -1; } if (len == 0) { return 0; } ByteBuffer buffer = pooled.getBuffer(); int copied = Buffers.copy(ByteBuffer.wrap(b, off, len), buffer); if (!buffer.hasRemaining()) { pooled.close(); pooled = null; } return copied; }
@Override public int read(final byte[] b, final int off, final int len) throws IOException { if(Thread.currentThread() == channel.getIoThread()) { throw UndertowMessages.MESSAGES.blockingIoFromIOThread(); } if (anyAreSet(state, FLAG_CLOSED)) { throw UndertowMessages.MESSAGES.streamIsClosed(); } readIntoBuffer(); if (anyAreSet(state, FLAG_FINISHED)) { return -1; } if (len == 0) { return 0; } ByteBuffer buffer = pooled.getBuffer(); int copied = Buffers.copy(ByteBuffer.wrap(b, off, len), buffer); if (!buffer.hasRemaining()) { pooled.close(); pooled = null; } return copied; }
@Override public void close() throws IOException { if (anyAreSet(state, FLAG_CLOSED)) { return; } state |= FLAG_CLOSED; try { while (allAreClear(state, FLAG_FINISHED)) { readIntoBuffer(); if (pooled != null) { pooled.close(); pooled = null; } } } finally { if (pooled != null) { pooled.close(); pooled = null; } channel.shutdownReads(); state |= FLAG_FINISHED; } } }
@Override public void close() throws IOException { if (anyAreSet(state, FLAG_CLOSED)) { return; } state |= FLAG_CLOSED; try { while (allAreClear(state, FLAG_FINISHED)) { readIntoBuffer(); if (pooled != null) { pooled.close(); pooled = null; } } } finally { if (pooled != null) { pooled.close(); pooled = null; } channel.shutdownReads(); state |= FLAG_FINISHED; } } }