List of usage examples for android.content Context openFileInput
public abstract FileInputStream openFileInput(String name) throws FileNotFoundException;
From source file:net.tawacentral.roger.secrets.FileUtils.java
/** * Gets the salt and rounds already in use on this device, or null if none * exists./*from w w w. j av a 2 s. com*/ * * @param context Activity context in which the save is called. * @param path The file to read the salt and rounds from. Can either be the * string SECRETS_FILE_NAME_SDCARD, SECRETS_FILE_NAME, or the name of a * restore point. * @return the salt and rounds */ public static SaltAndRounds getSaltAndRounds(Context context, String path) { // The salt is stored as a byte array at the start of the secrets file. FileInputStream input = null; try { input = SECRETS_FILE_NAME_SDCARD.equals(path) ? new FileInputStream(path) : context.openFileInput(path); return getSaltAndRounds(input); } catch (Exception ex) { Log.e(LOG_TAG, "getSaltAndRounds", ex); } finally { try { if (null != input) input.close(); } catch (IOException ex) { } } return new SaltAndRounds(null, 0); }
From source file:com.rcythr.masq.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/* ww w . jav a 2 s. c om*/ * @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 new FileInputStream(getSDCardFile()); } }
From source file:com.mhise.util.MHISEUtil.java
public static PrivateKey readKey(Context context) throws Exception { String keyFile = "privateKey.key"; FileInputStream fis = context.openFileInput(keyFile); int kl = fis.available(); byte[] kb = new byte[kl]; fis.read(kb);/* w ww . j a va 2 s .c o m*/ fis.close(); KeyFactory kf = KeyFactory.getInstance("RSA", "BC"); PKCS8EncodedKeySpec ks = new PKCS8EncodedKeySpec(kb); PrivateKey pk = kf.generatePrivate(ks); return pk; }
From source file:com.denayer.ovsr.MyFTPClient.java
public boolean ftpUpload(String srcFilePath, String desFileName, String desDirectory, Context context) { boolean status = false; try {//from w w w. j ava2 s .com // FileInputStream srcFileStream = new FileInputStream(srcFilePath); FileInputStream srcFileStream = context.openFileInput(srcFilePath); // change working directory to the destination directory //if (ftpChangeDirectory(desDirectory)) { status = mFTPClient.storeFile(desFileName, srcFileStream); //} srcFileStream.close(); return status; } catch (Exception e) { Log.d(TAG, "upload failed: " + e); } return status; }
From source file:org.onepf.opfmaps.osmdroid.model.BitmapDescriptor.java
@NonNull private InputStream createStream(@NonNull final Context context) throws IOException { if (path == null) { throw new IllegalArgumentException("Path can't be null"); }/*from ww w .ja v a 2s . c o m*/ switch (source) { case ASSET: return context.getAssets().open(path); case FILE_NAME: return context.openFileInput(path); } throw new IllegalArgumentException("Wrong source : " + source); }
From source file:net.tawacentral.roger.secrets.FileUtils.java
/** * Opens the secrets file using the password retrieved from the user. * * @param context Activity context in which the load is called. * @param fileName Name of file to be loaded * @param info CipherInfo// w ww . j a v a2 s. c o m * @return A list of loaded secrets. */ public static ArrayList<Secret> loadSecrets(Context context, String fileName, CipherInfo info) { Log.d(LOG_TAG, "FileUtils.loadSecrets"); if (null == info) return null; ArrayList<Secret> secrets = null; InputStream input = null; try { input = SECRETS_FILE_NAME_SDCARD.equals(fileName) ? new FileInputStream(fileName) : context.openFileInput(fileName); secrets = readSecrets(input, info.decryptCipher, info.salt, info.rounds); } catch (Exception ex) { Log.e(LOG_TAG, "loadSecrets", ex); } finally { try { if (null != input) input.close(); } catch (IOException ex) { } } Log.d(LOG_TAG, "FileUtils.loadSecrets: done"); return secrets; }
From source file:net.tawacentral.roger.secrets.FileUtils.java
/** * See previous method for description.// ww w.j a v a 2 s . c o m * * @param context * Activity context in which the load is called. * @param fileName Name of file to be loaded * @param info CipherInfo * @return A list of loaded secrets. */ public static ArrayList<Secret> loadSecretsV3(Context context, CipherInfo info, String fileName) { Log.d(LOG_TAG, "FileUtils.loadSecretsV3"); if (null == info) return null; ArrayList<Secret> secrets = null; InputStream input = null; try { input = SECRETS_FILE_NAME_SDCARD.equals(fileName) ? new FileInputStream(fileName) : context.openFileInput(fileName); secrets = readSecretsV2(input, info.decryptCipher, info.salt, info.rounds); } catch (Exception ex) { Log.e(LOG_TAG, "loadSecretsV3", ex); } finally { try { if (null != input) input.close(); } catch (IOException ex) { } } Log.d(LOG_TAG, "FileUtils.loadSecretsv3: done"); return secrets; }
From source file:net.tawacentral.roger.secrets.FileUtils.java
/** * See previous method for description.//from w ww . j a v a 2 s .c om * * @param context Activity context in which the load is called. * @param cipher Decryption cipher for old encryption. * @param fileName Name of file to be loaded * @return A list of loaded secrets. */ @SuppressWarnings("unchecked") public static ArrayList<Secret> loadSecretsV1(Context context, Cipher cipher, String fileName) { Log.d(LOG_TAG, "FileUtils.loadSecretsV1"); if (null == cipher) return null; ArrayList<Secret> secrets = null; ObjectInputStream input = null; try { InputStream fis = SECRETS_FILE_NAME_SDCARD.equals(fileName) ? new FileInputStream(fileName) : context.openFileInput(fileName); input = new ObjectInputStream(new CipherInputStream(fis, cipher)); secrets = (ArrayList<Secret>) input.readObject(); } catch (Exception ex) { Log.e(LOG_TAG, "loadSecretsV1", ex); } finally { try { if (null != input) input.close(); } catch (IOException ex) { } } Log.d(LOG_TAG, "FileUtils.loadSecretsV1: done"); return secrets; }
From source file:net.tawacentral.roger.secrets.FileUtils.java
/** * See previous method for description.// ww w . j a v a 2 s. co m * * @param context Activity context in which the load is called. * @param fileName Name of file to be loaded * @param cipher Decryption cipher for old encryption. * @param salt The salt to use when creating the encryption key. * @param rounds The number of rounds for bcrypt. * @return A list of loaded secrets. */ public static ArrayList<Secret> loadSecretsV2(Context context, String fileName, Cipher cipher, byte[] salt, int rounds) { Log.d(LOG_TAG, "FileUtils.loadSecretsV2"); if (null == cipher) return null; ArrayList<Secret> secrets = null; InputStream input = null; try { input = SECRETS_FILE_NAME_SDCARD.equals(fileName) ? new FileInputStream(fileName) : context.openFileInput(fileName); secrets = readSecretsV2(input, cipher, salt, rounds); } catch (Exception ex) { Log.e(LOG_TAG, "loadSecretsV2", ex); } finally { try { if (null != input) input.close(); } catch (IOException ex) { } } return secrets; }
From source file:org.blanco.techmun.android.cproviders.MensajesFetcher.java
private List<Mensaje> tryToLoadFromCache(Context context, boolean forceCacheLoad) { Long lastCache = PreferenceManager.getDefaultSharedPreferences(context).getLong("mensajes_last_cache", 1); long diff = System.currentTimeMillis() - lastCache; if (diff < 180000 && !forceCacheLoad) { //if the cache of the mensajes is greater than 3 minutes launch a new refresh return null; }/*from w w w . j av a 2 s. c om*/ try { FileInputStream mesasFIS = context.openFileInput("mensajes.df"); ObjectInputStream mesasOIS = new ObjectInputStream(mesasFIS); List<Mensaje> result = (List<Mensaje>) 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; } }