List of usage examples for org.apache.http.nio IOControl shutdown
void shutdown() throws IOException;
From source file:rx.apache.http.consumers.ResponseConsumerBasic.java
@Override public void _onContentReceived(ContentDecoder decoder, IOControl ioctrl) throws IOException { if (parentSubscription.isUnsubscribed()) { ioctrl.shutdown(); }//from w ww. j a v a 2s.co m onContentReceived(decoder, ioctrl); }
From source file:rx.apache.http.consumers.ResponseConsumerEventStream.java
@Override protected void onByteReceived(ByteBuffer buf, IOControl ioctrl) throws IOException { if (parentSubscription.isUnsubscribed()) { ioctrl.shutdown(); }//from w ww .ja v a 2 s . c o m while (buf.position() < buf.limit()) { byte b = buf.get(); if (b == 10 || b == 13) { if (dataBuffer.hasContent()) { contentSubject.onNext(dataBuffer.getBytes()); } dataBuffer.reset(); } else { dataBuffer.addByte(b); } } }
From source file:rx.apache.http.consumers.ResponseConsumerChunked.java
@Override protected final void onContentReceived(final ContentDecoder decoder, final IOControl ioctrl) throws IOException { if (parentSubscription.isUnsubscribed()) { ioctrl.shutdown(); }/*from w ww.ja v a 2s .com*/ byte[] data; data = new byte[BUFFER_SIZE]; final int bytesRead; bytesRead = decoder.read(ByteBuffer.wrap(data)); if (bytesRead > 0) { if (bytesRead == data.length) { contentSubject.onNext(data); } else { byte[] subset; subset = new byte[bytesRead]; System.arraycopy(data, 0, subset, 0, bytesRead); contentSubject.onNext(subset); } } if (decoder.isCompleted()) { contentSubject.onCompleted(); } }
From source file:org.apache.cxf.transport.http.asyncclient.SharedInputBuffer.java
public int consumeContent(final ContentDecoder decoder, final IOControl ioc) throws IOException { if (this.shutdown) { //something bad happened, we need to shutdown the connection //as we're not going to read the data at all and we //don't want to keep getting read notices and such ioc.shutdown(); return -1; }/*w w w .ja v a2s . c om*/ this.lock.lock(); try { this.ioctrl = ioc; setInputMode(); int totalRead = 0; int bytesRead; if (waitingBuffer != null && this.buffer.position() == 0) { while ((bytesRead = decoder.read(this.waitingBuffer)) > 0) { totalRead += bytesRead; } } //read more while ((bytesRead = decoder.read(this.buffer)) > 0) { totalRead += bytesRead; } if (bytesRead == -1 || decoder.isCompleted()) { this.endOfStream = true; } if (!this.buffer.hasRemaining() && this.ioctrl != null) { this.ioctrl.suspendInput(); } this.condition.signalAll(); if (totalRead > 0) { return totalRead; } else { if (this.endOfStream) { return -1; } else { return 0; } } } finally { this.lock.unlock(); } }