Search in sources :

Example 11 with AutoCloseInputStream

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

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 12 with AutoCloseInputStream

use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project k-9 by k9mail.

the class ParcelFileDescriptorUtil method pipeTo.

public static TransferThread pipeTo(OutputStream outputStream, ParcelFileDescriptor output) throws IOException {
    AutoCloseInputStream InputStream = new AutoCloseInputStream(output);
    TransferThread t = new TransferThread(InputStream, outputStream);
    t.start();
    return t;
}
Also used : AutoCloseInputStream(android.os.ParcelFileDescriptor.AutoCloseInputStream)

Example 13 with AutoCloseInputStream

use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project k-9 by k9mail.

the class ParcelFileDescriptorUtil method asyncPipeToDataSink.

public static <T> DataSinkTransferThread<T> asyncPipeToDataSink(OpenPgpDataSink<T> dataSink, ParcelFileDescriptor output) throws IOException {
    InputStream inputStream = new BufferedInputStream(new AutoCloseInputStream(output));
    DataSinkTransferThread<T> dataSinkTransferThread = new DataSinkTransferThread<T>(dataSink, inputStream);
    dataSinkTransferThread.start();
    return dataSinkTransferThread;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) AutoCloseInputStream(android.os.ParcelFileDescriptor.AutoCloseInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) AutoCloseInputStream(android.os.ParcelFileDescriptor.AutoCloseInputStream)

Example 14 with AutoCloseInputStream

use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project platform_frameworks_base by android.

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 15 with AutoCloseInputStream

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

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