@Override public int available() throws IOException { lock.lock(); try { return buffer.getUsed(); } finally { lock.unlock(); } }
@Override public int available() throws IOException { lock.lock(); try { return buffer.getUsed(); } finally { lock.unlock(); } }
@Override public int read(byte[] bytes, int offset, int length) throws IOException { lock.lock(); try { // are there any bytes available? while (buffer.getUsed() <= 0) { // was the output closed? if (outputClosed.get()) { // return EOF return -1; } //log.debug("waiting for write so up to {} bytes can be read", length); writeSignal.await(); } int getLength = Math.min(buffer.getUsed(), length); //log.debug("trying to get {} bytes ({} available)", getLength, buffer.getUsed()); buffer.get(bytes, offset, getLength); //log.debug("get {} bytes into buffer ({} available)", getLength, buffer.getUsed()); // signal data read readSignal.signal(); return getLength; } catch (InterruptedException e) { throw new IOException("Interrupted while waiting for signal", e); } finally { lock.unlock(); } }
@Override public int read(byte[] bytes, int offset, int length) throws IOException { lock.lock(); try { // are there any bytes available? while (buffer.getUsed() <= 0) { // was the output closed? if (outputClosed.get()) { // return EOF return -1; } //log.debug("waiting for write so up to {} bytes can be read", length); writeSignal.await(); } int getLength = Math.min(buffer.getUsed(), length); //log.debug("trying to get {} bytes ({} available)", getLength, buffer.getUsed()); buffer.get(bytes, offset, getLength); //log.debug("get {} bytes into buffer ({} available)", getLength, buffer.getUsed()); // signal data read readSignal.signal(); return getLength; } catch (InterruptedException e) { throw new IOException("Interrupted while waiting for signal", e); } finally { lock.unlock(); } }