MCPcopy Index your code
hub / github.com/cSploit/android / fetch

Method fetch

cSploit/src/org/csploit/android/net/RemoteReader.java:266–324  ·  view source on GitHub ↗
(final String url)

Source from the content-addressed store, hash-verified

264 }
265
266 public static byte[] fetch(final String url) throws IOException {
267 class BlockingReceiver implements Receiver {
268
269 private boolean done = false;
270 private byte[] content = null;
271 private String errorMessage = null;
272
273 @Override
274 public void onContentFetched(byte[] content) {
275 this.content = content;
276 this.done = true;
277 synchronized (this) {
278 this.notify();
279 }
280 }
281
282 @Override
283 public void onError(byte[] description) {
284 this.errorMessage = new String(description);
285 this.done = true;
286 synchronized (this) {
287 this.notify();
288 }
289 }
290
291 public byte[] getContent() {
292 return content;
293 }
294
295 public boolean isDone() {
296 return done;
297 }
298
299 public String getErrorMessage() {
300 return errorMessage;
301 }
302 }
303
304 RemoteReader reader = fromUrl(url);
305 BlockingReceiver r = new BlockingReceiver();
306 Task t = new Task(url, r);
307 reader.addFirst(t);
308
309 try {
310 synchronized (r) {
311 while(!r.isDone())
312 r.wait();
313 }
314 } catch (InterruptedException e) {
315 throw new IOException("Interrupted while fetching content");
316 }
317
318 byte[] res = r.getContent();
319
320 if(res == null)
321 throw new IOException(r.getErrorMessage());
322
323 return res;

Callers 2

fetchReleasesMethod · 0.95
fetchBranchesMethod · 0.95

Calls 6

fromUrlMethod · 0.95
addFirstMethod · 0.95
isDoneMethod · 0.95
getContentMethod · 0.95
getErrorMessageMethod · 0.95
waitMethod · 0.80

Tested by

no test coverage detected