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;
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations