use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project android_frameworks_base by DirtyUnicorns.
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);
}
}
use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project android_frameworks_base by crdroidandroid.
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);
}
use of android.os.ParcelFileDescriptor.AutoCloseInputStream in project android_frameworks_base by crdroidandroid.
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;
}
Aggregations