Example usage for java.io FileWriter close

List of usage examples for java.io FileWriter close

Introduction

In this page you can find the example usage for java.io FileWriter close.

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:com.palantir.gerrit.gerritci.servlets.JobsServlet.java

public static ArrayList<String> updateProjectJobFiles(File projectFile, File projectConfigDirectory,
        ArrayList<String> receivedJobNames) throws IOException {

    Scanner scanner = new Scanner(projectFile);

    ArrayList<String> updatedJobs = new ArrayList<String>();
    ArrayList<String> newJobs = new ArrayList<String>();
    ArrayList<String> deletedJobs = new ArrayList<String>();

    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        if (receivedJobNames.contains(line)) {
            updatedJobs.add(line);//w  ww .j a  va  2 s  . c om
            receivedJobNames.remove(line);
        } else {
            deletedJobs.add(line);
        }
    }
    logger.info("There are " + receivedJobNames.size() + " new jobs");
    logger.info("There are " + deletedJobs.size() + " deleted jobs");
    logger.info("There are " + updatedJobs.size() + " updated jobs");
    for (String s : receivedJobNames) {
        newJobs.add(s);
    }

    scanner.close();
    FileWriter writer = new FileWriter(projectFile, false);
    for (String s : updatedJobs) {
        writer.write(s);
        writer.write("\n");
    }
    for (String s : newJobs) {
        writer.write(s);
        writer.write("\n");
    }
    writer.close();
    return deletedJobs;
}

From source file:edu.umass.cs.utils.Util.java

public static void wipeoutFile(String filename) throws IOException {
    FileWriter writer = null;
    try {//from   w ww . j av  a2 s . c o  m
        (writer = new FileWriter(filename, false)).close();
    } finally {
        writer.close();
    }
}

From source file:org.apache.hadoop.gateway.SecureClusterTest.java

private static File setupJaasConf(File baseDir, String keyTabFile, String principal) throws IOException {
    File file = new File(baseDir, "jaas.conf");
    if (!file.exists()) {
        file.createNewFile();/*from www . j  a va2  s  .co  m*/
    } else {
        file.delete();
        file.createNewFile();
    }
    FileWriter writer = new FileWriter(file);
    String content = String.format("com.sun.security.jgss.initiate {\n"
            + "com.sun.security.auth.module.Krb5LoginModule required\n" + "renewTGT=true\n"
            + "doNotPrompt=true\n" + "useKeyTab=true\n" + "keyTab=\"%s\"\n" + "principal=\"%s\"\n"
            + "isInitiator=true\n" + "storeKey=true\n" + "useTicketCache=true\n" + "client=true;\n" + "};\n",
            keyTabFile, principal);
    writer.write(content);
    writer.close();
    return file;
}

From source file:cn.kk.exia.MangaDownloader.java

private final static void checkAndDump(final String line, final Logger log, final String targetDir) {
    if (line.contains("An Error Has Occurred")) {
        try {//from w  w w.j  a va2  s  . com
            Thread.sleep(
                    (60 * MangaDownloader.sleepBase) + (int) (Math.random() * 120 * MangaDownloader.sleepBase));
        } catch (final InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (line.contains("your IP address")) {
        log.err("??" + line);
        try {
            Thread.sleep(
                    (60 * MangaDownloader.sleepBase) + (int) (Math.random() * 120 * MangaDownloader.sleepBase));
        } catch (final InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (MangaDownloader.dump) {
        try {
            final File dumpFile = new File(targetDir + File.separator + "exia-dump.xml");
            if (!dumpFile.isFile()) {
                log.err("dump: " + dumpFile.getAbsolutePath());
            }
            final FileWriter writer = new FileWriter(dumpFile, true);

            writer.append(line);
            writer.append('\n');
            writer.close();
        } catch (final IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:loadTest.loadTestLib.LUtil.java

public static void writeCSVResult(LoadTestConfigModel model, long resTime) throws IOException {
    FileWriter writer = new FileWriter("loadTestResults.csv", true);
    writer.append(String.valueOf(model.getNodeCount()));
    writer.append(",");
    writer.append(String.valueOf(model.getFileCount()));
    writer.append(",");
    writer.append(String.valueOf(model.getFileSize()));
    writer.append(",");
    writer.append(String.valueOf(resTime));
    writer.append("\n");
    writer.flush();/*w  w w  .j  a  v  a2  s.c o m*/
    writer.close();
}

From source file:com.google.dart.tools.core.utilities.io.FileUtilities.java

/**
 * Overwrite the contents of the given file to the given contents.
 * /*from  ww w  .  j av a 2 s .c  om*/
 * @param file the file whose contents are to be written
 * @param contents the new contents for the file
 * @throws IOException if the file contents could not be written
 */
public static void setContents(File file, String contents) throws IOException {
    FileWriter fileWriter = null;
    BufferedWriter writer;

    try {
        fileWriter = new FileWriter(file);
        writer = new BufferedWriter(fileWriter);
        writer.write(contents);
        writer.flush();
    } finally {
        if (fileWriter != null) {
            fileWriter.close();
        }
    }
}

From source file:madkitgroupextension.export.Export.java

public static void saveAndIncrementBuild() throws IOException {
    MadKitGroupExtension.VERSION.setBuildNumber(MadKitGroupExtension.VERSION.getBuildNumber() + 1);
    FileWriter fw = new FileWriter(new File("build.txt"));
    BufferedWriter b = new BufferedWriter(fw);
    b.write(Integer.toString(MadKitGroupExtension.VERSION.getBuildNumber()));
    b.flush();//from w w  w .  jav a 2s . c om
    b.close();
    fw.close();
}

From source file:doc.doclets.WorkbenchHelpDoclet.java

private static void _writeIndex(final String indexText) throws IOException {
    String fileBaseName = "index.xml";

    String fileName = null;/*from w w  w. j a v a  2  s.  com*/
    if (_outputDirectory != null) {
        fileName = _outputDirectory + File.separator + fileBaseName;
    } else {
        fileName = fileBaseName;
    }
    // If necessary, create the directory.
    final File directoryFile = new File(fileName).getParentFile();
    if (!directoryFile.exists()) {
        if (!directoryFile.mkdirs()) {
            throw new IOException("Directory \"" + directoryFile + "\" does not exist and cannot be created.");
        }
    }
    System.out.println("Creating " + fileName);

    final FileWriter writer = new FileWriter(fileName);
    try {
        writer.write(indexText);
    } finally {
        writer.close();
    }
}

From source file:doc.doclets.WorkbenchHelpDoclet.java

private static void _writeTOC(final String indexText) throws IOException {
    String fileBaseName = "passerelle.xml";

    String fileName = null;/*  w  w w.  ja va 2 s  .co  m*/
    if (_outputDirectory != null) {
        fileName = _outputDirectory + File.separator + fileBaseName;
    } else {
        fileName = fileBaseName;
    }
    // If necessary, create the directory.
    final File directoryFile = new File(fileName).getParentFile();
    if (!directoryFile.exists()) {
        if (!directoryFile.mkdirs()) {
            throw new IOException("Directory \"" + directoryFile + "\" does not exist and cannot be created.");
        }
    }
    System.out.println("Creating " + fileName);

    final FileWriter writer = new FileWriter(fileName);
    try {
        writer.write(indexText);
    } finally {
        writer.close();
    }
}

From source file:doc.doclets.WorkbenchHelpDoclet.java

private static void _writeHtmlTOC(final String indexText) throws IOException {
    String fileBaseName = "passerelle.html";

    String fileName = null;/*from   ww  w.j  a  va2s.c  o m*/
    if (_outputDirectory != null) {
        fileName = _outputDirectory + File.separator + "html" + File.separator + fileBaseName;
    } else {
        fileName = fileBaseName;
    }
    // If necessary, create the directory.
    final File directoryFile = new File(fileName).getParentFile();
    if (!directoryFile.exists()) {
        if (!directoryFile.mkdirs()) {
            throw new IOException("Directory \"" + directoryFile + "\" does not exist and cannot be created.");
        }
    }
    System.out.println("Creating " + fileName);

    final FileWriter writer = new FileWriter(fileName);
    try {
        writer.write(indexText);
    } finally {
        writer.close();
    }
}