in stetho/src/main/java/com/facebook/stetho/inspector/network/DownloadingAsyncPrettyPrinterFactory.java [33:88]
public AsyncPrettyPrinter getInstance(final String headerName, final String headerValue) {
final MatchResult result = matchAndParseHeader(headerName, headerValue);
if (result == null) {
return null;
}
String uri = result.getSchemaUri();
URL schemaURL = parseURL(uri);
if (schemaURL == null) {
return getErrorAsyncPrettyPrinter(headerName, headerValue);
} else {
ExecutorService executorService = AsyncPrettyPrinterExecutorHolder.getExecutorService();
if (executorService == null) {
//last peer is unregistered...
return null;
}
final Future<String> response = executorService.submit(new Request(schemaURL));
return new AsyncPrettyPrinter() {
public void printTo(PrintWriter output, InputStream payload)
throws IOException {
try {
String schema;
try {
schema = response.get();
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (IOException.class.isInstance(cause)) {
doErrorPrint(
output,
payload,
"Cannot successfully download schema: "
+ e.getMessage());
return;
} else {
throw e;
}
}
doPrint(output, payload, schema);
} catch (InterruptedException e) {
doErrorPrint(
output,
payload,
"Encountered spurious interrupt while downloading schema for pretty printing: "
+ e.getMessage());
} catch (ExecutionException e) {
Throwable cause = e.getCause();
throw ExceptionUtil.propagate(cause);
}
}
public PrettyPrinterDisplayType getPrettifiedType() {
return result.getDisplayType();
}
};
}
}