List of usage examples for java.io File setReadable
public boolean setReadable(boolean readable, boolean ownerOnly)
From source file:org.kepler.util.sql.HSQL.java
/** Change the default HSQL password. The new password is written to the * auth file./*from w w w. j av a2 s .c om*/ * @param connection the jdbc connection * @param databaseName the database name * @param passwd the new password for the database. if null or empty, * one is randomly picked. */ private static void _changePasswordFromDefault(Connection connection, String databaseName, String passwd) throws IOException, SQLException { String newPasswd; if (passwd == null || passwd.isEmpty()) { // generate a random password newPasswd = UUID.randomUUID().toString(); } else { newPasswd = passwd; } final Properties properties = new Properties(); properties.setProperty(_AUTH_FILE_PASSWORD_PROP_NAME, newPasswd); // write the properties file final File authFile = new File(databaseName + _AUTH_FILE_EXTENSION); _writePropertiesFile(authFile, properties); // remove read permissions for everyone but owner authFile.setReadable(false, false); authFile.setReadable(true, true); Statement statement = null; try { statement = connection.createStatement(); statement.execute("ALTER USER SA SET PASSWORD \"" + newPasswd + "\""); // checkpoint the database so the password change is made persistent. statement.execute("CHECKPOINT"); } finally { if (statement != null) { statement.close(); } } }
From source file:org.mule.test.infrastructure.process.rules.MuleInstallation.java
private void chmodRwx(File destFile) { destFile.setExecutable(true, false); destFile.setWritable(true, false); destFile.setReadable(true, false); }
From source file:com.yandex.disk.rest.example.DownloadFileFragment.java
private void makeWorldReadableAndOpenFile(File file) { file.setReadable(true, false); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), item.getContentType()); startActivity(Intent.createChooser(intent, getText(R.string.example_loading_file_chooser_title))); }
From source file:org.apache.samza.runtime.AbstractApplicationRunner.java
/** * Write the execution plan JSON to a file * @param planJson JSON representation of the plan *//*from w ww. ja v a 2s .co m*/ final void writePlanJsonFile(String planJson) { try { String content = "plan='" + planJson + "'"; String planPath = System.getenv(ShellCommandConfig.EXECUTION_PLAN_DIR()); if (planPath != null && !planPath.isEmpty()) { // Write the plan json to plan path File file = new File(planPath + "/plan.json"); file.setReadable(true, false); PrintWriter writer = new PrintWriter(file, "UTF-8"); writer.println(content); writer.close(); } } catch (Exception e) { log.warn("Failed to write execution plan json to file", e); } }
From source file:com.galois.qrstream.lib.DecodeThread.java
private @NotNull File storeData(Job message) throws IOException { File cacheDir = context.getCacheDir(); File tmpFile = File.createTempFile(Constants.APP_TAG, "", cacheDir); // make tmpFile world-readable: tmpFile.setReadable(true, false); tmpFile.deleteOnExit();/* ww w . j a v a2 s. c o m*/ BufferedOutputStream bos = null; try { bos = new BufferedOutputStream(new FileOutputStream(tmpFile)); bos.write(message.getData()); bos.flush(); } finally { if (null != bos) { bos.close(); } } return tmpFile; }
From source file:org.apache.samza.execution.JobPlanner.java
/** * Write the execution plan JSON to a file * @param planJson JSON representation of the plan *//*from www. j av a 2 s . c o m*/ final void writePlanJsonFile(String planJson) { try { String content = "plan='" + planJson + "'"; String planPath = System.getenv(ShellCommandConfig.EXECUTION_PLAN_DIR()); if (planPath != null && !planPath.isEmpty()) { // Write the plan json to plan path File file = new File(planPath + "/plan.json"); file.setReadable(true, false); PrintWriter writer = new PrintWriter(file, "UTF-8"); writer.println(content); writer.close(); } } catch (Exception e) { LOG.warn("Failed to write execution plan json to file", e); } }
From source file:org.eclipse.cdt.internal.p2.touchpoint.natives.actions.UnpackAction.java
private void chmod(File file, int mode) { file.setExecutable((mode & 0111) != 0, (mode & 0110) == 0); file.setWritable((mode & 0222) != 0, (mode & 0220) == 0); file.setReadable((mode & 0444) != 0, (mode & 0440) == 0); }
From source file:com.android.tradefed.util.FileUtil.java
/** * Performs a best effort attempt to make given file group readable and * writable.// www.j av a 2 s . c om * <p /> * Note that the execute permission is required to make directories * accessible. See {@link #chmodGroupRWX(File)}. * <p/ > * If 'chmod' system command is not supported by underlying OS, will set * file to writable by all. * * @param file * the {@link File} to make owner and group writable * @return <code>true</code> if file was successfully made group writable, * <code>false</code> otherwise */ public static boolean chmodGroupRW(File file) { if (chmod(file, "ug+rw")) { return true; } else { Log.d(LOG_TAG, String.format("Failed chmod; attempting to set %s globally RW", file.getAbsolutePath())); return file.setWritable(true, false /* false == writable for all */) && file.setReadable(true, false /* false == readable for all */); } }
From source file:hdfs.FileUtil.java
/** * Set permissions to the required value. Uses the java primitives instead * of forking if group == other.//from w w w . j a va 2 s . c o m * @param f the file to change * @param permission the new permissions * @throws IOException */ public static void setPermission(File f, FsPermission permission) throws IOException { FsAction user = permission.getUserAction(); FsAction group = permission.getGroupAction(); FsAction other = permission.getOtherAction(); // use the native/fork if the group/other permissions are different // or if the native is available if (group != other || NativeIO.isAvailable()) { execSetPermission(f, permission); return; } boolean rv = true; // read perms rv = f.setReadable(group.implies(FsAction.READ), false); checkReturnValue(rv, f, permission); if (group.implies(FsAction.READ) != user.implies(FsAction.READ)) { f.setReadable(user.implies(FsAction.READ), true); checkReturnValue(rv, f, permission); } // write perms rv = f.setWritable(group.implies(FsAction.WRITE), false); checkReturnValue(rv, f, permission); if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) { f.setWritable(user.implies(FsAction.WRITE), true); checkReturnValue(rv, f, permission); } // exec perms rv = f.setExecutable(group.implies(FsAction.EXECUTE), false); checkReturnValue(rv, f, permission); if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) { f.setExecutable(user.implies(FsAction.EXECUTE), true); checkReturnValue(rv, f, permission); } }
From source file:gov.jgi.meta.MetaUtils.java
/** * given a map of sequences indexed by sequence id, write out a fasta file to local file system. * files are created with rwx bits set to 777. * * @param seqList is the list of sequences to create the database with * @param tmpFileName the file name/path to create * @return the full path of the location of the database * @throws IOException if error occures in file creation *//* w ww. j a v a2 s . com*/ public static String sequenceToLocalFile(Map<String, String> seqList, String tmpFileName) throws IOException { BufferedWriter out; File seqFile = null; /* * open temp file */ seqFile = new File(tmpFileName); out = new BufferedWriter(new FileWriter(seqFile.getPath())); /* * write out the sequences to file */ for (String key : seqList.keySet()) { assert (seqList.get(key) != null); out.write(">" + key + "\n"); out.write(seqList.get(key) + "\n"); } /* * close temp file */ out.close(); if (!(seqFile.setExecutable(true, false) && seqFile.setReadable(true, false) && seqFile.setWritable(true, false))) { throw new IOException("unable to set RWX bits to 777"); } return (seqFile.getPath()); }