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.thingml.compilers.build.JSBuildCompiler.java

public void generate(Configuration cfg, Context ctx) {
    try {/*  w w  w  . j a v a  2 s  . com*/
        final InputStream input = this.getClass().getClassLoader()
                .getResourceAsStream("javascript/lib/package.json");
        final List<String> packLines = IOUtils.readLines(input);
        String pack = "";
        for (String line : packLines) {
            pack += line + "\n";
        }
        input.close();
        pack = pack.replace("<NAME>", cfg.getName());

        final JsonObject json = JsonObject.readFrom(pack);
        final JsonValue deps = json.get("dependencies");
        for (Thing t : cfg.allThings()) {
            for (String dep : t.annotation("js_dep")) {
                deps.asObject().add(dep.split(":")[0].trim(), dep.split(":")[1].trim());
            }
        }

        final File f = new File(ctx.getOutputDir() + "/" + cfg.getName() + "/package.json");
        f.setWritable(true);
        final PrintWriter w = new PrintWriter(new FileWriter(f));
        w.println(json.toString());
        w.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.thingml.compilers.javascript.JSCfgBuildCompiler.java

@Override
public void generateBuildScript(Configuration cfg, Context ctx) {
    try {// w  w w .j  a  v a2  s .  co  m
        final InputStream input = this.getClass().getClassLoader()
                .getResourceAsStream("javascript/lib/package.json");
        final List<String> packLines = IOUtils.readLines(input);
        String pack = "";
        for (String line : packLines) {
            pack += line + "\n";
        }
        input.close();
        pack = pack.replace("<NAME>", cfg.getName());

        final JsonObject json = JsonObject.readFrom(pack);
        final JsonValue deps = json.get("dependencies");
        for (Thing t : cfg.allThings()) {
            for (String dep : t.annotation("js_dep")) {
                deps.asObject().add(dep.split(":")[0].trim(), dep.split(":")[1].trim());
            }

        }

        for (Thing t : cfg.allThings()) {
            if (t.getStreams().size() > 0) {
                deps.asObject().add("rx", "^2.5.3");
                deps.asObject().add("events", "^1.0.2");
                break;

            }
        }

        final File f = new File(ctx.getOutputDirectory() + "/" + cfg.getName() + "/package.json");
        f.setWritable(true);
        final PrintWriter w = new PrintWriter(new FileWriter(f));
        w.println(json.toString());
        w.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.jenkinsci.plugins.SemanticVersioning.test.ParserTests.java

protected void writeLinesToFile(String filename, Collection<String> lines) throws IOException {
    File file = new File(filename);
    if (file.exists()) {
        file.delete();/*from   w  ww  .j  ava 2  s .c o  m*/
    }
    file.setWritable(true);

    FileUtils.writeLines(file, lines);
}

From source file:com.web.mavenproject6.controller.DocumentUploadController.java

@ResponseBody
@RequestMapping(value = "/uploadMultipleFile", method = RequestMethod.POST)
public Object uploadMultipleFileHandler(@RequestParam("file") MultipartFile[] files) {
    System.out.print("PATH IS A:" + env.getProperty("upload.files.dir"));
    String buf = "";
    List<String> l = new ArrayList<>();
    for (MultipartFile file : files) {
        try {/*from w w w .j  a v a2 s  .com*/
            byte[] bytes = file.getBytes();

            String rootPath = env.getProperty("upload.files.dir");

            File dir = new File(rootPath);
            if (!dir.exists()) {
                dir.mkdirs();
                dir.setWritable(true);
            }
            File serverFile = new File(rootPath + File.separator + file.getOriginalFilename());
            serverFile.createNewFile();
            BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
            stream.write(bytes);
            stream.close();
            System.err.println(file.getOriginalFilename());
            buf = XLSParser.parse(env.getProperty("upload.files.dir") + "\\" + file.getOriginalFilename());

            l.add(file.getOriginalFilename());
        } catch (Exception e) {

        }
    }
    // ModelAndView model = new ModelAndView("jsp/uploadedFiles");
    //model.addObject("list", l.toArray());
    // model.addObject("buffer",buf);
    //  return model;
    return buf;
}

From source file:org.jenkinsci.plugins.drupal.scm.DrushMakefileSCM.java

@Override
public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, TaskListener listener,
        File changelogFile, SCMRevisionState baseline) throws IOException, InterruptedException {
    // If necessary, delete destination directory so we can install Drupal (unless Drupal root is workspace root).
    File rootDir = new File(workspace.getRemote(), root);
    FilePath rootPath = new FilePath(rootDir);
    if (rootDir.exists() && !rootPath.getRemote().equals(workspace.getRemote())) {
        listener.getLogger().println("[DRUPAL] Deleting destination directory " + rootDir.getAbsolutePath());
        // Make sure drupal/sites/defaults is writable so we can delete its contents.
        File defaultDir = new File(rootDir, "sites/default");
        defaultDir.setWritable(true);
        FileUtils.deleteDirectory(rootDir);
    }//from w w  w .  ja  v a2s  .  c  o m

    // Save Makefile into local file.
    File makefileFile = new File(workspace.getRemote(), MAKEFILE_FILE);
    listener.getLogger().println("[DRUPAL] Saving Makefile into " + makefileFile.getAbsolutePath());
    FileUtils.writeStringToFile(makefileFile, makefile);

    // Make Drupal.
    DrushInvocation drush = new DrushInvocation(rootPath, workspace, launcher, listener,
            build.getEnvironment(listener));
    drush.make(makefileFile);
}

From source file:ws.ip4u.mediadaemon.FileMover.java

private boolean fixPermissions(File f) {
    boolean success = f.canWrite() && f.canRead();
    if (!f.canWrite()) {
        success = f.setWritable(true);
    }/*from  w  ww  .  j  a va 2  s  .com*/
    if (success && !f.canRead()) {
        success = f.setReadable(true);
    }
    return success;
}

From source file:org.jodconverter.office.LocalOfficeUtilsTest.java

/** Tests the validateOfficeWorkingDirectory with a read only dicrectory as argument fails. */
@Test(expected = IllegalStateException.class)
public void validateOfficeWorkingDirectory_WithReadOnlyDirectory_ThrowsIllegalStateException()
        throws IOException {

    final File tempDir = new File(System.getProperty("java.io.tmpdir"));
    final File workingDir = new File(tempDir, UUID.randomUUID().toString());
    workingDir.setWritable(false);

    LocalOfficeUtils.validateOfficeWorkingDirectory(workingDir);
}

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

@Test
public void testWriteError2() {
    final File resource = new File(readonly2, RESOURCE_QUADS);
    assumeTrue(readonly2.setWritable(true));
    assumeTrue(resource.setWritable(false));
    assertFalse(CachedResource.write(readonly2, identifier, now()));
    resource.setWritable(true);// w w  w. ja v  a  2s .  co m
}

From source file:org.graylogalert.component.ConfigurationTest.java

/**
 *  ?  //from w  w  w.  ja va 2 s . c  om
 *
 * @param canWrite -  ?  ?
 */
public void setAccess(Boolean canWrite) {
    Path path = Paths.get(".").toAbsolutePath();
    File file = path.toFile();
    file.setWritable(canWrite);
}

From source file:com.citrix.g2w.webdriver.util.FileDownloader.java

public String downloader(String fileToDownloadLocation, String localDownloadPath)
        throws IOException, URISyntaxException {
    URL fileToDownload = new URL(fileToDownloadLocation);
    String fileNameURI = fileToDownload.getFile();
    String filePath = "";
    if (fileNameURI.contains("?")) {
        filePath = localDownloadPath//from   w  w w  . j ava  2  s.  c om
                + fileNameURI.substring(fileNameURI.substring(0, fileNameURI.indexOf("?")).lastIndexOf("/") + 1,
                        fileNameURI.indexOf("?"));
    } else {
        filePath = localDownloadPath + fileNameURI.substring(fileNameURI.lastIndexOf("/") + 1);
    }
    File downloadedFile = new File(filePath);
    if (downloadedFile.canWrite() == false) {
        downloadedFile.setWritable(true);
    }

    HttpClient client = new DefaultHttpClient();
    BasicHttpContext localContext = new BasicHttpContext();

    if (this.mimicWebDriverCookieState) {
        localContext.setAttribute(ClientContext.COOKIE_STORE,
                this.mimicCookieState(this.driver.manage().getCookies()));
    }

    HttpGet httpget = new HttpGet(fileToDownload.toURI());
    HttpParams httpRequestParameters = httpget.getParams();
    httpRequestParameters.setParameter(ClientPNames.HANDLE_REDIRECTS, this.followRedirects);
    httpget.setParams(httpRequestParameters);

    HttpResponse response = client.execute(httpget, localContext);

    FileUtils.copyInputStreamToFile(response.getEntity().getContent(), downloadedFile);
    response.getEntity().getContent().close();

    String downloadedFileAbsolutePath = downloadedFile.getAbsolutePath();
    this.logger.log("File downloaded to '" + downloadedFileAbsolutePath + "'");

    return downloadedFileAbsolutePath;
}