List of usage examples for android.content.res AssetManager open
public @NonNull InputStream open(@NonNull String fileName) throws IOException
From source file:Main.java
private static Bitmap getBitmapFromAsset(Context context, String filePath) { AssetManager assetManager = context.getAssets(); InputStream istream;// w w w . j av a 2 s . c om Bitmap bitmap = null; try { istream = assetManager.open(filePath); bitmap = BitmapFactory.decodeStream(istream); } catch (IOException e) { // handle exception } return bitmap; }
From source file:Main.java
public static Document getW3cDomDocumentFromAsset(AssetManager assetManager, String fileName) throws IOException, ParserConfigurationException, SAXException { InputStream inputStream = assetManager.open(fileName); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(inputStream); }
From source file:Main.java
/** Read a properties file from /assets. Returns null if it does not exist. */ public static Properties getProperties(String name, Context context) { Resources resources = context.getResources(); AssetManager assetManager = resources.getAssets(); // Read from the /assets directory try {/* w ww. j av a 2 s .c o m*/ InputStream inputStream = assetManager.open(name); Properties properties = new Properties(); properties.load(inputStream); return properties; } catch (IOException e) { Log.i("ChatSecure", "no chatsecure.properties available"); return null; } }
From source file:Main.java
public static Bitmap getBitmapFromAsset(FragmentActivity fragmentActivity, String strName) { try {//from ww w . j a va 2 s . co m AssetManager assetManager = fragmentActivity.getAssets(); InputStream inStream = null; try { inStream = assetManager.open(strName); } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = BitmapFactory.decodeStream(inStream); return bitmap; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String readSkeleton(AssetManager am, String filename) throws FileNotFoundException, IOException { BufferedReader skeletonFile = new BufferedReader(new InputStreamReader(am.open(filename))); StringBuilder builder = new StringBuilder(); String line;//from ww w . j av a 2s. com while ((line = skeletonFile.readLine()) != null) { builder.append(line); builder.append('\n'); } skeletonFile.close(); return builder.toString(); }
From source file:Main.java
public static void copyAssets(Context pContext, String pAssetFilePath, String pDestDirPath) { AssetManager assetManager = pContext.getAssets(); InputStream in = null;/*ww w .ja v a 2s .co m*/ OutputStream out = null; try { in = assetManager.open(pAssetFilePath); File outFile = new File(pDestDirPath, pAssetFilePath); out = new FileOutputStream(outFile); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } catch (IOException e) { Log.e("tag", "Failed to copy asset file: " + pAssetFilePath, e); } }
From source file:Main.java
public static Bitmap getBitmapFromAsset(Context ctx, String path, int reqWidth, int reqHeight) { if (ctx == null || path == null) return null; Bitmap bitmap = null;// w w w .j a va 2s . c o m try { AssetManager assets = ctx.getAssets(); InputStream is = assets.open(path); bitmap = decodeStream(is, reqWidth, reqHeight); } catch (IOException e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static Bitmap getImage(Context context, String path) { AssetManager as = context.getResources().getAssets(); InputStream is = null;/* w w w . j a v a2 s .co m*/ Bitmap bitmap = null; try { is = as.open(path); bitmap = BitmapFactory.decodeStream(is); } catch (IOException e) { return null; } return bitmap; }
From source file:Main.java
public static boolean IsFolder(AssetManager am, String uri) { uri = RemoveLastPathSeperator(uri);//from w ww .jav a 2 s. com try { InputStream is = am.open(uri); if (am.open(uri) == null) { return true; } else { is.close(); is = null; return false; } } catch (IOException e) { return true; } }
From source file:Main.java
/** * Loads the contents of a file in the assets directory as a string. Use '/' as separator. * * @param assetManager assetManager// ww w . j a v a2 s . c om * @param assetFileName assetFileName (relative path to asset file from assets folder) * @return The string contents of the asset * @throws IOException Any problem loading asset */ public static String loadAssetAsString(AssetManager assetManager, String assetFileName) throws IOException { BufferedReader reader = new BufferedReader( new InputStreamReader(assetManager.open(assetFileName), "UTF-8")); int character; StringBuilder builder = new StringBuilder(); do { character = reader.read(); if (character == -1) { break; } else { builder.append((char) character); } } while (true); return builder.toString(); }