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.amazon.dtasdk.v2.signature.CredentialStoreTest.java

@BeforeClass
public static void setUp() throws IOException {
    VALID_FILE = File.createTempFile("store", "csv");
    FileWriter writer = new FileWriter(VALID_FILE);

    writer.write(String.format("%s %s\n", KEYS[0], KEYS[1]));
    // Intentionally check if blank lines are supported
    writer.write(String.format("%s %s\n\n", KEYS[2], KEYS[3]));
    writer.write(String.format("%s %s\n", KEYS[4], KEYS[5]));
    writer.write("\n");

    writer.close();

    INVALID_FILE = File.createTempFile("store", "csv");
    writer = new FileWriter(INVALID_FILE);

    writer.write(String.format("%s%s\n", KEYS[0], KEYS[1]));
    writer.write(String.format("%s %s\n", KEYS[2], KEYS[3]));
    writer.write(String.format("%s %s\n", KEYS[4], KEYS[5]));
    writer.write("\n");

    writer.close();//from  w  w  w  .  j av  a  2  s .  c  om
}

From source file:de.pdark.dsmp.RequestHandler.java

public static void generateChecksum(File source, File f, String ext) {
    try {/*from ww w .j  a  v a  2  s .c o  m*/
        String checksum = null;
        if ("md5".equals(ext)) {
            Md5Digester digester = new Md5Digester();
            checksum = digester.calc(source);
        } else if ("sha1".equals(ext)) {
            Sha1Digester digester = new Sha1Digester();
            checksum = digester.calc(source);
        }

        if (checksum != null) {
            FileWriter w = new FileWriter(f);
            w.write(checksum);
            w.write(SystemUtils.LINE_SEPARATOR);
            w.close();
        }
    } catch (DigesterException e) {
        log.warn("Error creating " + ext.toUpperCase() + " checksum for " + source.getAbsolutePath(), e);
    } catch (IOException e) {
        log.warn("Error writing " + ext.toUpperCase() + " checksum for " + source.getAbsolutePath() + " to "
                + f.getAbsolutePath(), e);
    }

}

From source file:com.boyuanitsm.pay.alipay.util.AlipayCore.java

/** 
 * ???// www  .j ava  2  s.c  o m
 * @param sWord ?
 */
public static void logResult(String sWord) {
    FileWriter writer = null;
    try {
        writer = new FileWriter(AlipayConfig.log_path + "alipay_log_" + System.currentTimeMillis() + ".txt");
        writer.write(sWord);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:eu.europa.ec.markt.dss.validation102853.ValidationResourceManager.java

/**
 * This method saves the diagnostic data. A unique name is given to the saved file.
 *
 * @param diagnosticData/*from   w w w.  j a  va  2  s.c o  m*/
 */
public static void saveDiagnosticData(final DiagnosticData diagnosticData) {

    if (SAVE_DIAGNOSTIC_DATA) {

        try {

            final long diagnosticDataUniqueId = getSequenceNumber();
            String unique = diagnosticDataUniqueId + ".";

            // FIXME Just for tests to be deleted.
            unique = "";

            final String diagnosticDataFileName = DIAGNOSTIC_DATA_FOLDER + "/diagnostic_data"
                    + ((unique == null || unique.isEmpty()) ? "" : ("-" + unique)) + ".xml";

            ByteArrayOutputStream baos = jaxbMarshalToOutputStream(diagnosticData);
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            FileWriter fw = new FileWriter(diagnosticDataFileName);
            IOUtils.copy(bais, fw, "UTF-8");
            fw.close();
        } catch (Exception e) {

            LOG.warning(e.getMessage());
        }
    }
}

From source file:com.thinkit.operationsys.util.FileUtil.java

public static void copyFile(String src, String dest) {
    System.out.println("copy");
    File f1 = new File(src);
    File f2 = new File(dest);
    //int b=0;/*from w  ww  .  jav  a2  s .co m*/
    String line = "";
    try {
        FileReader reader = new FileReader(f1);
        FileWriter writer = new FileWriter(f2);
        BufferedReader br = new BufferedReader(reader);
        BufferedWriter bw = new BufferedWriter(writer);
        while ((line = br.readLine()) != null) {
            System.out.println(line);
            bw.write(line);
            bw.newLine();
            bw.flush();
        }
        reader.close();
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.cprassoc.solr.auth.util.Utils.java

public static String writeBytesToFile(String filePath, String content) {
    String path = "";
    try {//from   w w w.jav a 2s  .co  m
        File file = new File(filePath);
        FileWriter fw = new FileWriter(file);
        Log.log(Utils.class, "write file: " + filePath);
        fw.write(content);
        //  IOUtils.write(content, fw);
        //  IOUtils.write
        path = file.getAbsolutePath();
        fw.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return path;
}

From source file:eu.h2020.symbiote.ontology.validation.ValidationHelper.java

private static void writeModelToFile(Model model, String filename, RDFFormat format) {
    FileWriter out = null;
    try {/*w w  w  .ja va  2 s.  c  o  m*/
        out = new FileWriter(filename);
        model.write(out, format.name());
    } catch (IOException e) {

    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException closeException) {
            // ignore
        }
    }
}

From source file:hu.juranyi.zsolt.jauthortagger.util.TestUtils.java

public static File createEmptyFile(String fn) {
    File outFile = new File(TEST_DIR, fn);
    FileWriter w = null;
    try {//from ww w.ja  v  a  2s .com
        File parent = outFile.getParentFile();
        if (null != parent && !parent.exists()) {
            parent.mkdirs();
        }
        w = new FileWriter(outFile);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (null != w) {
            try {
                w.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return outFile;
}

From source file:fll.web.IntegrationTestUtils.java

public static void storeScreenshot(final WebDriver driver) throws IOException {
    final File baseFile = File.createTempFile("fll", null, new File("screenshots"));

    final File screenshot = new File(baseFile.getAbsolutePath() + ".png");
    if (driver instanceof TakesScreenshot) {
        final File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, screenshot);
        LOGGER.error("Screenshot saved to " + screenshot.getAbsolutePath());
    } else {//w  w w.ja va  2 s.c  o m
        LOGGER.warn("Unable to get screenshot");
    }

    final File htmlFile = new File(baseFile.getAbsolutePath() + ".html");
    final String html = driver.getPageSource();
    final FileWriter writer = new FileWriter(htmlFile);
    writer.write(html);
    writer.close();
    LOGGER.error("HTML saved to " + htmlFile.getAbsolutePath());

}

From source file:LineageSimulator.java

public static void writeOutputFile(String fileName, String data) {
    try {/*  ww w.  j av  a2  s  .  c om*/
        FileWriter fw = new FileWriter(fileName);
        fw.write(data);
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Failed to write to the file: " + fileName);
        System.exit(-1);
    }
}