当前位置: 首页>>代码示例>>Java>>正文


Java MemoryFile类代码示例

本文整理汇总了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();
    }
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:GingerbreadPurgeableDecoder.java

示例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);
    }
}
 
开发者ID:RikkaApps,项目名称:FontProvider,代码行数:27,代码来源:FontManager.java

示例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;
}
 
开发者ID:weizhiping,项目名称:ebook,代码行数:21,代码来源:WordParseUtils.java

示例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());
    }
}
 
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:38,代码来源:DbQueryUtils.java

示例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();
        }
    }
 
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:34,代码来源:DbQueryUtils.java

示例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());
    }
}
 
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:37,代码来源:SQLiteContentHelper.java

示例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();
    }
}
 
开发者ID:itsmechlark,项目名称:greendao-cipher,代码行数:34,代码来源:SQLiteContentHelper.java

示例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);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:WebpDecodingTest.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:WebpDecodingTest.java

示例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);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:WebpDecodingTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:WebpDecodingTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:WebpDecodingTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:WebpDecodingTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:WebpDecodingTest.java

示例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;
}
 
开发者ID:RikkaApps,项目名称:FontProvider,代码行数:11,代码来源:MemoryFileUtils.java


注:本文中的android.os.MemoryFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。