Example usage for java.io File setReadable

List of usage examples for java.io File setReadable

Introduction

In this page you can find the example usage for java.io File setReadable.

Prototype

public boolean setReadable(boolean readable, boolean ownerOnly) 

Source Link

Document

Sets the owner's or everybody's read permission for this abstract pathname.

Usage

From source file:com.linkedin.gradle.python.util.entrypoint.EntryPointWriter.java

public void writeEntryPoint(File location, Map<String, String> properties)
        throws IOException, ClassNotFoundException {
    if (location.exists()) {
        location.delete();/*from   ww  w  . ja v a2  s.  c  o  m*/
    }

    location.createNewFile();

    if (isCliTool) {
        location.setExecutable(true, false);
        location.setReadable(true, false);
    } else {
        location.setExecutable(true);
    }

    SimpleTemplateEngine simpleTemplateEngine = new SimpleTemplateEngine();
    String rendered = simpleTemplateEngine.createTemplate(template).make(properties).toString();
    FileUtils.write(location, rendered);
}

From source file:com.opengamma.maven.scripts.ScriptableScriptGeneratorMojo.java

@SuppressWarnings("unchecked")
@Override/*from w ww . j  av  a2 s . c  om*/
public void execute() throws MojoExecutionException, MojoFailureException {
    boolean templateSet = !StringUtils.isBlank(_template);
    boolean templateMapSet = _baseClassTemplateMap != null && _baseClassTemplateMap.isEmpty();
    if ((templateSet && templateMapSet) || (!templateSet && !templateMapSet)) {
        throw new MojoExecutionException("Exactly one of 'template' or 'baseClassTemplateMap' must be set");
    }
    if (!_outputDir.exists()) {
        try {
            getLog().debug("Creating output directory " + _outputDir);
            if (!_outputDir.mkdirs()) {
                throw new MojoExecutionException(
                        "Unable to create output directory " + _outputDir.getAbsolutePath());
            }
        } catch (Exception e) {
            throw new MojoExecutionException("Error creating output directory " + _outputDir.getAbsolutePath());
        }
    }

    List<String> classpathElementList;
    try {
        classpathElementList = _project.getCompileClasspathElements();
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("Error obtaining dependencies", e);
    }
    URL[] classpathUrls = ClasspathUtils.getClasspathURLs(classpathElementList);
    Set<String> annotationClasses = ClassNameAnnotationScanner.scan(classpathUrls, Scriptable.class.getName());
    getLog().info("Generating " + annotationClasses.size() + " scripts");

    ClassLoader classLoader = new URLClassLoader(classpathUrls, this.getClass().getClassLoader());
    Map<Class<?>, Template> templateMap = resolveTemplateMap(classLoader);

    for (String className : annotationClasses) {
        Map<String, Object> templateData = new HashMap<String, Object>();
        templateData.put("className", className);
        Template template = getTemplateForClass(className, classLoader, templateMap);
        if (template == null) {
            getLog().warn("No template for scriptable class " + className);
            continue;
        }
        ScriptsGenerator.generate(className, _outputDir, template, templateData);
    }

    if (_additionalScripts != null) {
        getLog().info("Copying " + _additionalScripts.length + " additional script(s)");
        for (String script : _additionalScripts) {
            File scriptFile = new File(script);
            if (scriptFile.exists()) {
                if (!scriptFile.isFile()) {
                    throw new MojoExecutionException(
                            "Can only copy files, but additional script '" + scriptFile + "' is not a file");
                }
                try {
                    FileUtils.copyFileToDirectory(scriptFile, _outputDir);
                    File copiedFile = new File(_outputDir, scriptFile.getName());
                    copiedFile.setReadable(true, false);
                    copiedFile.setExecutable(true, false);
                } catch (IOException e) {
                    throw new MojoExecutionException("Unable to copy additional script '" + scriptFile + "'",
                            e);
                }
            }
        }
    }
}

From source file:io.sloeber.core.managers.InternalPackageManager.java

private static void chmod(File file, int mode) throws IOException, InterruptedException {
    String octal = Integer.toOctalString(mode);
    if (Platform.getOS().equals(Platform.OS_WIN32)) {
        boolean ownerExecute = (((mode / (8 * 8)) & 1) == 1);
        boolean ownerRead = (((mode / (8 * 8)) & 4) == 4);
        boolean ownerWrite = (((mode / (8 * 8)) & 2) == 2);
        boolean everyoneExecute = (((mode / 8) & 1) == 1);
        boolean everyoneRead = (((mode / 8) & 4) == 4);
        boolean everyoneWrite = (((mode / 8) & 2) == 2);
        file.setWritable(true, false);// w  ww .  ja  v a2s.  co m
        file.setExecutable(ownerExecute, !everyoneExecute);
        file.setReadable(ownerRead, !everyoneRead);
        file.setWritable(ownerWrite, !everyoneWrite);
    } else {
        Process process = Runtime.getRuntime().exec(new String[] { "chmod", octal, file.getAbsolutePath() }, //$NON-NLS-1$
                null, null);
        process.waitFor();
    }
}

From source file:com.papteco.client.netty.SelProjectClientHandler.java

private void prepareLocalFolders(ProjectBean project) {
    File projectFolder = new File(EnvConstant.LCL_STORING_PATH, project.getProjectCde());
    if (!projectFolder.exists()) {
        projectFolder.mkdirs();//from   w ww. ja  v  a2  s .c o m
        projectFolder.setExecutable(true, false);
        projectFolder.setReadable(true, false);
        projectFolder.setWritable(true, false);
        // logger.info("Folder \"" + projectFolder.getName()
        // + "\" created!");
    } else {
        // logger.info("Folder \"" + projectFolder.getName()
        // + "\" existing already!");
    }

    for (FolderBean folder : project.getFolderTree()) {
        File sf = new File(projectFolder.getPath(), folder.getFolderName());
        if (!sf.exists()) {
            sf.mkdirs();
            sf.setExecutable(true, false);
            sf.setReadable(true, false);
            sf.setWritable(true, false);
            // logger.info("(execable, readable, writeable) - ("
            // + sf.canExecute() + ", " + sf.canRead() + ", "
            // + sf.canWrite() + ") - " + projectFolder.getPath()
            // + "/" + folder.getFolderName());
        } else {
            // logger.info("(execable, readable, writeable) - ("
            // + sf.canExecute() + ", " + sf.canRead() + ", "
            // + sf.canWrite() + ") - " + projectFolder.getPath()
            // + "/" + folder.getFolderName() + " [existing already]");
        }
    }
    logger.info("Folders creation finish.");
}

From source file:org.slc.sli.ingestion.tenant.TenantPopulator.java

/**
 *
 * Create the landing zone directory for the parent landing zone
 *
 *///from w w w .  j a v a 2  s . c  o  m
private void createParentLzDirectory() {
    String lzPath = Matcher.quoteReplacement(parentLandingZoneDir);
    File lzDirectory = new File(lzPath);
    if (!lzDirectory.mkdir()) {
        LOG.debug("Failed to mkdir: {}", lzDirectory.getPath());
    }
    if (!lzDirectory.setReadable(true, false)) {
        LOG.debug("Failed to setReadable: {}", lzDirectory.getPath());
    }
    if (!lzDirectory.setWritable(true, false)) {
        LOG.debug("Failed to setWritable: {}", lzDirectory.getPath());
    }
}

From source file:com.android.tradefed.util.FileUtil.java

public static boolean chmodRWXRecursively(File file) {
    boolean success = true;
    if (!file.setExecutable(true, false)) {
        CLog.w("Failed to set %s executable.", file.getAbsolutePath());
        success = false;//ww  w . jav a2  s .c  o m
    }
    if (!file.setWritable(true, false)) {
        CLog.w("Failed to set %s writable.", file.getAbsolutePath());
        success = false;
    }
    if (!file.setReadable(true, false)) {
        CLog.w("Failed to set %s readable", file.getAbsolutePath());
        success = false;
    }

    if (file.isDirectory()) {
        File[] childs = file.listFiles();
        for (File child : childs) {
            if (!chmodRWXRecursively(child)) {
                success = false;
            }
        }

    }
    return success;
}

From source file:org.slc.sli.ingestion.tenant.TenantPopulator.java

/**
 *
 * Create the landing zone directory for a tenant.
 *
 * @param tenant//from www. j  a  va 2  s  . c  om
 *            , the tenant for which to create landing zone directories
 *
 */
private void createTenantLzDirectory(TenantRecord tenant) {
    List<LandingZoneRecord> landingZones = tenant.getLandingZone();
    for (LandingZoneRecord lz : landingZones) {
        String lzPath = lz.getPath();
        File lzDirectory = new File(lzPath);
        if (!lzDirectory.mkdir()) {
            LOG.debug("Failed to mkdir: {}", lzDirectory.getPath());
        }
        if (!lzDirectory.setReadable(true, false)) {
            LOG.debug("Failed to setReadable: {}", lzDirectory.getPath());
        }
        if (!lzDirectory.setWritable(true, false)) {
            LOG.debug("Failed to setWritable: {}", lzDirectory.getPath());
        }
    }
}

From source file:org.apache.hadoop.io.crypto.tool.BeeCli.java

private void credentailsFileWriter(Credentials credentials, String path) throws Exception {
    DataOutputStream dos = new DataOutputStream(new FileOutputStream(path));
    credentials.writeTokenStorageToStream(dos);
    File f = new File(path);
    f.setExecutable(false, false);// www .j  ava 2  s  . c  o  m
    f.setReadable(true, true);
    f.setWritable(true, true);
}

From source file:com.android.tradefed.util.FileUtil.java

/**
 * Performs a best effort attempt to make given file group executable,
 * readable, and writable./*from ww w .  j a v a2s  .  co  m*/
 * <p/ >
 * If 'chmod' system command is not supported by underlying OS, will attempt
 * to set permissions for all users.
 *
 * @param file
 *            the {@link File} to make owner and group writable
 * @return <code>true</code> if permissions were set successfully,
 *         <code>false</code> otherwise
 */
public static boolean chmodGroupRWX(File file) {
    if (chmod(file, "ug+rwx")) {
        return true;
    } else {
        Log.d(LOG_TAG,
                String.format("Failed chmod; attempting to set %s globally RWX", file.getAbsolutePath()));
        return file.setExecutable(true, false /* false == executable for all */)
                && file.setWritable(true, false /* false == writable for all */)
                && file.setReadable(true, false /* false == readable for all */);
    }
}

From source file:com.wuba.utils.FileUtil.java

public static boolean chmodRWXRecursively(File file) {
    boolean success = true;
    if (!file.setExecutable(true, false)) {
        LOG.warn(String.format("Failed to set %s executable.", file.getAbsolutePath()));
        success = false;//  w w  w  .j a  v  a  2 s  .c om
    }
    if (!file.setWritable(true, false)) {
        LOG.warn(String.format("Failed to set %s writable.", file.getAbsolutePath()));
        success = false;
    }
    if (!file.setReadable(true, false)) {
        LOG.warn(String.format("Failed to set %s readable", file.getAbsolutePath()));
        success = false;
    }

    if (file.isDirectory()) {
        File[] childs = file.listFiles();
        for (File child : childs) {
            if (!chmodRWXRecursively(child)) {
                success = false;
            }
        }

    }
    return success;
}