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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations