MCPcopy
hub / github.com/koush/AndroidAsync / emitAllData

Method emitAllData

AndroidAsync/src/com/koushikdutta/async/Util.java:19–54  ·  view source on GitHub ↗
(DataEmitter emitter, ByteBufferList list)

Source from the content-addressed store, hash-verified

17public class Util {
18 public static boolean SUPRESS_DEBUG_EXCEPTIONS = false;
19 public static void emitAllData(DataEmitter emitter, ByteBufferList list) {
20 int remaining;
21 DataCallback handler = null;
22 while (!emitter.isPaused() && (handler = emitter.getDataCallback()) != null && (remaining = list.remaining()) > 0) {
23 handler.onDataAvailable(emitter, list);
24 if (remaining == list.remaining() && handler == emitter.getDataCallback() && !emitter.isPaused()) {
25 // this is generally indicative of failure...
26
27 // 1) The data callback has not changed
28 // 2) no data was consumed
29 // 3) the data emitter was not paused
30
31 // call byteBufferList.recycle() or read all the data to prevent this assertion.
32 // this is nice to have, as it identifies protocol or parsing errors.
33
34// System.out.println("Data: " + list.peekString());
35 System.out.println("handler: " + handler);
36 list.recycle();
37 if (SUPRESS_DEBUG_EXCEPTIONS)
38 return;
39 throw new RuntimeException("mDataHandler failed to consume data, yet remains the mDataHandler.");
40 }
41 }
42 if (list.remaining() != 0 && !emitter.isPaused()) {
43 // not all the data was consumed...
44 // call byteBufferList.recycle() or read all the data to prevent this assertion.
45 // this is nice to have, as it identifies protocol or parsing errors.
46// System.out.println("Data: " + list.peekString());
47 System.out.println("handler: " + handler);
48 System.out.println("emitter: " + emitter);
49 list.recycle();
50 if (SUPRESS_DEBUG_EXCEPTIONS)
51 return;
52// throw new AssertionError("Not all data was consumed by Util.emitAllData");
53 }
54 }
55
56 public static void pump(final InputStream is, final DataSink ds, final CompletedCallback callback) {
57 pump(is, Integer.MAX_VALUE, ds, callback);

Callers 12

testPushParserUntilMethod · 0.95
testTapCallbackMethod · 0.95
onReadableMethod · 0.95
spitPendingMethod · 0.95
onDataAvailableMethod · 0.95
runMethod · 0.95
onDataAvailableMethod · 0.95
addAndEmitMethod · 0.95
onDataAvailableMethod · 0.95
onDataAvailableMethod · 0.95
runMethod · 0.95

Calls 5

onDataAvailableMethod · 0.95
recycleMethod · 0.80
isPausedMethod · 0.65
getDataCallbackMethod · 0.65
remainingMethod · 0.45

Tested by 3

testPushParserUntilMethod · 0.76
testTapCallbackMethod · 0.76