interface that can be
shared by multiple threads, usually the I/O dispatch of an I/O reactor and
a worker thread.
| Method from org.apache.http.nio.util.SharedInputBuffer Detail: |
public void close() {
if (this.shutdown) {
return;
}
this.endOfStream = true;
synchronized (this.mutex) {
this.mutex.notifyAll();
}
}
|
public int consumeContent(ContentDecoder decoder) throws IOException {
if (this.shutdown) {
return -1;
}
synchronized (this.mutex) {
setInputMode();
int totalRead = 0;
int bytesRead;
while ((bytesRead = decoder.read(this.buffer)) > 0) {
totalRead += bytesRead;
}
if (bytesRead == -1 || decoder.isCompleted()) {
this.endOfStream = true;
}
if (!this.buffer.hasRemaining()) {
this.ioctrl.suspendInput();
}
this.mutex.notifyAll();
if (totalRead > 0) {
return totalRead;
} else {
if (this.endOfStream) {
return -1;
} else {
return 0;
}
}
}
}
|
protected boolean isEndOfStream() {
return this.shutdown || (!hasData() && this.endOfStream);
}
|
protected boolean isShutdown() {
return this.shutdown;
}
|
public int read() throws IOException {
if (this.shutdown) {
return -1;
}
synchronized (this.mutex) {
if (!hasData()) {
waitForData();
}
if (isEndOfStream()) {
return -1;
}
return this.buffer.get() & 0xff;
}
}
|
public int read(byte[] b) throws IOException {
if (this.shutdown) {
return -1;
}
if (b == null) {
return 0;
}
return read(b, 0, b.length);
}
|
public int read(byte[] b,
int off,
int len) throws IOException {
if (this.shutdown) {
return -1;
}
if (b == null) {
return 0;
}
synchronized (this.mutex) {
if (!hasData()) {
waitForData();
}
if (isEndOfStream()) {
return -1;
}
setOutputMode();
int chunk = len;
if (chunk > this.buffer.remaining()) {
chunk = this.buffer.remaining();
}
this.buffer.get(b, off, chunk);
return chunk;
}
}
|
public void reset() {
if (this.shutdown) {
return;
}
synchronized (this.mutex) {
clear();
this.endOfStream = false;
}
}
|
public void shutdown() {
if (this.shutdown) {
return;
}
this.shutdown = true;
synchronized (this.mutex) {
this.mutex.notifyAll();
}
}
|
protected void waitForData() throws IOException {
synchronized (this.mutex) {
try {
while (!hasData() && !this.endOfStream) {
if (this.shutdown) {
throw new InterruptedIOException("Input operation aborted");
}
this.ioctrl.requestInput();
this.mutex.wait();
}
} catch (InterruptedException ex) {
throw new IOException("Interrupted while waiting for more data");
}
}
}
|