Example usage for java.io File setReadOnly

List of usage examples for java.io File setReadOnly

Introduction

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

Prototype

public boolean setReadOnly() 

Source Link

Document

Marks the file or directory named by this abstract pathname so that only read operations are allowed.

Usage

From source file:net.refractions.udig.document.source.ShpDocUtils.java

/**
 * Copies a read-only copy of the old file into new file directory.
 * //from   w ww .  j  a va 2  s.com
 * @param oldFile
 * @param newFileDir
 * @return new file
 */
public static File copyFile(File oldFile, File newFileDir) {
    try {
        if (!newFileDir.exists()) {
            newFileDir.mkdir();
        }
        final File newFile = new File(newFileDir, oldFile.getName());
        if (!newFile.exists()) {
            FileUtils.copyFileToDirectory(oldFile, newFileDir);
            newFile.setReadOnly();
        }
        return newFile;
    } catch (IOException e) {
        // Should not happen
        e.printStackTrace();
    }
    return null;
}

From source file:com.pieframework.runtime.utils.Zipper.java

private void gatherFiles(File folder, List<File> list) {
    folder.setReadOnly();
    File[] files = folder.listFiles();
    for (int j = 0; j < files.length; j++) {
        if (files[j].isDirectory()) {
            gatherFiles(files[j], list);
        } else {//from  w  w  w  .j  av  a2  s .c om
            list.add(files[j]);
        }
    }
}

From source file:com.CodeSeance.JSeance2.CodeGenXML.XMLElements.Test.OutputTest.java

@Test
public void fileOutputTest_TargetFileReadonly() {
    File outputFile = createOutputFile("FILE");
    boolean result = outputFile.setReadOnly();
    assert result;

    template.append("!Output(\"{FILE}\")!");
    template.append("Test");
    template.append("!End!");

    expectResult("", true, true);
}

From source file:com.CodeSeance.JSeance2.CodeGenXML.XMLElements.Test.OutputTest.java

@Test
public void fileOutputTest_TargetFileReadonlyFail() {
    File outputFile = createOutputFile("FILE");
    boolean result = outputFile.setReadOnly();
    assert result;

    template.append("!Output(\"{FILE}\")!");
    template.append("Test");
    template.append("!End!");

    expectError(ExecutionError.TARGET_FILE_READONLY, true, true, true, false, outputFile.getName(), false);
}

From source file:io.druid.query.lookup.LookupSnapshotTakerTest.java

@Test(expected = ISE.class)
public void testIOExceptionDuringLookupPersist() throws IOException {
    File directory = temporaryFolder.newFolder();
    File snapshotFile = new File(directory, LookupSnapshotTaker.PERSIST_FILE_NAME);
    Assert.assertFalse(snapshotFile.exists());
    Assert.assertTrue(snapshotFile.createNewFile());
    Assert.assertTrue(snapshotFile.setReadOnly());
    LookupSnapshotTaker lookupSnapshotTaker = new LookupSnapshotTaker(mapper, directory.getAbsolutePath());
    LookupBean lookupBean = new LookupBean("name", null, new LookupExtractorFactoryContainer("v1",
            new MapLookupExtractorFactory(ImmutableMap.of("key", "value"), true)));
    List<LookupBean> lookupBeanList = Lists.newArrayList(lookupBean);
    lookupSnapshotTaker.takeSnapshot(lookupBeanList);
}

From source file:com.thoughtworks.go.server.service.support.toggle.FeatureToggleRepositoryTest.java

@Test
public void shouldFailWhenUnableToWriteToUserTogglesFile_DuringChangingOfAToggleValue() throws Exception {
    setupAvailableToggles(new FeatureToggle("key1", "desc1", true));

    File userTogglesFile = setupUserToggles(new FeatureToggle("key1", "desc1", true));
    userTogglesFile.setReadOnly();

    FeatureToggleRepository repository = new FeatureToggleRepository(environment);

    try {/*from   w  ww .  j  a  v a 2 s .  c om*/
        repository.changeValueOfToggle("key1", false);
        fail("Should have failed to write");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString(userTogglesFile.getPath()));
    }
}

From source file:com.ssn.ws.rest.service.LoginWithInstagram.java

private void storeAccessToken(AccessGrant accessGrant) {
    try {//from w w  w.  ja  va 2 s  .  co m
        String rootPath = SSNHelper.getSsnWorkSpaceDirPath();
        String RememberMePath = rootPath + File.separator + SSNConstants.SSN_REMMEBER_ME_DIRECTORY;
        File file = new File(RememberMePath);

        if (!file.exists()) {
            file.mkdir();
        }

        String serializationFilePath = RememberMePath + File.separator + SSNConstants.SSN_INSTAGRAM_TOKEN
                + ".ser";
        File serializationFile = new File(serializationFilePath);
        serializationFile.setReadOnly();
        FileOutputStream fout = new FileOutputStream(serializationFile);
        ObjectOutputStream oos = new ObjectOutputStream(fout);

        oos.writeObject(accessGrant);
        oos.close();
        fout.close();
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }
}

From source file:com.saptarshidebnath.lib.processrunner.process.RunnerFactoryTest.java

@Test(expected = ProcessConfigurationException.class)
public void startProcessWithProcessConfigWithWrongParams()
        throws IOException, ProcessConfigurationException, InterruptedException, ExecutionException {
    final File tempFile = File.createTempFile(ProcessRunnerConstants.FILE_PREFIX_NAME_LOG_DUMP,
            ProcessRunnerConstants.FILE_SUFFIX_JSON);
    if (!tempFile.setReadOnly()) {
        throw new RuntimeException("Unable to set file : " + tempFile.getAbsolutePath() + " as readonly.");
    }/*from  ww  w. j  av a2s  .c o  m*/
    tempFile.deleteOnExit();

    RunnerFactory.startProcess(new ConfigBuilder(getDefaultInterpreter(), getInterPreterVersion())
            .setWorkigDir(ProcessRunnerConstants.DEFAULT_CURRENT_DIR_PATH).setMasterLogFile(tempFile, true)
            .build());
}

From source file:com.saptarshidebnath.lib.processrunner.process.RunnerFactoryTest.java

@Test(expected = ProcessConfigurationException.class)
public void startThreadedProcessWithProcessConfigWithWrongParams()
        throws IOException, ProcessConfigurationException {
    final File tempFile = File.createTempFile(ProcessRunnerConstants.FILE_PREFIX_NAME_LOG_DUMP,
            ProcessRunnerConstants.FILE_SUFFIX_JSON);
    if (!tempFile.setReadOnly()) {
        throw new RuntimeException("Unable to set file : " + tempFile.getAbsolutePath() + " as readonly.");
    }//from  w w  w. j  a v  a2  s . c  o  m
    tempFile.deleteOnExit();

    RunnerFactory.startAsyncProcess(new ConfigBuilder(getDefaultInterpreter(), getInterPreterVersion())
            .setWorkigDir(ProcessRunnerConstants.DEFAULT_CURRENT_DIR_PATH).setMasterLogFile(tempFile, true)
            .build());
}

From source file:com.saptarshidebnath.lib.processrunner.process.RunnerFactoryTest.java

@Test(expected = IOException.class)
public void validateUtilitiesClassWriteLogHandlesFileExceptionProperlyOrNot() throws IOException,
        ProcessException, InterruptedException, ProcessConfigurationException, ExecutionException {
    final Runner runner = RunnerFactory
            .getRunner(new ConfigBuilder(getDefaultInterpreter(), getInterPreterVersion())
                    .setWorkigDir(ProcessRunnerConstants.DEFAULT_CURRENT_DIR_PATH)
                    .setMasterLogFile(new TempFile().createTempLogDump(), true).build());
    final Output response = runner.run();
    final File sysout = response
            .saveSysOut(File.createTempFile(ProcessRunnerConstants.FILE_PREFIX_NAME_LOG_DUMP + "-sysout",
                    ProcessRunnerConstants.FILE_SUFFIX_JSON));
    sysout.deleteOnExit();//from ww  w . j  a  v a  2s.  c om
    assertThat("Validating if sysout file is set as readonly or not", sysout.setReadOnly(), is(true));
    response.saveSysOut(sysout);
}