use of android.os.MemoryFile in project Signal-Android by signalapp.
the class PartProvider method getParcelStreamForAttachment.
private ParcelFileDescriptor getParcelStreamForAttachment(AttachmentId attachmentId) throws IOException {
long plaintextLength = Util.getStreamLength(DatabaseFactory.getAttachmentDatabase(getContext()).getAttachmentStream(attachmentId, 0));
MemoryFile memoryFile = new MemoryFile(attachmentId.toString(), Util.toIntExact(plaintextLength));
InputStream in = DatabaseFactory.getAttachmentDatabase(getContext()).getAttachmentStream(attachmentId, 0);
OutputStream out = memoryFile.getOutputStream();
Util.copy(in, out);
Util.close(out);
Util.close(in);
return MemoryFileUtil.getParcelFileDescriptor(memoryFile);
}
use of android.os.MemoryFile in project android-database-sqlcipher by sqlcipher.
the class SQLiteContentHelper method getBlobColumnAsAssetFile.
/**
* Runs an SQLite query and returns an AssetFileDescriptor for the
* blob in column 0 of the first row. If the first column does
* not contain a blob, an unspecified exception is thrown.
*
* @param db Handle to a readable database.
* @param sql SQL query, possibly with query arguments.
* @param selectionArgs Query argument values, or {@code null} for no argument.
* @return If no exception is thrown, a non-null AssetFileDescriptor is returned.
* @throws FileNotFoundException If the query returns no results or the
* value of column 0 is NULL, or if there is an error creating the
* asset file descriptor.
*/
public static AssetFileDescriptor getBlobColumnAsAssetFile(SQLiteDatabase db, String sql, String[] selectionArgs) throws FileNotFoundException {
android.os.ParcelFileDescriptor fd = null;
try {
MemoryFile file = simpleQueryForBlobMemoryFile(db, sql, selectionArgs);
if (file == null) {
throw new FileNotFoundException("No results.");
}
Class c = file.getClass();
try {
java.lang.reflect.Method m = c.getDeclaredMethod("getParcelFileDescriptor");
m.setAccessible(true);
fd = (android.os.ParcelFileDescriptor) m.invoke(file);
} catch (Exception e) {
android.util.Log.i("SQLiteContentHelper", "SQLiteCursor.java: " + e);
}
AssetFileDescriptor afd = new AssetFileDescriptor(fd, 0, file.length());
return afd;
} catch (IOException ex) {
throw new FileNotFoundException(ex.toString());
}
}
use of android.os.MemoryFile in project fresco by facebook.
the class WebpDecodingTest method getMemoryFile.
private MemoryFile getMemoryFile(String path) {
try {
byte[] data = ByteStreams.toByteArray(getTestImageInputStream(path));
MemoryFile memoryFile = new MemoryFile(null, data.length);
memoryFile.allowPurging(false);
memoryFile.writeBytes(data, 0, 0, data.length);
return memoryFile;
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
use of android.os.MemoryFile in project fresco by facebook.
the class WebpDecodingTest method test_webp_lossless_decoding_filedescriptor_bitmap.
@Test
public void test_webp_lossless_decoding_filedescriptor_bitmap() throws Throwable {
final MemoryFile memoryFile = getMemoryFile("webp_ll.webp");
final Bitmap bitmap = mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
assertBitmap(bitmap, 400, 301);
}
use of android.os.MemoryFile in project fresco by facebook.
the class WebpDecodingTest method test_webp_plain_decoding_filedescriptor_bitmap.
@Test
public void test_webp_plain_decoding_filedescriptor_bitmap() throws Throwable {
final MemoryFile memoryFile = getMemoryFile("webp_plain.webp");
final Bitmap bitmap = mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
assertBitmap(bitmap, 320, 214);
}
Aggregations