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:de.knurt.fam.template.controller.letter.EMailLetterAdapter.java

private File getTmpFile(String customid) throws IOException {
    String fullpath = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator")
            + this.df.format(new Date()) + "-" + customid + ".pdf";
    File result = new File(fullpath);
    result.createNewFile();/*from  ww w  .  ja  v  a 2s .  co m*/
    result.setWritable(true);
    return result;
}

From source file:com.cloudant.sync.datastore.ForceInsertTest.java

@Test
public void notification_forceinsertWithAttachmentsError() throws IOException {

    // this test only makes sense if the data is inline base64 (there's no remote server to pull the attachment from)
    boolean pullAttachmentsInline = true;

    // try and force an IOException when setting the attachment, and check everything is OK:

    // create a read only zero-length file where the extensions dir would go, to cause an IO exception
    File extensions = new File(datastore.datastoreDir + "/extensions");
    extensions.createNewFile();/*from w  w  w .j a v  a2  s  . com*/
    extensions.setWritable(false);

    BasicDocumentRevision doc1_rev1 = datastore.createDocument(bodyOne);
    Map<String, Object> atts = new HashMap<String, Object>();
    Map<String, Object> att1 = new HashMap<String, Object>();

    atts.put("att1", att1);
    att1.put("data", new String(new Base64().encode("this is some data".getBytes())));
    att1.put("content_type", "text/plain");

    ArrayList<String> revisionHistory = new ArrayList<String>();
    revisionHistory.add(doc1_rev1.getRevision());
    doc1_rev1.setRevision("2-blah");
    revisionHistory.add(doc1_rev1.getRevision());
    // now do a force insert
    datastore.forceInsert(doc1_rev1, revisionHistory, atts, pullAttachmentsInline);

    // adding the attachment should have failed transactionally, so the rev should not exist as well
    DocumentRevision dr = datastore.getDocument(doc1_rev1.getId(), doc1_rev1.getRevision());
    Assert.assertNull("Document should not exist at this revision", dr);

    Attachment storedAtt = datastore.getAttachment(doc1_rev1, "att1");
    Assert.assertNull(storedAtt);
}

From source file:org.trellisldp.rosid.file.RDFPatchTest.java

@Test
public void testWriteErrors() throws Exception {
    final File file = new File(getClass().getResource("/readonly/resource.rdfp").toURI());
    assumeTrue(file.setWritable(false));
    assertFalse(RDFPatch.write(file, empty(), empty(), now()));
    file.setWritable(true);/*  www  .j  ava  2  s  .  c  o  m*/
}

From source file:org.trellisldp.rosid.file.CachedResourceTest.java

@Test
public void testWriteErrorResource() throws IOException {
    final File cache = new File(readonly2, RESOURCE_CACHE);
    final File quads = new File(readonly2, RESOURCE_QUADS);

    readonly2.setWritable(true);//from  w w  w.  ja v  a 2 s. c o m
    cache.createNewFile();
    quads.createNewFile();

    assumeTrue(quads.setWritable(false));
    assertFalse(CachedResource.write(readonly2, ldprsIri, now()));

    assumeTrue(cache.setWritable(false));
    assertFalse(CachedResource.write(readonly2, ldprsIri, now()));

    quads.setWritable(true);
    cache.setWritable(true);
}

From source file:org.openehealth.ipf.labs.maven.confluence.export.AbstractConfluenceExportTemplate.java

private void download(InputStream content, File targetFile) throws IOException {
    if (!targetFile.exists()) {
        targetFile.setWritable(true);
        targetFile.getParentFile().mkdirs();
        boolean created = targetFile.createNewFile();
        if (!created) {
            throw new IOException("Unable to create file " + targetFile.getAbsolutePath());
        }//from   w  ww . ja v  a 2  s  .c  o m
    }
    OutputStream targetStream = null;
    try {
        targetStream = new BufferedOutputStream(new FileOutputStream(targetFile), 1024 * 4);
        IOUtils.copy(content, targetStream);
    } finally {
        IOUtils.closeQuietly(targetStream);
    }
}

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

@After
public void deleteKeyFile() throws Exception {
    File keyFile = new File(ACTUAL_KEY_FILE_PATH);
    if (keyFile.exists()) {
        keyFile.setWritable(true);
        FileUtils.forceDelete(keyFile);/*from  ww  w.j  av  a 2s .  c  o  m*/
    }
    keyFile = new File(OLD_KEY_FILE_PATH);
    if (keyFile.exists()) {
        keyFile.setWritable(true);
        FileUtils.forceDelete(keyFile);
    }
}

From source file:org.silverpeas.core.security.encryption.ContentEncryptionServiceTest.java

@AfterEach
public void deleteKeyFile() throws Exception {
    File keyFile = new File(ACTUAL_KEY_FILE_PATH);
    if (keyFile.exists()) {
        keyFile.setWritable(true);
        FileUtils.forceDelete(keyFile);/* ww  w. j a  v a2s.c  om*/
    }
    keyFile = new File(DEPRECATED_KEY_FILE_PATH);
    if (keyFile.exists()) {
        keyFile.setWritable(true);
        FileUtils.forceDelete(keyFile);
    }
}

From source file:org.silverpeas.core.security.encryption.ContentEncryptionServiceTest.java

/**
 * Creates the key file with the specified actual key in hexadecimal.
 * @param key the key used in a content encryption and to store in the key file.
 * @throws Exception if the key file creation failed.
 *///from  w w  w. j  ava  2  s  . c o m
public void createKeyFileWithTheActualKey(String key) throws Exception {
    File keyFile = new File(ACTUAL_KEY_FILE_PATH);
    if (keyFile.exists()) {
        keyFile.setWritable(true);
    } else {
        System.out.println("WARNIIIINNNNNG: the key file " + ACTUAL_KEY_FILE_PATH + " DOESN'T EXIST!");
    }
    String encryptedKey = encryptKey(key);
    String encryptedContent = StringUtil.asBase64(CIPHER_KEY.getRawKey()) + " " + encryptedKey;
    Files.copy(new ByteArrayInputStream(encryptedContent.getBytes()), keyFile.toPath(), REPLACE_EXISTING);
    keyFile.setReadOnly();
}

From source file:org.silverpeas.core.security.encryption.ContentEncryptionServiceTest.java

/**
 * Creates the key file with the specified deprecated key in hexadecimal.
 * @param key the key used in a content encryption and to store in the old key file.
 * @throws Exception if the key file creation failed.
 *//*from   w  w w.j  a v  a 2  s. c om*/
public void createKeyFileWithTheDeprecatedKey(String key) throws Exception {
    File keyFile = new File(DEPRECATED_KEY_FILE_PATH);
    if (keyFile.exists()) {
        keyFile.setWritable(true);
    }
    String encryptedKey = encryptKey(key);
    String encryptedContent = StringUtil.asBase64(CIPHER_KEY.getRawKey()) + " " + encryptedKey;
    Files.copy(new ByteArrayInputStream(encryptedContent.getBytes()), keyFile.toPath(), REPLACE_EXISTING);
    keyFile.setReadOnly();
}

From source file:beans.FotoBean.java

public void tirarFoto(CaptureEvent captureEvent) throws IOException {
    arquivo = gerarNome();/*from w  w w.  j  a v a  2 s  .c  o m*/
    byte[] data = captureEvent.getData();

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String pasta = servletContext.getRealPath("") + File.separator + "resources" + File.separator
            + "fotossalvas";
    File vpasta = new File(pasta);
    if (!vpasta.exists()) {
        vpasta.setWritable(true);
        vpasta.mkdirs();
    }
    String novoarquivo = pasta + File.separator + arquivo + ".jpeg";
    System.out.println(novoarquivo);
    fotosalva = new File(novoarquivo);
    fotosalva.createNewFile();
    FileImageOutputStream imageOutput;
    try {
        imageOutput = new FileImageOutputStream(fotosalva);
        imageOutput.write(data, 0, data.length);
        imageOutput.close();

    } catch (IOException e) {
        Util.criarMensagemErro(e.toString());

    }
}