本文整理汇总了Java中android.os.MemoryFile类的典型用法代码示例。如果您正苦于以下问题:Java MemoryFile类的具体用法?Java MemoryFile怎么用?Java MemoryFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MemoryFile类属于android.os包,在下文中一共展示了MemoryFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeFileDescriptorAsPurgeable
import android.os.MemoryFile; //导入依赖的package包/类
protected Bitmap decodeFileDescriptorAsPurgeable(
CloseableReference<PooledByteBuffer> bytesRef,
int inputLength,
byte[] suffix,
BitmapFactory.Options options) {
MemoryFile memoryFile = null;
try {
memoryFile = copyToMemoryFile(bytesRef, inputLength, suffix);
FileDescriptor fd = getMemoryFileDescriptor(memoryFile);
Bitmap bitmap = sWebpBitmapFactory.decodeFileDescriptor(fd, null, options);
return Preconditions.checkNotNull(bitmap, "BitmapFactory returned null");
} catch (IOException e) {
throw Throwables.propagate(e);
} finally {
if (memoryFile != null) {
memoryFile.close();
}
}
}
示例2: init
import android.os.MemoryFile; //导入依赖的package包/类
public static void init(Context context) {
if (sFonts != null) {
return;
}
sCache = new LruCache<String, MemoryFile>(FontProviderSettings.getMaxCache()) {
@Override
protected void entryRemoved(boolean evicted, String key, MemoryFile oldValue, MemoryFile newValue) {
if (evicted) {
oldValue.close();
}
}
@Override
protected int sizeOf(String key, MemoryFile value) {
return value.length();
}
};
sFonts = new ArrayList<>();
for (int res : FONTS_RES) {
FontInfo font = new Gson().fromJson(new InputStreamReader(context.getResources().openRawResource(res)), FontInfo.class);
sFonts.add(font);
}
}
示例3: openMemoryFile
import android.os.MemoryFile; //导入依赖的package包/类
public static MemoryFile openMemoryFile( String filename, int length )
{
try
{
MemoryFile memoryFile = new MemoryFile(filename, length);
if( memoryFile != null )
{
memoryFile.allowPurging(false);
}
return memoryFile;
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例4: getBlobColumnAsAssetFile
import android.os.MemoryFile; //导入依赖的package包/类
/**
* 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());
}
}
示例5: simpleQueryForBlobMemoryFile
import android.os.MemoryFile; //导入依赖的package包/类
/**
* Runs an SQLite query and returns a MemoryFile for the
* blob in column 0 of the first row. If the first column does
* not contain a blob, an unspecified exception is thrown.
*
* @return A memory file, or {@code null} if the query returns no results
* or the value column 0 is NULL.
* @throws IOException If there is an error creating the memory file.
*/
// TODO: make this native and use the SQLite blob API to reduce copying
private static MemoryFile simpleQueryForBlobMemoryFile(SQLiteDatabase db, String sql, String[] selectionArgs)
throws IOException {
Cursor cursor = db.rawQuery(sql, selectionArgs);
if (cursor == null) {
return null;
}
try {
if (!cursor.moveToFirst()) {
return null;
}
byte[] bytes = cursor.getBlob(0);
if (bytes == null) {
return null;
}
MemoryFile file = new MemoryFile(null, bytes.length);
file.writeBytes(bytes, 0, 0, bytes.length);
// file.deactivate();
return file;
} finally {
cursor.close();
}
}
示例6: getBlobColumnAsAssetFile
import android.os.MemoryFile; //导入依赖的package包/类
/**
* 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());
}
}
示例7: simpleQueryForBlobMemoryFile
import android.os.MemoryFile; //导入依赖的package包/类
/**
* Runs an SQLite query and returns a MemoryFile for the
* blob in column 0 of the first row. If the first column does
* not contain a blob, an unspecified exception is thrown.
*
* @return A memory file, or {@code null} if the query returns no results
* or the value column 0 is NULL.
* @throws IOException If there is an error creating the memory file.
*/
// TODO: make this native and use the SQLite blob API to reduce copying
private static MemoryFile simpleQueryForBlobMemoryFile(SQLiteDatabase db, String sql,
String[] selectionArgs) throws IOException {
Cursor cursor = db.rawQuery(sql, selectionArgs);
if (cursor == null) {
return null;
}
try {
if (!cursor.moveToFirst()) {
return null;
}
byte[] bytes = cursor.getBlob(0);
if (bytes == null) {
return null;
}
MemoryFile file = new MemoryFile(null, bytes.length);
file.writeBytes(bytes, 0, 0, bytes.length);
// file.deactivate();
return file;
} finally {
cursor.close();
}
}
示例8: getMemoryFile
import android.os.MemoryFile; //导入依赖的package包/类
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);
}
}
示例9: getFileDescriptorMethod
import android.os.MemoryFile; //导入依赖的package包/类
private synchronized Method getFileDescriptorMethod() {
if (sGetFileDescriptorMethod == null) {
try {
sGetFileDescriptorMethod = MemoryFile.class.getDeclaredMethod("getFileDescriptor");
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
return sGetFileDescriptorMethod;
}
示例10: getMemoryFileDescriptor
import android.os.MemoryFile; //导入依赖的package包/类
private FileDescriptor getMemoryFileDescriptor(MemoryFile memoryFile) {
try {
Object rawFD = getFileDescriptorMethod().invoke(memoryFile);
return (FileDescriptor) rawFD;
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
示例11: test_webp_extended_decoding_filedescriptor_bitmap
import android.os.MemoryFile; //导入依赖的package包/类
@Test
public void test_webp_extended_decoding_filedescriptor_bitmap() throws Throwable {
final MemoryFile memoryFile = getMemoryFile("webp_e.webp");
final Bitmap bitmap = mWebpBitmapFactory.decodeFileDescriptor(
getMemoryFileDescriptor(memoryFile),
null,
null);
memoryFile.close();
assertBitmap(bitmap, 480, 320);
}
示例12: test_webp_extended_with_alpha_decoding_filedescriptor_bitmap
import android.os.MemoryFile; //导入依赖的package包/类
@Test
public void test_webp_extended_with_alpha_decoding_filedescriptor_bitmap() throws Throwable {
final MemoryFile memoryFile = getMemoryFile("webp_ea.webp");
final Bitmap bitmap = mWebpBitmapFactory.decodeFileDescriptor(
getMemoryFileDescriptor(memoryFile),
null,
null);
memoryFile.close();
assertBitmap(bitmap, 400 ,301);
}
示例13: test_webp_lossless_decoding_filedescriptor_bitmap
import android.os.MemoryFile; //导入依赖的package包/类
@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);
}
示例14: test_webp_plain_decoding_filedescriptor_bitmap
import android.os.MemoryFile; //导入依赖的package包/类
@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);
}
示例15: getFileDescriptor
import android.os.MemoryFile; //导入依赖的package包/类
public static FileDescriptor getFileDescriptor(MemoryFile mf) {
if (getFileDescriptorMethod != null) {
try {
return (FileDescriptor) getFileDescriptorMethod.invoke(mf);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
return null;
}