微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.os.MemoryFile的实例源码

项目:GitHub    文件GingerbreadPurgeableDecoder.java   
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();
    }
  }
}
项目:FontProvider    文件FontManager.java   
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);
    }
}
项目:ebook    文件WordParseUtils.java   
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;
}
项目:fresco    文件GingerbreadPurgeableDecoder.java   
protected Bitmap decodeFileDescriptorAsPurgeable(
    CloseableReference<PooledByteBuffer> bytesRef,"BitmapFactory returned null");
  } catch (IOException e) {
    throw Throwables.propagate(e);
  } finally {
    if (memoryFile != null) {
      memoryFile.close();
    }
  }
}
项目:silent-contacts-android    文件DbQueryUtils.java   
/**
 * 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,file.length());
        return afd;
    } catch (IOException ex) {
        throw new FileNotFoundException(ex.toString());
    }
}
项目:silent-contacts-android    文件DbQueryUtils.java   
/**
     * 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[] 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,bytes.length);
//            file.deactivate();
            return file;
        } finally {
            cursor.close();
        }
    }
项目:greendao-cipher    文件sqliteContentHelper.java   
/**
    * 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[] selectionArgs) throws FileNotFoundException {
    android.os.ParcelFileDescriptor fd = null;

    try {
        MemoryFile file = simpleQueryForBlobMemoryFile(db,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",file.length());
        return afd;
    } catch (IOException ex) {
        throw new FileNotFoundException(ex.toString());
    }
}
项目:greendao-cipher    文件sqliteContentHelper.java   
/**
 * 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[] 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,bytes.length);

     //   file.deactivate();
        return file;
    } finally {
        cursor.close();
    }
}
项目:GitHub    文件WebpDecodingTest.java   
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,data.length);
    return memoryFile;
  } catch (IOException e) {
    throw Throwables.propagate(e);
  }
}
项目:GitHub    文件WebpDecodingTest.java   
private synchronized Method getFileDescriptorMethod() {
  if (sGetFileDescriptorMethod == null) {
    try {
      sGetFileDescriptorMethod = MemoryFile.class.getDeclaredMethod("getFileDescriptor");
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
  return sGetFileDescriptorMethod;
}
项目:GitHub    文件WebpDecodingTest.java   
private FileDescriptor getMemoryFileDescriptor(MemoryFile memoryFile) {
  try {
    Object rawFD = getFileDescriptorMethod().invoke(memoryFile);
    return (FileDescriptor) rawFD;
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
项目:GitHub    文件WebpDecodingTest.java   
@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);
  memoryFile.close();
  assertBitmap(bitmap,480,320);
}
项目:GitHub    文件WebpDecodingTest.java   
@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),400,301);
}
项目:GitHub    文件WebpDecodingTest.java   
@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),301);
}
项目:GitHub    文件WebpDecodingTest.java   
@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),320,214);
}
项目:GitHub    文件GingerbreadPurgeableDecoder.java   
private synchronized Method getFileDescriptorMethod() {
  if (sGetFileDescriptorMethod == null) {
    try {
      sGetFileDescriptorMethod = MemoryFile.class.getDeclaredMethod("getFileDescriptor");
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
  return sGetFileDescriptorMethod;
}
项目:GitHub    文件GingerbreadPurgeableDecoder.java   
private FileDescriptor getMemoryFileDescriptor(MemoryFile memoryFile) {
  try {
    Object rawFD = getFileDescriptorMethod().invoke(memoryFile);
    return (FileDescriptor) rawFD;
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
项目:FontProvider    文件MemoryFileUtils.java   
public static FileDescriptor getFileDescriptor(MemoryFile mf) {
    if (getFileDescriptorMethod != null) {
        try {
            return  (FileDescriptor) getFileDescriptorMethod.invoke(mf);
        } catch (illegalaccessexception | InvocationTargetException e) {
            e.printstacktrace();
        }
    }
    return null;
}
项目:Cable-Android    文件PartProvider.java   
private ParcelFileDescriptor getParcelStreamForAttachment(MasterSecret masterSecret,AttachmentId attachmentId) throws IOException {
  long       plaintextLength = Util.getStreamLength(DatabaseFactory.getAttachmentDatabase(getContext()).getAttachmentStream(masterSecret,attachmentId));
  MemoryFile memoryFile      = new MemoryFile(attachmentId.toString(),Util.toIntExact(plaintextLength));

  InputStream  in  = DatabaseFactory.getAttachmentDatabase(getContext()).getAttachmentStream(masterSecret,attachmentId);
  OutputStream out = memoryFile.getoutputStream();

  Util.copy(in,out);
  Util.close(out);
  Util.close(in);

  return MemoryFileUtil.getParcelFileDescriptor(memoryFile);
}
项目:fresco    文件WebpDecodingTest.java   
private MemoryFile getMemoryFile(String path) {
  try {
    byte[] data = ByteStreams.toByteArray(getTestimageInputStream(path));
    MemoryFile memoryFile = new MemoryFile(null,data.length);
    return memoryFile;
  } catch (IOException e) {
    throw Throwables.propagate(e);
  }
}
项目:fresco    文件WebpDecodingTest.java   
private synchronized Method getFileDescriptorMethod() {
  if (sGetFileDescriptorMethod == null) {
    try {
      sGetFileDescriptorMethod = MemoryFile.class.getDeclaredMethod("getFileDescriptor");
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
  return sGetFileDescriptorMethod;
}
项目:fresco    文件WebpDecodingTest.java   
private FileDescriptor getMemoryFileDescriptor(MemoryFile memoryFile) {
  try {
    Object rawFD = getFileDescriptorMethod().invoke(memoryFile);
    return (FileDescriptor) rawFD;
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
项目:fresco    文件WebpDecodingTest.java   
@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),320);
}
项目:fresco    文件WebpDecodingTest.java   
@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),301);
}
项目:fresco    文件WebpDecodingTest.java   
@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),301);
}
项目:fresco    文件WebpDecodingTest.java   
@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),214);
}
项目:fresco    文件GingerbreadPurgeableDecoder.java   
private synchronized Method getFileDescriptorMethod() {
  if (sGetFileDescriptorMethod == null) {
    try {
      sGetFileDescriptorMethod = MemoryFile.class.getDeclaredMethod("getFileDescriptor");
    } catch (Exception e) {
      throw Throwables.propagate(e);
    }
  }
  return sGetFileDescriptorMethod;
}
项目:fresco    文件GingerbreadPurgeableDecoder.java   
private FileDescriptor getMemoryFileDescriptor(MemoryFile memoryFile) {
  try {
    Object rawFD = getFileDescriptorMethod().invoke(memoryFile);
    return (FileDescriptor) rawFD;
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
项目:FontProvider    文件FontManager.java   
public static FileDescriptor getFileDescriptor(Context context,String filename) {
    MemoryFile mf = sCache.get(filename);

    if (mf != null) {
        Log.i(TAG,"MemoryFile " + filename + " is in the cache");

        FileDescriptor fd = MemoryFileUtils.getFileDescriptor(mf);
        if (fd != null && fd.valid()) {
            return fd;
        } else {
            Log.i(TAG,"MemoryFile " + filename + " is not valid?");
        }
    }

    long time = System.currentTimeMillis();

    Log.i(TAG,"loading file " + filename);

    // built in font? read from asset
    if (BUILT_IN_FONTS_SIZE.containsKey(filename)) {
        mf = MemoryFileUtils.fromAsset(context.getAssets(),filename,FILE_SIZE.get(filename));
    }

    // downloadable font? read from file
    if (mf == null) {
        File file = ContextUtils.getExternalFile(context,filename);
        if (file.exists()) {
            mf = MemoryFileUtils.fromFile(file);
            if (mf != null) {
                FILE_SIZE.put(filename,mf.length());
            }
        }
    }

    // file not exist?
    if (mf == null) {
        Log.w(TAG,"loading " + filename + " Failed");
        return null;
    }

    Log.i(TAG,"loading finished in " + (System.currentTimeMillis() - time) + "ms");
    sCache.put(filename,mf);

    return MemoryFileUtils.getFileDescriptor(mf);
}
项目:ebook    文件WordParseUtils.java   
public static MemoryFile getMemoryFile()
{
    return  mMemoryFile;
}
项目:LiveMultimedia    文件SharedVideoMemory.java   
/**
 * Allocates a new ashmem region. The region is initially not purgable.
 *
 * @param name      optional name for the file (can be null).
 * @param frameSize how many frame to store
 * @param length    of the memory file in bytes.
 * @throws IOException if the memory file Could not be created.
 */
public SharedVideoMemory(String name,int frameSize,int length) throws IOException {
    mSharedMemFile = new MemoryFile(name,length);
    mFrameSize = frameSize;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。