(String filename, CallbackContext callback)
| 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 |
no test coverage detected