Java Code Examples for android.content.Context#getFileStreamPath()

The following examples show how to use android.content.Context#getFileStreamPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginUtils.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 6 votes vote down vote up
public static void extractPlugin() {
    Context context = ApplicationContextHolder.getContext();
    try {
        String[] fileNames = context.getAssets().list("plugin");
        for (String file : fileNames) {
            File extractFile = context.getFileStreamPath(file);
            try (InputStream is = context.getAssets().open("plugin" + "/" + file);
                 FileOutputStream fos = new FileOutputStream(extractFile)) {
                byte[] buffer = new byte[1024];
                int count;
                while ((count = is.read(buffer)) > 0) {
                    fos.write(buffer, 0, count);
                }
                fos.flush();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: NormalReleaser.java    From ShellAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public File release() throws IOException {
    Context context = getContext();
    int cpuType = Cpu.getCpuType();
    final String cflagName;
    if (cpuType == Cpu.CPU_INTEL){
        cflagName = ShellAndroid.CFLAG_TOOL_X86_FILE_NAME;
    }else{
        cflagName = ShellAndroid.CFLAG_TOOL_FILE_NAME;
    }

    try {
        AssetUtils.extractAsset(context, cflagName, true);
    } catch (IOException e) {
        // e.printStackTrace();
        // extra cflag error, so don't block the sh
        throw e;
    }
    File cFlag = context.getFileStreamPath(cflagName);
    return cFlag;
}
 
Example 3
Source File: ShellAndroid.java    From ShellAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * initialize command terminal flag tool
 * with exist cflag
 * @param context
 * @param cFlag a exist cflag
 * @return
 */
public String initFlag(Context context, File cFlag){
    File flagFile = context.getFileStreamPath(FLAG_FILE_NAME + FLAG_ID.incrementAndGet());
    if (!flagFile.exists()) {
        try {
            flagFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    if (cFlag != null){
    	mFlagTrigger = cFlag.getAbsolutePath();
    }else{
    	mIsInBlockMode = false;
    }
    mChmod.setChmod(mFlagTrigger, "777");
    return flagFile.getAbsolutePath();
}
 
Example 4
Source File: TxtOverlay.java    From AndroidUSBCamera with Apache License 2.0 6 votes vote down vote up
public static void install(Context context) {
    if(instance == null) {
        instance = new TxtOverlay(context.getApplicationContext());

        File youyuan = context.getFileStreamPath("SIMYOU.ttf");
        if (!youyuan.exists()){
            AssetManager am = context.getAssets();
            try {
                InputStream is = am.open("zk/SIMYOU.ttf");
                FileOutputStream os = context.openFileOutput("SIMYOU.ttf", Context.MODE_PRIVATE);
                byte[] buffer = new byte[1024];
                int len = 0;
                while ((len = is.read(buffer)) != -1) {
                    os.write(buffer, 0, len);
                }
                os.close();
                is.close();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 5
Source File: FeaturesUtils.java    From Alibaba-Android-Certification with MIT License 5 votes vote down vote up
/** 删除手机内存中的文件*/
public static boolean deleteFile(Context context,String filename){
	File file=context.getFileStreamPath(filename);
	if(!file.exists()){
		return true;
	}else{
		return file.delete();
	}
	
}
 
Example 6
Source File: UnreadNotificationsService.java    From ghwatch with Apache License 2.0 5 votes vote down vote up
/**
 * Create service.
 *
 * @param context this service runs in
 */
public UnreadNotificationsService(Context context) {
  this.context = context;
  this.persistFile = context.getFileStreamPath(persistFileName);
  this.authenticationManager = AuthenticationManager.getInstance();
  this.notificationColor = context.getResources().getColor(R.color.apptheme_colorPrimary);
  createNotificationChannel();
}
 
Example 7
Source File: SamsungBleStack.java    From awesomesauce-rfduino with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** Function to use our version of BluetoothAdapter and BluetoothDevice if the native Android OS doesn't have 4.3 yet. 
 * @throws IOException 
 * @throws ClassNotFoundException **/
public static void loadSamsungLibraries(Context hostActivityContext) throws IOException, ClassNotFoundException{
	File internalStoragePath = hostActivityContext.getFileStreamPath("com.samsung.ble.sdk-1.0.jar");
	if (!internalStoragePath.exists()){
		
	
	  //We'll copy the SDK to disk so we can open the JAR file:
	  // it has to be first copied from asset resource to a storage location.
	  InputStream jar = hostActivityContext.getAssets().open("com.samsung.ble.sdk-1.0.jar", Context.MODE_PRIVATE);
	  FileOutputStream outputStream = hostActivityContext.openFileOutput("com.samsung.ble.sdk-1.0.jar", Context.MODE_PRIVATE);
	     
	  int size = 0;
	    // Read the entire resource into a local byte buffer.
	    byte[] buffer = new byte[1024];
	    while((size=jar.read(buffer,0,1024))>=0){
	      outputStream.write(buffer,0,size);
	    }
	    jar.close();
	   
	}
	    
	  Log.i(logTag, internalStoragePath.getAbsolutePath()+" exists? "+ internalStoragePath.exists());
	  
         URL[] urls = { new URL("jar:file:" + internalStoragePath.getAbsolutePath()+"!/") };
         URLClassLoader cl  = URLClassLoader.newInstance(urls);
         
         samsungBluetoothAdapterClass = cl.loadClass("android.bluetooth.BluetoothAdapter");
         samsungBluetoothDeviceClass = cl.loadClass("android.bluetooth.BluetoothDevice");
 	
}
 
Example 8
Source File: ColoringUtils.java    From coloring with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deletes the error log file.
 * @param context
 */
public static void deleteErrorLogFile(Context context) {
    File errorLog = context.getFileStreamPath(context.getString(R.string.error_log_file));
    if (errorLog.exists()) {
        //noinspection ResultOfMethodCallIgnored
        errorLog.delete();
    }
}
 
Example 9
Source File: CacheManager.java    From Cotable with Apache License 2.0 5 votes vote down vote up
/**
 * Juget whether the cache file exists.
 *
 * @param context   context
 * @param cachefile cache file
 * @return true if the cache data exists, false otherwise.
 */
public static boolean isExistDataCache(Context context, String cachefile) {
    if (context == null)
        return false;
    boolean exist = false;
    File data = context.getFileStreamPath(cachefile);
    if (data.exists())
        exist = true;
    return exist;
}
 
Example 10
Source File: FileUtils.java    From Varis-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Reads data from the file in internal memory
 *
 * @param fileName File name
 * @param context  Context
 * @return Read data
 */
public static String readInternalFile(String fileName, Context context) {
    String dataFromFile = "";

    File file = context.getFileStreamPath(fileName);
    if (file.exists()) {

        try {
            InputStream inputStream = context.openFileInput(fileName);
            if (inputStream != null) {
                InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                String receiveString = "";
                StringBuilder stringBuilder = new StringBuilder();

                while ((receiveString = bufferedReader.readLine()) != null) {
                    stringBuilder.append(receiveString);
                }

                inputStream.close();
                dataFromFile = stringBuilder.toString();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return dataFromFile;
}
 
Example 11
Source File: FilePayload.java    From cloudinary_android with MIT License 5 votes vote down vote up
private File getFile(Context context) throws FileNotFoundException {
    // check if data is an absolute path or a local app path and check if file exists:
    File file = data.contains(File.separator) ? new File(data) : context.getFileStreamPath(data);

    if (!file.exists()) {
        throw new FileNotFoundException(String.format("File '%s' does not exist", data));
    }

    return file;
}
 
Example 12
Source File: PackageFilesUtil.java    From springreplugin with Apache License 2.0 5 votes vote down vote up
public static boolean isExtractedFromAssetsToFiles(Context c, String filename) {
    File file = c.getFileStreamPath(filename);
    if (file == null || !file.exists()) {
        if (BuildConfig.DEBUG) {
            Log.i(TAG, "Extract no exist file from assets filename = " + filename);
        }
        return true;
    }
    // compare file version for extract
    return compareDataFileVersion(c, filename);
}
 
Example 13
Source File: PackageFilesUtil.java    From springreplugin with Apache License 2.0 5 votes vote down vote up
/**
 * 检查 files 目录下个某个文件是否已经为最新(比 assets 目录下的新)
 *
 * @param c
 * @param filename
 * @return 如果文件比 assets 下的同名文件的时间戳旧,或者文件不存在,则返回 false.
 */
public static boolean isFileUpdated(Context c, String filename) {
    File file = c.getFileStreamPath(filename);
    if (file == null) {
        return false;
    }
    if (!file.exists()) {
        return false;
    }

    long timestampOfFile = getFileTimestamp(c, filename);
    long timestampOfAsset = getBundleTimestamp(c, filename);

    return (timestampOfAsset <= timestampOfFile);
}
 
Example 14
Source File: Hooker.java    From FuzzDroid with Apache License 2.0 5 votes vote down vote up
private static void doPrivateDirFileFuzzing(MethodHookParam param, int index, FileFuzzingSerializableObject fuzzyingObject) {
	String fileName = (String)param.args[index];
	Context appContext = Hooker.applicationContext;
	File localFile = appContext.getFileStreamPath(fileName);
	//only create a dummy file if there is no file
	if(!localFile.exists()) {
		//what file format do we need?
		copyCorrectFile(localFile, fuzzyingObject.getFileFormat());			
	}
}
 
Example 15
Source File: identity.java    From android-sqrl with GNU General Public License v3.0 4 votes vote down vote up
public boolean deleteIdentityFile(Context con) {
	File file = con.getFileStreamPath("sqrl.dat");
       return file.delete();
}
 
Example 16
Source File: AuthenticationManager.java    From ghwatch with Apache License 2.0 4 votes vote down vote up
private File getCuFile(Context context) {
  if (cuFile == null)
    cuFile = context.getFileStreamPath(cuFileName);
  return cuFile;
}
 
Example 17
Source File: Service.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
public static boolean doesStorageFileExist(String key, Context context) {
    File file = context.getFileStreamPath(key);
    return file.exists();
}
 
Example 18
Source File: AuthenticationManager.java    From ghwatch with Apache License 2.0 4 votes vote down vote up
private File getCuliFile(Context context) {
  if (culiFile == null)
    culiFile = context.getFileStreamPath(culiFileName);
  return culiFile;
}
 
Example 19
Source File: Utility.java    From ExpressHelper with GNU General Public License v3.0 3 votes vote down vote up
public static String readFile(Context context, String name) throws IOException{
	File file = context.getFileStreamPath(name);
	InputStream is = new FileInputStream(file);

	byte b[] = new byte[(int) file.length()];

	is.read(b);
	is.close();

	String string = new String(b);

	return string;
}
 
Example 20
Source File: PreferencesUtils.java    From ghwatch with Apache License 2.0 2 votes vote down vote up
/**
 * Store donation timestamp.
 *
 * @param context
 * @param timestamp to store
 */
public static void storeDonationTimestamp(Context context, Long timestamp) {
  File file = context.getFileStreamPath(DTFN);
  Utils.writeToStore(TAG, context, file, timestamp);
}