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:org.silverpeas.core.security.encryption.ContentEncryptionServiceTest.java

private void createSecurityDirectoryAndSetupJCEProviders() throws IOException {
    ACTUAL_KEY_FILE_PATH = FileRepositoryManager.getSecurityDirPath() + ".aid_key";
    DEPRECATED_KEY_FILE_PATH = FileRepositoryManager.getSecurityDirPath() + ".did_key";
    try {//from  w  ww.  jav  a 2s. c  om
        CIPHER_KEY = CipherKey.aKeyFromHexText("06277d1ce530c94bd9a13a72a58342be");
    } catch (ParseException e) {
        throw new RuntimeException("Cannot create the cryptographic key!", e);
    }

    String securityPath = FileRepositoryManager.getSecurityDirPath();
    File securityDir = new File(securityPath);
    if (!securityDir.exists()) {
        FileUtils.forceMkdir(securityDir);
    }
    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:net.orpiske.sdm.lib.io.support.ShieldAwareCopier.java

@Override
protected void handleFile(File file, int depth, Collection results) throws IOException {
    File destinationFile = new File(destination, file.getName());

    if (!ShieldUtils.isShielded(destinationFile)) {
        FileUtils.copyFile(file, destinationFile);

        destinationFile.setExecutable(file.canExecute());
        destinationFile.setReadable(file.canRead());
        destinationFile.setWritable(file.canWrite());
    } else {/*from  w  w  w  . ja v a2 s.c  o m*/
        System.out.println("Ignoring shielded file " + file.getPath());
    }
}

From source file:io.druid.indexing.common.tasklogs.FileTaskLogsTest.java

@Test
public void testPushTaskLogDirCreationFails() throws Exception {
    final File tmpDir = temporaryFolder.newFolder();

    try {//from   w  ww  .  jav a  2 s . co m
        IOException thrown = null;

        final File logDir = new File(tmpDir, "druid/logs");
        final File logFile = new File(tmpDir, "log");
        Files.write("blah", logFile, Charsets.UTF_8);

        if (!tmpDir.setWritable(false)) {
            new RuntimeException("failed to make tmp dir read-only");
        }

        final TaskLogs taskLogs = new FileTaskLogs(new FileTaskLogsConfig(logDir));
        try {
            taskLogs.pushTaskLog("foo", logFile);
        } catch (IOException ex) {
            thrown = ex;
        }
        Assert.assertNotNull("pushTaskLog should fail with exception of dir creation error", thrown);
    } finally {
        tmpDir.setWritable(true);
        FileUtils.deleteDirectory(tmpDir);
    }
}

From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java

@After
public void tearDown() throws Exception {
    Collection<File> aFilesToDelete = FileUtils.listFiles(new File("target"),
            new WildcardFileFilter("Z*-input*.zip"), null);
    for (File aFile : aFilesToDelete) {
        aFile.setWritable(true);
        FileUtils.deleteQuietly(aFile);/*from www.  j a va  2s. c om*/
    }
    FileUtils.deleteDirectory(new File("target/Z-testfiles"));
}

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

@Test
public void testNonIntegerButValidMultilabel() throws Exception {
    List<Writable> record = Arrays.asList((Writable) new IntWritable(3), new IntWritable(2),
            new DoubleWritable(1.0));
    File tempFile = File.createTempFile("LibSvmRecordWriter", ".txt");
    tempFile.setWritable(true);
    tempFile.deleteOnExit();/*from  w  w w. j  a va  2 s.  c  o  m*/
    if (tempFile.exists())
        tempFile.delete();

    try (LibSvmRecordWriter writer = new LibSvmRecordWriter()) {
        Configuration configWriter = new Configuration();
        configWriter.setInt(LibSvmRecordWriter.FEATURE_FIRST_COLUMN, 0);
        configWriter.setInt(LibSvmRecordWriter.FEATURE_LAST_COLUMN, 1);
        configWriter.setBoolean(LibSvmRecordWriter.MULTILABEL, true);
        FileSplit outputSplit = new FileSplit(tempFile);
        writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner());
        writer.write(record);
    }
}

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

@Test(expected = NumberFormatException.class)
public void nonIntegerMultilabel() throws Exception {
    List<Writable> record = Arrays.asList((Writable) new IntWritable(3), new IntWritable(2),
            new DoubleWritable(1.2));
    File tempFile = File.createTempFile("LibSvmRecordWriter", ".txt");
    tempFile.setWritable(true);
    tempFile.deleteOnExit();//  w w w .j  a v a 2  s.c  om
    if (tempFile.exists())
        tempFile.delete();

    try (LibSvmRecordWriter writer = new LibSvmRecordWriter()) {
        Configuration configWriter = new Configuration();
        configWriter.setInt(LibSvmRecordWriter.FEATURE_FIRST_COLUMN, 0);
        configWriter.setInt(LibSvmRecordWriter.FEATURE_LAST_COLUMN, 1);
        configWriter.setBoolean(LibSvmRecordWriter.MULTILABEL, true);
        FileSplit outputSplit = new FileSplit(tempFile);
        writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner());
        writer.write(record);
    }
}

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

@Test(expected = NumberFormatException.class)
public void nonBinaryMultilabel() throws Exception {
    List<Writable> record = Arrays.asList((Writable) new IntWritable(0), new IntWritable(1),
            new IntWritable(2));
    File tempFile = File.createTempFile("LibSvmRecordWriter", ".txt");
    tempFile.setWritable(true);
    tempFile.deleteOnExit();//from w ww  .  j  a v a  2 s  .  c o  m
    if (tempFile.exists())
        tempFile.delete();

    try (LibSvmRecordWriter writer = new LibSvmRecordWriter()) {
        Configuration configWriter = new Configuration();
        configWriter.setInt(LibSvmRecordWriter.FEATURE_FIRST_COLUMN, 0);
        configWriter.setInt(LibSvmRecordWriter.FEATURE_LAST_COLUMN, 1);
        configWriter.setBoolean(LibSvmRecordWriter.MULTILABEL, true);
        FileSplit outputSplit = new FileSplit(tempFile);
        writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner());
        writer.write(record);
    }
}

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

@Test
public void testNonIntegerButValidMultilabel() throws Exception {
    List<Writable> record = Arrays.asList((Writable) new IntWritable(3), new IntWritable(2),
            new DoubleWritable(1.0));
    File tempFile = File.createTempFile("SVMLightRecordWriter", ".txt");
    tempFile.setWritable(true);
    tempFile.deleteOnExit();//from   w w  w  .  j  a  v a 2 s.c  o  m
    if (tempFile.exists())
        tempFile.delete();

    try (SVMLightRecordWriter writer = new SVMLightRecordWriter()) {
        Configuration configWriter = new Configuration();
        configWriter.setInt(SVMLightRecordWriter.FEATURE_FIRST_COLUMN, 0);
        configWriter.setInt(SVMLightRecordWriter.FEATURE_LAST_COLUMN, 1);
        configWriter.setBoolean(SVMLightRecordWriter.MULTILABEL, true);
        FileSplit outputSplit = new FileSplit(tempFile);
        writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner());
        writer.write(record);
    }
}

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

@Test(expected = NumberFormatException.class)
public void nonIntegerMultilabel() throws Exception {
    List<Writable> record = Arrays.asList((Writable) new IntWritable(3), new IntWritable(2),
            new DoubleWritable(1.2));
    File tempFile = File.createTempFile("SVMLightRecordWriter", ".txt");
    tempFile.setWritable(true);
    tempFile.deleteOnExit();/* w ww  .j  a va2  s.c o m*/
    if (tempFile.exists())
        tempFile.delete();

    try (SVMLightRecordWriter writer = new SVMLightRecordWriter()) {
        Configuration configWriter = new Configuration();
        configWriter.setInt(SVMLightRecordWriter.FEATURE_FIRST_COLUMN, 0);
        configWriter.setInt(SVMLightRecordWriter.FEATURE_LAST_COLUMN, 1);
        configWriter.setBoolean(SVMLightRecordWriter.MULTILABEL, true);
        FileSplit outputSplit = new FileSplit(tempFile);
        writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner());
        writer.write(record);
    }
}

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

@Test(expected = NumberFormatException.class)
public void nonBinaryMultilabel() throws Exception {
    List<Writable> record = Arrays.asList((Writable) new IntWritable(0), new IntWritable(1),
            new IntWritable(2));
    File tempFile = File.createTempFile("SVMLightRecordWriter", ".txt");
    tempFile.setWritable(true);
    tempFile.deleteOnExit();/*from ww  w  .ja  v a 2 s  .co  m*/
    if (tempFile.exists())
        tempFile.delete();

    try (SVMLightRecordWriter writer = new SVMLightRecordWriter()) {
        Configuration configWriter = new Configuration();
        configWriter.setInt(SVMLightRecordWriter.FEATURE_FIRST_COLUMN, 0);
        configWriter.setInt(SVMLightRecordWriter.FEATURE_LAST_COLUMN, 1);
        configWriter.setBoolean(SVMLightRecordWriter.MULTILABEL, true);
        FileSplit outputSplit = new FileSplit(tempFile);
        writer.initialize(configWriter, outputSplit, new NumberOfRecordsPartitioner());
        writer.write(record);
    }
}