List of usage examples for android.content Context openFileInput
public abstract FileInputStream openFileInput(String name) throws FileNotFoundException;
From source file:org.growingstems.scouting.MatchSchedule.java
private String getSchedule(Context parent) { try {/*from w ww . ja va2 s.c om*/ BufferedInputStream bis = new BufferedInputStream(parent.openFileInput(FILENAME)); byte[] buffer = new byte[bis.available()]; bis.read(buffer, 0, buffer.length); return new String(buffer); } catch (Exception e) { return ""; } }
From source file:org.blanco.techmun.android.cproviders.EventosFetcher.java
private Eventos tryToLoadFromCache(Context context, long mesaId) { try {//from ww w.j a v a2 s. c o m FileInputStream mesasFIS = context.openFileInput("eventos_" + mesaId + ".df"); ObjectInputStream mesasOIS = new ObjectInputStream(mesasFIS); Eventos result = (Eventos) mesasOIS.readObject(); mesasOIS.close(); return result; } catch (IOException e) { Log.e("tachmun", "Error opening cache file for mesas in content provider. " + "No cache will be restored", e); return null; } catch (ClassNotFoundException e) { Log.e("tachmun", "Error in cache file for mesas in content provider. " + "Something is there but is not a Mesas object. Cache no restored", e); return null; } }
From source file:org.frc836.database.DB.java
public static void exportToCSV(Context context) { try {//from w w w .ja v a 2 s . c om cb = new ExportCallback(); String filename; try { BufferedInputStream bis = new BufferedInputStream(context.openFileInput(FILENAME)); byte[] buffer = new byte[bis.available()]; bis.read(buffer, 0, buffer.length); filename = new String(buffer); } catch (Exception e) { filename = null; } cb.context = context; new FileSelector(context, FileOperation.SELECTDIR, mDirSelectListener, null, filename).show(); } catch (Exception e) { Toast.makeText(context, "Error exporting Database", Toast.LENGTH_LONG).show(); } }
From source file:com.thoughtmetric.tl.TLLib.java
private static TagNode TagNodeFromURLHelper(InputStream is, String fullTag, Handler handler, Context context, HtmlCleaner cleaner) throws IOException { SharedPreferences settings = context.getSharedPreferences(Settings.SETTINGS_FILE_NAME, 0); boolean disableSmartParsing = settings.getBoolean(Settings.DISABLE_SMART_PARSING, false); if (fullTag != null && !disableSmartParsing) { FileOutputStream fos = context.openFileOutput(TEMP_FILE_NAME, Context.MODE_WORLD_WRITEABLE); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); TagParser.extractTagToFile(fullTag, is, bw); bw.flush();// w w w . j a v a 2s .c o m bw.close(); if (handler != null) handler.sendEmptyMessage(PROGRESS_PARSING); return cleaner.clean(context.openFileInput(TEMP_FILE_NAME)); } else { if (handler != null) handler.sendEmptyMessage(PROGRESS_PARSING); return cleaner.clean(is); } }
From source file:com.fusionjack.slimota.configs.LinkConfig.java
public List<OTALink> getLinks(Context context, boolean force) { if (mLinks == null || force) { try {/* w ww .j av a2s. c o m*/ mLinks = new ArrayList<>(); FileInputStream fis = context.openFileInput(FILENAME); BufferedReader reader = new BufferedReader(new InputStreamReader(fis)); StringBuffer out = new StringBuffer(); String line; while ((line = reader.readLine()) != null) { out.append(line); } reader.close(); fis.close(); JSONArray jsonLinks = new JSONArray(out.toString()); for (int i = 0; i < jsonLinks.length(); i++) { JSONObject jsonLink = jsonLinks.getJSONObject(i); OTALink link = new OTALink(jsonLink.getString(OTAParser.ID)); link.setTitle(jsonLink.getString(OTAParser.TITLE)); link.setDescription(jsonLink.getString(OTAParser.DESCRIPTION)); link.setUrl(jsonLink.getString(OTAParser.URL)); mLinks.add(link); } } catch (JSONException | IOException e) { OTAUtils.logError(e); } } return mLinks; }
From source file:com.psiphon3.psiphonlibrary.TunnelManager.java
public static String getServerEntries(Context context) { StringBuilder list = new StringBuilder(); for (String encodedServerEntry : EmbeddedValues.EMBEDDED_SERVER_LIST) { list.append(encodedServerEntry); list.append("\n"); }//from w w w . jav a2s .c o m // Import legacy server entries try { FileInputStream file = context.openFileInput(LEGACY_SERVER_ENTRY_FILENAME); BufferedReader reader = new BufferedReader(new InputStreamReader(file)); StringBuilder json = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { json.append(line); } file.close(); JSONObject obj = new JSONObject(json.toString()); JSONArray jsonServerEntries = obj.getJSONArray("serverEntries"); // MAX_LEGACY_SERVER_ENTRIES ensures the list we pass through to tunnel-core // is unlikely to trigger an OutOfMemoryError for (int i = 0; i < jsonServerEntries.length() && i < MAX_LEGACY_SERVER_ENTRIES; i++) { list.append(jsonServerEntries.getString(i)); list.append("\n"); } // Don't need to repeat the import again context.deleteFile(LEGACY_SERVER_ENTRY_FILENAME); } catch (FileNotFoundException e) { // pass } catch (IOException | JSONException | OutOfMemoryError e) { MyLog.g("prepareServerEntries failed: %s", e.getMessage()); } return list.toString(); }
From source file:com.agateau.equiv.ui.Kernel.java
private void loadDay(Context context) { NLog.i("");/*from w w w.j a v a 2 s . c o m*/ FileInputStream stream; try { stream = context.openFileInput(DAY_JSON); } catch (FileNotFoundException e) { return; } try { DayJsonIO.read(stream, mDay, mProductStore); stream.close(); } catch (IOException | JSONException e) { NLog.e("Failed to load day: %s", e); } }
From source file:com.jamessimshaw.wallpaperhelper.datasources.WallpaperFileHelper.java
public Wallpaper loadWallpaper(Context context, boolean isLandscape) { Bitmap bitmap;//from w w w . ja va 2 s. co m String filename = isLandscape ? LANDSCAPE_FILENAME : PORTRAIT_FILENAME; try { //TODO: Set this up to be an async task FileInputStream fileInputStream = context.openFileInput(filename); bitmap = BitmapFactory.decodeStream(fileInputStream); fileInputStream.close(); } catch (IOException e) { //Set a default Wallpaper of a black screen and send a notification Bitmap.Config bitmapOptions = Bitmap.Config.ARGB_8888; bitmap = Bitmap.createBitmap(100, 100, bitmapOptions); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.BLACK); Intent settingsIntent = new Intent(context, SettingsActivity.class); PendingIntent notificationIntent = PendingIntent.getActivity(context, 0, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT); String notificationString = isLandscape ? context.getString(R.string.noLandscapeImage) : context.getString(R.string.noPortraitImage); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_notification_small) .setContentTitle(context.getString(R.string.app_name)).setContentText(notificationString) .setContentIntent(notificationIntent); int notificationId = 1; NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(notificationId, notificationBuilder.build()); } return new Wallpaper(bitmap, isLandscape); }
From source file:com.project.qrypto.keymanagement.KeyManager.java
/** * Returns a file in stream for a keystore. It will use the settings loaded to determine where it is. * @param context the context to use/*from w ww . ja v a 2s . co m*/ * @return the opened FileInputStream * * @throws FileNotFoundException if the file is not found */ private FileInputStream getAssociatedInFileStream(Context context) throws FileNotFoundException { if (internalStorage) { return context.openFileInput(KEYSTORE); } else { return null; } }
From source file:com.irahul.worldclock.WorldClockData.java
public WorldClockData(Context context) { this.context = context; // load timezones if not available if (this.selectedTimeZones == null) { try {/*from ww w .j a va 2s . co m*/ FileInputStream fis = context.openFileInput(FILENAME); StringBuilder fileData = new StringBuilder(); byte[] buffer = new byte[1]; while (fis.read(buffer) != -1) { fileData.append(new String(buffer)); } Log.d(TAG, "RAW - Loaded from file:" + fileData.toString()); selectedTimeZones = deserialize(fileData.toString()); } catch (FileNotFoundException e) { // no file exists - treat as empty list and create file createFile(); this.selectedTimeZones = new HashSet<WorldClockTimeZone>(); } catch (IOException e) { throw new WorldClockException(e); } catch (JSONException e) { throw new WorldClockException(e); } } }