Search in sources :

Example 6 with AutoCloseInputStream

use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project android_frameworks_base by ResurrectionRemix.

the class DownloadManagerBaseTest method verifyFileContents.

/**
     * Helper to verify the contents of a downloaded file versus a byte[].
     *
     * @param actual The file of whose contents to verify
     * @param expected The data we expect to find in the aforementioned file
     * @throws IOException if there was a problem reading from the file
     */
protected void verifyFileContents(ParcelFileDescriptor actual, byte[] expected) throws IOException {
    AutoCloseInputStream input = new ParcelFileDescriptor.AutoCloseInputStream(actual);
    long fileSize = actual.getStatSize();
    assertTrue(fileSize <= Integer.MAX_VALUE);
    assertEquals(expected.length, fileSize);
    byte[] actualData = new byte[expected.length];
    assertEquals(input.read(actualData), fileSize);
    compareByteArrays(actualData, expected);
}
Also used : AutoCloseInputStream(android.os.ParcelFileDescriptor.AutoCloseInputStream)

Example 7 with AutoCloseInputStream

use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project android_frameworks_base by DirtyUnicorns.

the class DocumentsProviderHelper method readDocument.

public byte[] readDocument(Uri documentUri) throws RemoteException, IOException {
    ParcelFileDescriptor file = mClient.openFile(documentUri, "r", null);
    byte[] buf = null;
    try (AutoCloseInputStream in = new AutoCloseInputStream(file)) {
        buf = Streams.readFully(in);
    }
    return buf;
}
Also used : ParcelFileDescriptor(android.os.ParcelFileDescriptor) AutoCloseInputStream(android.os.ParcelFileDescriptor.AutoCloseInputStream)

Example 8 with AutoCloseInputStream

use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project android_frameworks_base by AOSPA.

the class DownloadManagerBaseTest method verifyFileContents.

/**
     * Helper to verify the contents of a downloaded file versus a byte[].
     *
     * @param actual The file of whose contents to verify
     * @param expected The data we expect to find in the aforementioned file
     * @throws IOException if there was a problem reading from the file
     */
protected void verifyFileContents(ParcelFileDescriptor actual, byte[] expected) throws IOException {
    AutoCloseInputStream input = new ParcelFileDescriptor.AutoCloseInputStream(actual);
    long fileSize = actual.getStatSize();
    assertTrue(fileSize <= Integer.MAX_VALUE);
    assertEquals(expected.length, fileSize);
    byte[] actualData = new byte[expected.length];
    assertEquals(input.read(actualData), fileSize);
    compareByteArrays(actualData, expected);
}
Also used : AutoCloseInputStream(android.os.ParcelFileDescriptor.AutoCloseInputStream)

Example 9 with AutoCloseInputStream

use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project android_frameworks_base by AOSPA.

the class DownloadManagerBaseTest method verifyFileContents.

/**
     * Verifies the contents of a downloaded file versus the contents of a File.
     *
     * @param pfd The file whose data we want to verify
     * @param file The file containing the data we expect to see in the aforementioned file
     * @throws IOException If there was a problem reading either of the two files
     */
protected void verifyFileContents(ParcelFileDescriptor pfd, File file) throws IOException {
    byte[] actual = new byte[FILE_BLOCK_READ_SIZE];
    byte[] expected = new byte[FILE_BLOCK_READ_SIZE];
    AutoCloseInputStream input = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
    assertEquals(file.length(), pfd.getStatSize());
    DataInputStream inFile = new DataInputStream(new FileInputStream(file));
    int actualRead = 0;
    int expectedRead = 0;
    while (((actualRead = input.read(actual)) != -1) && ((expectedRead = inFile.read(expected)) != -1)) {
        assertEquals(actualRead, expectedRead);
        compareByteArrays(actual, expected);
    }
}
Also used : DataInputStream(java.io.DataInputStream) AutoCloseInputStream(android.os.ParcelFileDescriptor.AutoCloseInputStream) FileInputStream(java.io.FileInputStream)

Example 10 with AutoCloseInputStream

use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project android_frameworks_base by crdroidandroid.

the class DownloadManagerBaseTest method verifyFileContents.

/**
     * Verifies the contents of a downloaded file versus the contents of a File.
     *
     * @param pfd The file whose data we want to verify
     * @param file The file containing the data we expect to see in the aforementioned file
     * @throws IOException If there was a problem reading either of the two files
     */
protected void verifyFileContents(ParcelFileDescriptor pfd, File file) throws IOException {
    byte[] actual = new byte[FILE_BLOCK_READ_SIZE];
    byte[] expected = new byte[FILE_BLOCK_READ_SIZE];
    AutoCloseInputStream input = new ParcelFileDescriptor.AutoCloseInputStream(pfd);
    assertEquals(file.length(), pfd.getStatSize());
    DataInputStream inFile = new DataInputStream(new FileInputStream(file));
    int actualRead = 0;
    int expectedRead = 0;
    while (((actualRead = input.read(actual)) != -1) && ((expectedRead = inFile.read(expected)) != -1)) {
        assertEquals(actualRead, expectedRead);
        compareByteArrays(actual, expected);
    }
}
Also used : DataInputStream(java.io.DataInputStream) AutoCloseInputStream(android.os.ParcelFileDescriptor.AutoCloseInputStream) FileInputStream(java.io.FileInputStream)

Aggregations

AutoCloseInputStream (android.os.ParcelFileDescriptor.AutoCloseInputStream)19 DataInputStream (java.io.DataInputStream)6 FileInputStream (java.io.FileInputStream)6 ParcelFileDescriptor (android.os.ParcelFileDescriptor)5 BufferedInputStream (java.io.BufferedInputStream)1 InputStream (java.io.InputStream)1