Search in sources :

Example 26 with AssetManager

use of android.content.res.AssetManager in project rainbow by juankysoriano.

the class RainbowIO method createInputRaw.

/**
     * Call createInput() without automatic gzip decompression.
     */
public static InputStream createInputRaw(Context context, final String filename) {
    InputStream stream = null;
    if (filename == null) {
        return null;
    }
    if (filename.length() == 0) {
        return null;
    }
    if (filename.indexOf(":") != -1) {
        // at least smells like URL
        try {
            HttpGet httpRequest = null;
            httpRequest = new HttpGet(URI.create(filename));
            final HttpClient httpclient = new DefaultHttpClient();
            final HttpResponse response = httpclient.execute(httpRequest);
            final HttpEntity entity = response.getEntity();
            return entity.getContent();
        } catch (final MalformedURLException mfue) {
        } catch (final FileNotFoundException fnfe) {
        } catch (final IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    // Try the assets folder
    final AssetManager assets = context.getAssets();
    try {
        stream = assets.open(filename);
        if (stream != null) {
            return stream;
        }
    } catch (final IOException e) {
    }
    // Maybe this is an absolute path, didja ever think of that?
    final File absFile = new File(filename);
    if (absFile.exists()) {
        try {
            stream = new FileInputStream(absFile);
            if (stream != null) {
                return stream;
            }
        } catch (final FileNotFoundException fnfe) {
        // fnfe.printStackTrace();
        }
    }
    // Maybe this is a file that was written by the sketch later.
    final File sketchFile = new File(sketchPath(context, filename));
    if (sketchFile.exists()) {
        try {
            stream = new FileInputStream(sketchFile);
            if (stream != null) {
                return stream;
            }
        } catch (final FileNotFoundException fnfe) {
        }
    }
    // Attempt to load the file more directly. Doesn't like paths.
    try {
        stream = context.openFileInput(filename);
        if (stream != null) {
            return stream;
        }
    } catch (final FileNotFoundException e) {
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) AssetManager(android.content.res.AssetManager) HttpEntity(org.apache.http.HttpEntity) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) FileNotFoundException(java.io.FileNotFoundException) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) File(java.io.File) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) FileInputStream(java.io.FileInputStream)

Example 27 with AssetManager

use of android.content.res.AssetManager in project restful-android by jeremyhaberman.

the class AboutActivity method getInputStream.

private static InputStream getInputStream(Context context, String filename) {
    AssetManager assetManager = context.getAssets();
    InputStream inputStream = null;
    try {
        inputStream = assetManager.open(filename);
    } catch (IOException e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
    }
    return inputStream;
}
Also used : AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 28 with AssetManager

use of android.content.res.AssetManager in project Talon-for-Twitter by klinker24.

the class IOUtils method readChangelog.

public static String readChangelog(Context context) {
    String ret = "";
    try {
        AssetManager assetManager = context.getAssets();
        Scanner in = new Scanner(assetManager.open("changelog.txt"));
        while (in.hasNextLine()) {
            ret += in.nextLine() + "\n";
        }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
    return ret;
}
Also used : Scanner(java.util.Scanner) AssetManager(android.content.res.AssetManager) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 29 with AssetManager

use of android.content.res.AssetManager in project LitePal by LitePalFramework.

the class ModelListActivity method getInputStream.

private InputStream getInputStream() throws IOException {
    AssetManager assetManager = LitePalApplication.getContext().getAssets();
    String[] fileNames = assetManager.list("");
    if (fileNames != null && fileNames.length > 0) {
        for (String fileName : fileNames) {
            if (Const.Config.CONFIGURATION_FILE_NAME.equalsIgnoreCase(fileName)) {
                return assetManager.open(fileName, AssetManager.ACCESS_BUFFER);
            }
        }
    }
    throw new ParseConfigurationFileException(ParseConfigurationFileException.CAN_NOT_FIND_LITEPAL_FILE);
}
Also used : AssetManager(android.content.res.AssetManager) ParseConfigurationFileException(org.litepal.exceptions.ParseConfigurationFileException)

Example 30 with AssetManager

use of android.content.res.AssetManager in project MarsDaemon by Marswin.

the class DaemonStrategyXiaomi method copyAssets.

private void copyAssets(Context context, String assetsFilename, File file, String mode) throws IOException, InterruptedException {
    AssetManager manager = context.getAssets();
    final InputStream is = manager.open(assetsFilename);
    copyFile(file, is, mode);
}
Also used : AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream)

Aggregations

AssetManager (android.content.res.AssetManager)201 IOException (java.io.IOException)75 InputStream (java.io.InputStream)60 Resources (android.content.res.Resources)48 XmlResourceParser (android.content.res.XmlResourceParser)28 File (java.io.File)28 DisplayMetrics (android.util.DisplayMetrics)25 Configuration (android.content.res.Configuration)16 Bitmap (android.graphics.Bitmap)13 BufferedReader (java.io.BufferedReader)13 FileOutputStream (java.io.FileOutputStream)13 InputStreamReader (java.io.InputStreamReader)12 FileInputStream (java.io.FileInputStream)10 FileNotFoundException (java.io.FileNotFoundException)10 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)10 Intent (android.content.Intent)8 AndroidRuntimeException (android.util.AndroidRuntimeException)8 OutputStream (java.io.OutputStream)8 Method (java.lang.reflect.Method)8 AttributeSet (android.util.AttributeSet)7