Java Code Examples for java.io.File.setReadable()

The following are Jave code examples for showing how to use setReadable() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: lantian-nolitter   File: SettingsFragment.java   Source Code and License Vote up 6 votes
@Override
public void onPause() {
    // From https://forum.xda-developers.com/xposed/how-to-save-load-module-settings-t3640881
    super.onPause();

    // Set preferences permissions to be world readable
    // Workaround for Android N and above since MODE_WORLD_READABLE will cause security exception and FC.
    final File dataDir = new File(getActivity().getApplicationInfo().dataDir);
    final File prefsDir = new File(dataDir, "shared_prefs");
    final File prefsFile = new File(prefsDir, getPreferenceManager().getSharedPreferencesName() + ".xml");

    if (prefsFile.exists()) {
        dataDir.setReadable(true, false);
        dataDir.setExecutable(true, false);

        prefsDir.setReadable(true, false);
        prefsDir.setExecutable(true, false);

        prefsFile.setReadable(true, false);
        prefsFile.setExecutable(true, false);
    }
}
 
Example 2
Project: uavstack   File: UpgradeUtil.java   Source Code and License Vote up 6 votes
/**
 * Change the permission of the file to --Readable, Writable, Executable--
 * 
 * @param fileName
 */
public static void changeFilePermisson4Win(String fileName) {

    File file = new File(fileName);
    if (!file.exists()) {
        return;
    }

    if (!file.canRead()) {
        file.setReadable(true);
    }

    if (!file.canWrite()) {
        file.setWritable(true);
    }

    if (!file.canExecute()) {
        file.setExecutable(true);
    }
}
 
Example 3
Project: oneops   File: AbstractOrderExecutor.java   Source Code and License Vote up 6 votes
/**
 * writes private key
 *
 * @param key String
 */
protected String writePrivateKey(String key) {
  String uuid = UUID.randomUUID().toString();
  String fileName = config.getDataDir() + "/" + uuid;
  try (BufferedWriter bw = Files.newBufferedWriter(Paths.get(fileName))) {
    bw.write(key);
    bw.close();
    File f = new File(fileName);
    f.setExecutable(false, false);
    f.setReadable(false, false);
    f.setWritable(false, false);
    f.setReadable(true, true);
    f.setWritable(true, true);
    logger.debug("file: " + fileName);
  } catch (IOException e) {
    logger.error("could not write file: " + fileName + " msg:"
        + e.getMessage());
  }
  return fileName;
}
 
Example 4
Project: sstore-soft   File: SnapshotScan.java   Source Code and License Vote up 6 votes
private final List<File> retrieveRelevantFiles(String filePath) {
    final File path = new File(filePath);

    if (!path.exists()) {
        errorString = "Provided search path does not exist: " + filePath;
        return null;
    }

    if (!path.isDirectory()) {
        errorString = "Provided path exists but is not a directory: " + filePath;
        return null;
    }

    if (!path.canRead()) {
        if (!path.setReadable(true)) {
            errorString = "Provided path exists but is not readable: " + filePath;
            return null;
        }
    }

    return retrieveRelevantFiles(path, 0);
}
 
Example 5
Project: web3j-maven-plugin   File: SolC.java   Source Code and License Vote up 6 votes
private void initBundled() throws IOException {
    File tmpDir = new File(System.getProperty("java.io.tmpdir"), "solc");
    tmpDir.setReadable(true);
    tmpDir.setWritable(true);
    tmpDir.setExecutable(true);
    tmpDir.mkdirs();

    String solcPath = "/native/" + getOS() + "/solc/";
    InputStream is = getClass().getResourceAsStream(solcPath + "file.list");
    Scanner scanner = new Scanner(is);
    while (scanner.hasNext()) {
        String s = scanner.next();
        File targetFile = new File(tmpDir, s);
        InputStream fis = getClass().getResourceAsStream(solcPath + s);
        Files.copy(fis, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        if (solc == null) {
            // first file in the list denotes executable
            solc = targetFile;
            solc.setExecutable(true);
        }
        targetFile.deleteOnExit();
    }
    tmpDir.deleteOnExit();
}
 
Example 6
Project: s-store   File: SnapshotScan.java   Source Code and License Vote up 6 votes
private final List<File> retrieveRelevantFiles(String filePath) {
    final File path = new File(filePath);

    if (!path.exists()) {
        errorString = "Provided search path does not exist: " + filePath;
        return null;
    }

    if (!path.isDirectory()) {
        errorString = "Provided path exists but is not a directory: " + filePath;
        return null;
    }

    if (!path.canRead()) {
        if (!path.setReadable(true)) {
            errorString = "Provided path exists but is not readable: " + filePath;
            return null;
        }
    }

    return retrieveRelevantFiles(path, 0);
}
 
Example 7
Project: dshell   File: DefaultJavaFileCompilerTest.java   Source Code and License Vote up 5 votes
@Test(expected = IllegalArgumentException.class)
public void throws_exception_when_provided_java_file_is_not_accessible() throws IOException {
    compiler.init(
            folder.getRoot().getAbsolutePath(),
            new DefaultDependencyResolver(),
            new DefaultInternalCompiler()
    );

    final File javaFile = folder.newFile();
    javaFile.setReadable(false);
    compiler.compile(javaFile.getAbsolutePath(), null);
}
 
Example 8
Project: sstore-soft   File: SnapshotScan.java   Source Code and License Vote up 5 votes
private final List<File> retrieveRelevantFiles(File f, int recursion) {
    assert (f.isDirectory());
    assert (f.canRead());

    ArrayList<File> retvals = new ArrayList<File>();

    if (recursion == 32) {
        return retvals;
    }

    for (File file : f.listFiles()) {
        if (file.isDirectory()) {
            if (!file.canRead()) {
                if (!file.setReadable(true)) {
                    continue;
                }
            }
            retvals.addAll(retrieveRelevantFiles(file, recursion++));
        } else {
            if (!file.getName().endsWith(".vpt") && !file.getName().endsWith(".digest")) {
                continue;
            }
            if (!file.canRead()) {
                file.setReadable(true);
            }
            retvals.add(file);
        }
    }
    return retvals;
}
 
Example 9
Project: sstore-soft   File: SnapshotDelete.java   Source Code and License Vote up 5 votes
private final List<File> retrieveRelevantFiles(String filePath, String nonce) {
    final File path = new File(filePath);

    if (!path.exists()) {
        errorString = "Provided search path does not exist: " + filePath;
        return null;
    }

    if (!path.isDirectory()) {
        errorString = "Provided path exists but is not a directory: " + filePath;
        return null;
    }

    if (!path.canRead()) {
        if (!path.setReadable(true)) {
            errorString = "Provided path exists but is not readable: " + filePath;
            return null;
        }
    }

    if (!path.canWrite()) {
        if (!path.setWritable(true)) {
            errorString = "Provided path exists but is not writable: " + filePath;
            return null;
        }
    }

    return retrieveRelevantFiles(path, nonce);
}
 
Example 10
Project: aos-MediaLib   File: ImageScaler.java   Source Code and License Vote up 5 votes
private static File createFile(String path) {
    if (DBG) Log.d(TAG, "createFile: " + path);
    File f = new File(path);
    if (f.exists())
        return f;
    try {
        f.createNewFile();
        f.setReadable(true, false);
    } catch (IOException e) {
        Log.e(TAG, "could not create file:" + path, e);
    }
    return f;
}
 
Example 11
Project: secrets-locker   File: FileSystemSecretsLockerTest_constructor.java   Source Code and License Vote up 5 votes
@Test(expected = IllegalArgumentException.class)
public void testFileSystemSecretsLocker_notReadable() {
    File tmpdir = new File(System.getProperty("java.io.tmpdir") + "/foo");

    tmpdir.deleteOnExit();
    tmpdir.mkdir();
    tmpdir.setReadable(false);

    secretsLocker = new FileSystemSecretsLocker(tmpdir.getAbsolutePath());
}
 
Example 12
Project: Accessibility   File: FileUtils.java   Source Code and License Vote up 5 votes
public static boolean changeFilePermission755(final File file) {
    try {
        if (file == null || !file.exists()) {
            return false;
        }

        file.setReadable(true, false);
        file.setExecutable(true, false);
        file.setWritable(true, true);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}
 
Example 13
Project: trellis-rosid-file   File: CachedResourceTest.java   Source Code and License Vote up 5 votes
@Test
public void testReadError() {
    final Optional<Resource> res = CachedResource.find(readonly2, rdf.createIRI("trellis:repository/ldpnr"));
    assertTrue(res.isPresent());

    final File quads = new File(readonly2, RESOURCE_QUADS);
    assumeTrue(quads.setReadable(false));
    assertEquals(0L, res.get().stream().count());
    quads.setReadable(true);
}
 
Example 14
Project: XPrivacy   File: PrivacyProvider.java   Source Code and License Vote up 5 votes
public static void fixFilePermissions() {
	File folder = new File(Util.getUserDataDirectory(Process.myUid()) + File.separator + "shared_prefs");
	folder.setReadable(true, false);
	File[] files = folder.listFiles();
	if (files != null)
		for (File file : files)
			if (file.getName().startsWith("biz.bokhorst.xprivacy.provider.") && file.getName().endsWith(".xml")
					&& !file.getName().contains(".usage."))
				file.setReadable(true, false);
}
 
Example 15
Project: s-store   File: SnapshotScan.java   Source Code and License Vote up 5 votes
private final List<File> retrieveRelevantFiles(File f, int recursion) {
    assert (f.isDirectory());
    assert (f.canRead());

    ArrayList<File> retvals = new ArrayList<File>();

    if (recursion == 32) {
        return retvals;
    }

    for (File file : f.listFiles()) {
        if (file.isDirectory()) {
            if (!file.canRead()) {
                if (!file.setReadable(true)) {
                    continue;
                }
            }
            retvals.addAll(retrieveRelevantFiles(file, recursion++));
        } else {
            if (!file.getName().endsWith(".vpt") && !file.getName().endsWith(".digest")) {
                continue;
            }
            if (!file.canRead()) {
                file.setReadable(true);
            }
            retvals.add(file);
        }
    }
    return retvals;
}
 
Example 16
Project: fresco_floodlight   File: CryptoUtil.java   Source Code and License Vote up 5 votes
public static void writeSharedSecret(String keyStorePath,
                                     String keyStorePassword,
                                     byte[] sharedSecret) 
                                               throws Exception {
    char[] password = keyStorePassword.toCharArray();
    KeyStore ks;
    try {
        ks = readKeyStore(keyStorePath, password);
    } catch (FileNotFoundException e) {
        ks = KeyStore.getInstance("JCEKS");
        ks.load(null, password);
    } 

    KeyStore.ProtectionParameter protParam =
            new KeyStore.PasswordProtection(password);
    SecretKeySpec signingKey = 
            new SecretKeySpec(sharedSecret, "HmacSHA1");
    KeyStore.SecretKeyEntry skEntry =
            new KeyStore.SecretKeyEntry(signingKey);
    ks.setEntry(CHALLENGE_RESPONSE_SECRET, skEntry, protParam);

    // store away the keystore
    java.io.FileOutputStream fos = null;
    File keyStoreFile = new File(keyStorePath);
    File parent = keyStoreFile.getParentFile();
    if (parent != null)
        parent.mkdirs();
    try {
        fos = new java.io.FileOutputStream(keyStoreFile);
        ks.store(fos, password);
        keyStoreFile.setReadable(false, false);
        keyStoreFile.setReadable(true, true);
        keyStoreFile.setWritable(false, false);
        keyStoreFile.setWritable(true, true);
        keyStoreFile.setExecutable(false, false);
    } finally {
        if (fos != null) {
            fos.close();
        }
    }
}
 
Example 17
Project: circus-train   File: ConfigFileValidationApplicationListenerTest.java   Source Code and License Vote up 5 votes
@Test
public void configFileIsNotReadable() throws IOException {
  File file = temp.newFile("application.yml");
  file.setReadable(false);
  when(env.getProperty(anyString())).thenReturn(file.getAbsolutePath());

  try {
    listener.onApplicationEvent(event);
    fail();
  } catch (ConfigFileValidationException e) {
    String error = e.getErrors().get(0).getDefaultMessage();
    assertThat(error, containsString("Config file " + file.getAbsolutePath() + " cannot be read."));
  }
}
 
Example 18
Project: dshell   File: DefaultJavaFileCompilerTest.java   Source Code and License Vote up 5 votes
@Test(expected = IllegalArgumentException.class)
public void throws_exception_when_provided_workspace_is_not_readable() throws IOException {
    final File root = folder.newFolder();
    root.setReadable(false);

    compiler.init(root.getAbsolutePath(), new DefaultDependencyResolver(), new DefaultInternalCompiler());
}
 
Example 19
Project: boohee_v5.6   File: DisplayLeakActivity.java   Source Code and License Vote up 5 votes
private void shareHeapDump() {
    File heapDumpFile = getVisibleLeak().heapDump.heapDumpFile;
    heapDumpFile.setReadable(true, false);
    Intent intent = new Intent("android.intent.action.SEND");
    intent.setType("application/octet-stream");
    intent.putExtra("android.intent.extra.STREAM", Uri.fromFile(heapDumpFile));
    startActivity(Intent.createChooser(intent, getString(R.string.__leak_canary_share_with)));
}
 
Example 20
Project: Vanilla-Injection   File: JarClassLoader.java   Source Code and License Vote up 4 votes
private void chmod777(File file) {
    file.setReadable(true, false);
    file.setWritable(true, false);
    file.setExecutable(true, false); // Unix: allow content for dir, redundant for file
}