Example usage for java.io FileWriter write

List of usage examples for java.io FileWriter write

Introduction

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

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:jetbrains.exodus.util.CompressBackupUtilTest.java

@Test
public void testFolderArchived() throws Exception {
    File src = new File(randName);
    src.mkdir();/*from   w w  w.  j a v a  2  s . com*/
    FileWriter fw = new FileWriter(new File(src, "1.txt"));
    fw.write("12345");
    fw.close();
    fw = new FileWriter(new File(src, "2.txt"));
    fw.write("12");
    fw.close();
    CompressBackupUtil.tar(src, dest);
    Assert.assertTrue("No destination archive created", dest.exists());
    TarArchiveInputStream tai = new TarArchiveInputStream(
            new GZIPInputStream(new BufferedInputStream(new FileInputStream(dest))));
    ArchiveEntry entry1 = tai.getNextEntry();
    ArchiveEntry entry2 = tai.getNextEntry();
    if (entry1.getName().compareTo(entry2.getName()) > 0) { // kinda sort them lol
        ArchiveEntry tmp = entry1;
        entry1 = entry2;
        entry2 = tmp;
    }
    Assert.assertNotNull("No entry found in destination archive", entry1);
    Assert.assertEquals("Entry has wrong size", 5, entry1.getSize());
    System.out.println(entry1.getName());
    Assert.assertEquals("Entry has wrong relative path", src.getName() + "/1.txt", entry1.getName());
    System.out.println(entry2.getName());
    Assert.assertEquals("Entry has wrong size", 2, entry2.getSize());
    Assert.assertEquals("Entry has wrong relative path", src.getName() + "/2.txt", entry2.getName());
}

From source file:org.yestech.lib.io.FileSystemFileDownloadFilterUnitTest.java

@Test
public void testDeleteAfterDownload() throws IOException, ServletException {
    config.addInitParameter("deleteAfterDownload", "true");
    filter.init(config);// w  w w .  ja  va 2 s. c o m
    String testFileName = "unittest.tst222";
    File file = new File(System.getProperty("java.io.tmpdir"), testFileName);
    FileWriter writer = new FileWriter(file);
    String text = "testing download with delete";
    writer.write(text);
    writer.flush();
    writer.close();
    request.setParameter("file", testFileName);
    filter.doFilter(request, response, chain);
    assertEquals(text.length(), response.getContentLength());
    assertEquals(text, response.getContentAsString());
    assertFalse(file.exists());
}

From source file:com.tealeaf.Downloader.java

protected void write(File f, String contents) {
    try {// w  ww  .j av a  2s  . c  o m
        if (!f.exists()) {
            File dir = new File(f.getParent());
            dir.mkdirs();
            f.createNewFile();
        }
        FileWriter fw = new FileWriter(f);
        fw.write(contents);
        fw.close();
    } catch (IOException e) {
        logger.log(e);
    }
}

From source file:generate.ShowConceptMapAction.java

public String execute() throws ClassNotFoundException, SQLException, IOException {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Major", "root", "pass");
    PreparedStatement ps = con/*  w w  w  .ja va2 s.c  o  m*/
            .prepareStatement("SELECT * from conceptmapdata where chapter_name = ? and section_name = ?");
    ps.setString(1, getKey1());
    ps.setString(2, getKey2());
    System.out.println(getKey1());
    System.out.println(getKey2());
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {

        setData(rs.getString("output_text"));
    }
    try {

        FileWriter file = new FileWriter("/home/chanakya/NetBeansProjects/Concepto/web/new_graph.json");
        file.write(getData());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    return SUCCESS;
}

From source file:com.playonlinux.bash.ScriptLegacy.java

@Override
public void executeScript(PythonInterpreter pythonInterpreter) throws ScriptFailureException {
    // FIXME: Use the properties here
    Script playonlinuxBashInterpreter;/*  w  ww .  j a  v a  2  s .c  om*/
    File bashScriptFile;
    try {
        playonlinuxBashInterpreter = scriptFactory.createInstanceFromFile(
                new File("phoenicis-bash-support/src/main/python/PlayOnLinuxBashInterpreter.py"));

        bashScriptFile = File.createTempFile("script", "sh");
        bashScriptFile.deleteOnExit();
        FileWriter bashScriptWriter = new FileWriter(bashScriptFile);
        bashScriptWriter.write(this.getScriptContent());
        bashScriptWriter.close();
    } catch (IOException e) {
        throw new ScriptFailureException(e);
    }

    pythonInterpreter.set("__scriptToWrap__", bashScriptFile.getAbsolutePath());

    playonlinuxBashInterpreter.executeScript(pythonInterpreter);
}

From source file:com.bt.aloha.testing.SimpleSipStackLogEnhancerTest.java

private void writeSourceFile(String text) throws IOException {
    FileWriter fw = null;
    try {//from  w  ww . j a va 2s .co  m
        fw = new FileWriter(tempSourceFile);
        fw.write(text);
    } finally {
        if (fw != null)
            fw.close();
    }
}

From source file:DIA_Umpire_Quant.DIA_Umpire_ProtQuant.java

private static void SaintOutput(LCMSID protID, LCMSID IDsummary, FragmentSelection fragselection,
        FileWriter interactionfile, String filename, String samplename, HashMap<String, String> PreyID,
        int quanttype) throws IOException {
    for (String key : protID.ProteinList.keySet()) {
        if (IDsummary.ProteinList.containsKey(key)) {
            ProtID protein = IDsummary.ProteinList.get(key);
            float abundance = 0f;

            if (quanttype == 1) {
                abundance = protein.GetAbundanceByMS1_IBAQ();
            } else if (quanttype == 2) {
                abundance = protein.GetAbundanceByTopCorrFragAcrossSample(
                        fragselection.TopPeps.get(protein.getAccNo()), fragselection.TopFrags);
            }//from www .j ava  2s.c om
            if (abundance > 0) {
                interactionfile.write(FilenameUtils.getBaseName(filename) + "\t" + samplename + "\t"
                        + protein.getAccNo() + "\t" + abundance + "\n");
                if (!PreyID.containsKey(protein.getAccNo())) {
                    PreyID.put(protein.getAccNo(), /*protein.Sequence.length()+"\t"+*/ protein.GetGeneName());
                }
            }
        }
    }
}

From source file:com.flexive.tests.embedded.benchmark.logger.XmlLogger.java

/** {@inheritDoc} */
@Override/*from  ww  w.  java  2  s.co  m*/
public synchronized String getOutput() {
    if (active) {
        active = false;
        wax.close();

        // also write result to XML file
        if (!new File(OUTPUT_DIRECTORY).mkdirs()) {
            // ignore
        }
        final String targetName = OUTPUT_DIRECTORY + File.separator + OUTPUT_FILE;
        LOG.info("Writing XML benchmark results to " + targetName);
        final File f = new File(targetName);
        FileWriter fw = null;
        try {
            fw = new FileWriter(f);
            fw.write(out.toString());
        } catch (IOException e) {
            throw new IllegalStateException(e);
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {
                    LOG.error("Failed to close file: " + e.getMessage(), e);
                }
            }
        }
    }
    return out.toString();
}

From source file:org.mashupmedia.service.MapperManagerImpl.java

@Override
public void writeEndRemoteMusicLibraryXml(long libraryId) throws Exception {
    File file = FileHelper.getLibraryXmlFile(libraryId);
    FileWriter writer = new FileWriter(file, true);
    writer.write("</library>");
    writer.close();/*from w  ww .j ava  2 s.c om*/
}

From source file:com.michaelfitzmaurice.devtools.HeaderTool.java

/**
 * Inserts the header at the beginning of each file.
 * Does not check whether or not the header is already
 * present.//from  w w  w. j  av a 2s. c  o  m
 * 
 * @param files The files to be amended
 * @throws IOException If something goes wrong reading 
 *          from or writing to any of the files
 */
public void insertHeader(Collection<File> files) throws IOException {

    LOG.info("Inserting header from {} into {} files", headerFile, files.size());

    for (File file : files) {
        String originalFileContent = fileContents(file);
        FileWriter writer = new FileWriter(file);
        writer.write(header);
        writer.write(originalFileContent);
        writer.close();
        LOG.info("Added header to {}", file);
    }
}