MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / readFile

Method readFile

src/plugins/sdcard/src/android/SDcard.java:455–486  ·  view source on GitHub ↗
(String filename, CallbackContext callback)

Source from the content-addressed store, hash-verified

453 }
454
455 private void readFile(String filename, CallbackContext callback) {
456 cordova
457 .getThreadPool()
458 .execute(
459 new Runnable() {
460 public void run() {
461 try {
462 Uri uri = Uri.parse(filename);
463 InputStream is = context
464 .getContentResolver()
465 .openInputStream(uri);
466
467 if (is == null) {
468 callback.error("File not found");
469 return;
470 }
471 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
472 final int bufferSize = 1024;
473 byte[] buffer = new byte[bufferSize];
474 int bytesRead = 0;
475 while ((bytesRead = is.read(buffer, 0, bufferSize)) != -1) {
476 outputStream.write(buffer, 0, bytesRead);
477 }
478 is.close();
479 callback.success(outputStream.toByteArray());
480 } catch (Exception e) {
481 callback.error(e.toString());
482 }
483 }
484 }
485 );
486 }
487
488 private void readAsText(final String filename, final String encoding, final CallbackContext callback) {
489 cordova

Callers 15

executeMethod · 0.95
reopenWithNewEncodingFunction · 0.45
PluginIncludeFunction · 0.45
handlerFunction · 0.45
plugin.view.jsFile · 0.45
fileToObjectUrlFunction · 0.45
getInstalledPluginsFunction · 0.45
getOwnedFunction · 0.45
loadLatestReleaseFunction · 0.45
loadBetaReleaseFunction · 0.45
loadFullChangelogFunction · 0.45
loadVersionChangelogFunction · 0.45

Calls 1

executeMethod · 0.45

Tested by

no test coverage detected