Example usage for java.io File setWritable

List of usage examples for java.io File setWritable

Introduction

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

Prototype

public boolean setWritable(boolean writable) 

Source Link

Document

A convenience method to set the owner's write permission for this abstract pathname.

Usage

From source file:com.blockwithme.longdb.leveldb.Util.java

/** Force drop. */
public static void forceDrop(final File theFile) {
    if (!theFile.isDirectory()) {
        try {//from  w w  w .j  a v a 2s  .  c om
            theFile.setWritable(true);
            FileUtils.forceDelete(theFile);
        } catch (final IOException e) {
            LOG.warn("exception ignored - forceDrop(File f=" + theFile + ")");
            // ignore.
        }
    } else {
        final File[] files = theFile.listFiles();
        for (final File file : files) {
            forceDrop(file);
        }
    }
}

From source file:org.metaeffekt.dcc.commons.DccUtils.java

public static void prepareFoldersForWriting(File... folders) {
    for (File file : folders) {
        if (!file.exists()) {
            file.mkdirs();//www.ja  v  a 2s.  c  o m
            file.setWritable(true);
            file.setExecutable(true);
        } else if (!file.isDirectory()) {
            throw new IllegalStateException(String.format(
                    "Cannot create directory [%s] because a file with the same name already exists!", file));
        } else if (!file.canWrite()) {
            file.setWritable(true);
            if (!file.canWrite()) {
                throw new IllegalStateException(String.format("[%s] is not writable!", file));
            }
        }
    }
}

From source file:org.silverpeas.security.web.CipherKeyResourceTest.java

@AfterClass
public static void deleteSecurityDirectory() throws IOException {
    String securityPath = FileRepositoryManager.getSecurityDirPath();
    File securityDir = new File(securityPath);
    if (securityDir.exists()) {
        File keyFile = new File(ACTUAL_KEY_FILE_PATH);
        if (keyFile.exists()) {
            keyFile.setWritable(true);
            FileUtils.forceDelete(keyFile);
        }// ww  w  . j av a2 s  . co m
        keyFile = new File(OLD_KEY_FILE_PATH);
        if (keyFile.exists()) {
            keyFile.setWritable(true);
            FileUtils.forceDelete(keyFile);
        }
        FileUtils.forceDelete(securityDir);
    }
}

From source file:se.dibbler.backend.generics.DibblerImageUtil.java

private static void setFileAccess(File imgOutFile, FileAccess access) {
    switch (access) {
    case READONLY:
        imgOutFile.setReadable(true);//from  w  w w  . j av  a  2 s  .c o  m
        imgOutFile.setWritable(false);
        imgOutFile.setExecutable(false);
        break;
    case EXECUTEONLY:
        imgOutFile.setReadable(false);
        imgOutFile.setWritable(false);
        imgOutFile.setExecutable(true);
        break;
    case WRITEONLY:
        imgOutFile.setReadable(false);
        imgOutFile.setWritable(true);
        imgOutFile.setExecutable(false);
        break;
    case READ_AND_EXECUTE:
        imgOutFile.setReadable(true);
        imgOutFile.setWritable(false);
        imgOutFile.setExecutable(true);
        break;
    case WRITE_AND_EXECUTE:
        imgOutFile.setReadable(false);
        imgOutFile.setWritable(true);
        imgOutFile.setExecutable(true);
        break;
    case READ_AND_WRITE:
        imgOutFile.setReadable(true);
        imgOutFile.setWritable(true);
        imgOutFile.setExecutable(false);
        break;
    default:
        LOG.error("[ Wrong file access type or not implemented in method ]");
    }
}

From source file:org.silverpeas.security.web.CipherKeyResourceTest.java

@BeforeClass
public static void createSecurityDirectoryAndSetupJCEProviders() throws IOException {
    String securityPath = FileRepositoryManager.getSecurityDirPath();
    File securityDir = new File(securityPath);
    if (!securityDir.exists()) {
        FileUtils.forceMkdir(securityDir);
    }//from   w w w.jav  a  2  s. co  m
    securityDir.setWritable(true);
    securityDir.setExecutable(true);
    securityDir.setReadable(true);
    if (System.getProperty("os.name").toLowerCase().contains("windows")) {
        Runtime.getRuntime().exec("attrib +H " + securityPath);
    }

    Security.addProvider(new BouncyCastleProvider());
}

From source file:org.benetech.secureapp.generator.Fdroid.java

static public void copyApkToFDroid(HttpSession session, File apkCreated) throws Exception {
    try {/*  w w w  . j av a 2s  .  c o  m*/
        long startTime = System.currentTimeMillis();
        File baseDir = setupTempFDroidRepo(session);
        File repoDir = new File(baseDir, FDROID_REPO_DIR);
        File destination = new File(repoDir, apkCreated.getName());
        SagLogger.logInfo(session, "Copy to FDroid Repo: " + destination.getAbsolutePath());
        FileUtils.copyFile(apkCreated, destination);
        destination.setExecutable(true);
        destination.setWritable(true);

        String fDroidCommand = getFDroidCommand("--version");
        SecureAppGeneratorApplication.executeCommand(session, fDroidCommand, baseDir);

        fDroidCommand = getFDroidCommand("update --create-metadata -v");
        SecureAppGeneratorApplication.executeCommand(session, fDroidCommand, baseDir);

        fDroidCommand = getFDroidCommand("server update -v");
        SecureAppGeneratorApplication.executeCommand(session, fDroidCommand, baseDir);
        long endTime = System.currentTimeMillis();
        String timeToBuild = SagLogger.getElapsedTime(startTime, endTime);
        SagLogger.logInfo(session, "Fdroid Build took" + timeToBuild);
    } finally {
        //      try
        {
            //         TODO: add this back once tested on server.         
            //         if(baseDir != null)
            //            FileUtils.deleteDirectory(baseDir);
        }
        //      catch (IOException e)
        {
            //         Logger.logException(e);         
        }
    }
}

From source file:org.datavec.api.records.writer.impl.LibSvmRecordWriterTest.java

public static void executeTest(Configuration configWriter, Configuration configReader, File inputFile)
        throws Exception {
    File tempFile = File.createTempFile("LibSvmRecordWriter", ".txt");
    tempFile.setWritable(true);
    tempFile.deleteOnExit();/*w  w  w.  ja  v a 2s .  c o  m*/
    if (tempFile.exists())
        tempFile.delete();

    try (LibSvmRecordWriter writer = new LibSvmRecordWriter()) {
        FileSplit outputSplit = new FileSplit(tempFile);
        writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner());
        LibSvmRecordReader rr = new LibSvmRecordReader();
        rr.initialize(configReader, new FileSplit(inputFile));
        while (rr.hasNext()) {
            List<Writable> record = rr.next();
            writer.write(record);
        }
    }

    Pattern p = Pattern.compile(String.format("%s:\\d+ ", LibSvmRecordReader.QID_PREFIX));
    List<String> linesOriginal = new ArrayList<>();
    for (String line : FileUtils.readLines(inputFile)) {
        if (!line.startsWith(LibSvmRecordReader.COMMENT_CHAR)) {
            String lineClean = line.split(LibSvmRecordReader.COMMENT_CHAR, 2)[0];
            if (lineClean.startsWith(" ")) {
                lineClean = " " + lineClean.trim();
            } else {
                lineClean = lineClean.trim();
            }
            Matcher m = p.matcher(lineClean);
            lineClean = m.replaceAll("");
            linesOriginal.add(lineClean);
        }
    }
    List<String> linesNew = FileUtils.readLines(tempFile);
    assertEquals(linesOriginal, linesNew);
}

From source file:org.datavec.api.records.writer.impl.SVMLightRecordWriterTest.java

public static void executeTest(Configuration configWriter, Configuration configReader, File inputFile)
        throws Exception {
    File tempFile = File.createTempFile("SVMLightRecordWriter", ".txt");
    tempFile.setWritable(true);
    tempFile.deleteOnExit();//from w ww. j  a  v  a  2s .co m
    if (tempFile.exists())
        tempFile.delete();

    try (SVMLightRecordWriter writer = new SVMLightRecordWriter()) {
        FileSplit outputSplit = new FileSplit(tempFile);
        writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner());
        SVMLightRecordReader rr = new SVMLightRecordReader();
        rr.initialize(configReader, new FileSplit(inputFile));
        while (rr.hasNext()) {
            List<Writable> record = rr.next();
            writer.write(record);
        }
    }

    Pattern p = Pattern.compile(String.format("%s:\\d+ ", SVMLightRecordReader.QID_PREFIX));
    List<String> linesOriginal = new ArrayList<>();
    for (String line : FileUtils.readLines(inputFile)) {
        if (!line.startsWith(SVMLightRecordReader.COMMENT_CHAR)) {
            String lineClean = line.split(SVMLightRecordReader.COMMENT_CHAR, 2)[0];
            if (lineClean.startsWith(" ")) {
                lineClean = " " + lineClean.trim();
            } else {
                lineClean = lineClean.trim();
            }
            Matcher m = p.matcher(lineClean);
            lineClean = m.replaceAll("");
            linesOriginal.add(lineClean);
        }
    }
    List<String> linesNew = FileUtils.readLines(tempFile);
    assertEquals(linesOriginal, linesNew);
}

From source file:org.kuali.rice.krad.theme.ThemeBuilderOverlays.java

/**
 * Invoked at the beginning of the build process to move assets from the web source directory to the
 * output directory, where they can be further processed
 *
 * <p>//from  ww  w.j  a v  a2  s  .c  o m
 * Note: Not all web resources are copied, just the assets that are needed to build all themes. This includes
 * all the theme directories, plugin directories, and KRAD scripts directory
 * </p>
 *
 * @param webappSourceDir absolute path to the web source directory
 * @param themeBuilderOutputDir absolute path to the target directory, where assets will be copied
 * to and processed. If the directory does not exist it will be created
 * @param additionalThemeDirectories list of additional theme paths that should be copied to
 * the output directory
 * @param additionalPluginDirectories list of additional plugin paths that should be copied to
 * the output directory
 * @throws IOException
 */
protected static void copyAssetsToWorkingDir(String webappSourceDir, String themeBuilderOutputDir,
        List<String> additionalThemeDirectories, List<String> additionalPluginDirectories) throws IOException {
    Assert.hasText(themeBuilderOutputDir, "Working directory for theme builder not set");

    File webappSource = new File(webappSourceDir);
    if (!webappSource.exists()) {
        throw new RuntimeException("Webapp source directory does not exist");
    }

    File workingDir = new File(themeBuilderOutputDir);
    if (!workingDir.exists()) {
        workingDir.mkdir();
    }

    workingDir.setWritable(true);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Copying script, theme, plugin resource to working dir: " + themeBuilderOutputDir);
    }

    ThemeBuilderUtils.copyDirectory(webappSourceDir + ThemeBuilderConstants.KRAD_SCRIPTS_DIRECTORY,
            themeBuilderOutputDir + ThemeBuilderConstants.KRAD_SCRIPTS_DIRECTORY);

    ThemeBuilderUtils.copyDirectory(webappSourceDir + ThemeBuilderConstants.DEFAULT_THEMES_DIRECTORY,
            themeBuilderOutputDir + ThemeBuilderConstants.DEFAULT_THEMES_DIRECTORY);

    if (additionalThemeDirectories != null) {
        for (String additionalThemeDirectory : additionalThemeDirectories) {
            ThemeBuilderUtils.copyDirectory(webappSourceDir + additionalThemeDirectory,
                    themeBuilderOutputDir + additionalThemeDirectory);
        }
    }

    ThemeBuilderUtils.copyDirectory(webappSourceDir + ThemeBuilderConstants.DEFAULT_PLUGINS_DIRECTORY,
            themeBuilderOutputDir + ThemeBuilderConstants.DEFAULT_PLUGINS_DIRECTORY);

    if (additionalPluginDirectories != null) {
        for (String additionalPluginDirectory : additionalPluginDirectories) {
            ThemeBuilderUtils.copyDirectory(webappSourceDir + additionalPluginDirectory,
                    themeBuilderOutputDir + additionalPluginDirectory);
        }
    }
}

From source file:juicebox.data.HiCFileTools.java

/**
 * @param fileName/*w  ww  .  j a v a  2  s.c  o  m*/
 * @return
 */
public static PrintWriter openWriter(String fileName) {
    try {
        File file = new File(fileName);
        file.createNewFile();
        file.setWritable(true);
        return new PrintWriter(new BufferedWriter(new FileWriter(file)), true);
    } catch (IOException e) {
        System.out.println("I/O error opening file: " + fileName);
        System.exit(0);
    }
    return null;
}