Example usage for java.io FileWriter append

List of usage examples for java.io FileWriter append

Introduction

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

Prototype

@Override
    public Writer append(CharSequence csq) throws IOException 

Source Link

Usage

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.FileUtilityTest.java

@Test
public void testRevertLatestBackupFiles() throws IOException, InterruptedException, FileUtilityException {
    LOGGER.debug("REVERT TEST STARTING");
    Date latestDate = new Date();
    fileUtility.copyBackupFile(TEMP_DIR, "config", "tempfile2.tmp", latestDate);
    File alterFile = new File(TEMP_DIR + "/config/tempfile2.tmp");
    LOGGER.debug("ALTER FILE - " + alterFile.getAbsolutePath() + " - Exists: " + alterFile.isFile());
    FileWriter writer = new FileWriter(alterFile);
    writer.append("THIS IS A NEWER FILE");
    writer.close();//from www.j a v  a2  s  . c o m
    FileReader reader = new FileReader(alterFile);
    BufferedReader br = new BufferedReader(reader);
    String fileText = br.readLine();
    reader.close();
    assertEquals("This text should be the same.", "THIS IS A NEWER FILE", fileText);
    Set<String> latestDirs = fileUtility.getLatestBackupDirectories(TEMP_DIR);
    String highestDirectory = ((TreeSet<String>) latestDirs).last();
    fileUtility.revertToBackupFiles(TEMP_DIR, highestDirectory);
    alterFile = new File(TEMP_DIR + "/config/tempfile2.tmp");
    LOGGER.debug("ALTER FILE After - " + alterFile.getAbsolutePath() + " - Exists: " + alterFile.isFile());
    reader = new FileReader(alterFile);
    br = new BufferedReader(reader);
    fileText = br.readLine();
    reader.close();
    assertEquals("The text in the file should be the same.", FILE2_TEXT, fileText);
}

From source file:eu.eidas.node.auth.metadata.EidasNodeMetadataGeneratorTest.java

private void putMetadataInFile(String fileName, String metadataContent) {
    File f = new File(fileName);
    try {// w w  w . j  a va2 s  . co m
        FileWriter fw = new FileWriter(f);
        fw.append(metadataContent);
        fw.close();
    } catch (IOException ioe) {
        fail("error writing metadata contents: " + ioe);
    }
}

From source file:bigdataproject.KDistances.java

void printKdistances() {
    try {/*from   w w  w. j  ava  2 s.  com*/
        FileWriter writer = new FileWriter("eps.csv");
        for (int i = 0; i < Karray.length; i++) {
            writer.append(String.valueOf(Karray[i]));
            writer.append("\n");
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:io.github.binout.wordpress2html.writer.PostWriter.java

private void addHeader(File asciidoc) throws IOException {
    boolean firstTag = true;
    List<String> tags;
    String content = IOUtils.toString(new FileInputStream(asciidoc));
    FileWriter fileWriter = new FileWriter(asciidoc, false);
    fileWriter.append("= ").append(post.getTitle()).append("\n");
    fileWriter.append(":published_at: ").append(post.getDate().format(DATE_TIME_FORMATTER)).append("\n");
    tags = post.getTags();/*from   ww  w . ja v  a 2s. co m*/
    if (!tags.isEmpty()) {
        fileWriter.append(":hp-tags: ");
        for (String tag : post.getTags()) {
            if (!firstTag) {
                fileWriter.append(", ");
            } else {
                firstTag = false;
            }
            fileWriter.append(tag);
        }
        fileWriter.append("\n");
    }
    content = content.replaceAll(Globals.from, Globals.to);
    content = content.replaceAll("\\[caption .*image:http://.*/(.*)\\]\\[/caption\\]", "image::$1");
    // TODO
    // Add youtube conversion
    //        content = content.replaceAll("\\[youtube=http://www.youtube.com/watch?v=(.*)]", "video::$1[youtube]");
    //        [youtube=http://www.youtube.com/watch?v=cQ0bgz3tyNk&fs=1&hl=fr_FR]
    //        video::KCylB780zSM[youtube]
    content = content.replaceAll("\\[.*code language=\"(.*)\"\\]", "[source,$1]");
    content = content.replaceAll("&lt;", "<");
    content = content.replaceAll("&gt;", ">");
    content = content.replaceAll("&amp;", "&");
    content = content.replaceAll("&quot;", "\"");
    content = content.replaceAll("-{5,}", "-----------------------");

    fileWriter.append("\n").append(content);
    fileWriter.close();
}

From source file:net.itransformers.idiscover.v2.core.listeners.network.NetworkGraphmlFileLogDiscoveryListener.java

@Override
public void networkDiscovered(NetworkDiscoveryResult result) {
    File baseDir = new File(projectPath);
    if (!baseDir.exists())
        baseDir.mkdir();/*from   w  w  w .  j ava2 s.c o  m*/

    File labelDirPath = new File(baseDir, labelDirName);
    if (!labelDirPath.exists())
        labelDirPath.mkdir();

    File graphmlDir = new File(labelDirPath, graphmlDirName);
    if (!graphmlDir.exists())
        graphmlDir.mkdir();

    Map<String, NodeDiscoveryResult> discoveryResultMap = result.getDiscoveredData();
    for (String node : discoveryResultMap.keySet()) {

        byte[] discoveredDeviceData = (byte[]) discoveryResultMap.get(node).getDiscoveredData("graphml");

        try {
            final String fileName = ProjectConstants.networkGraphmlFileName;
            final File nodeFile = new File(graphmlDir, fileName);
            String graphml = new String(discoveredDeviceData);
            FileUtils.writeStringToFile(nodeFile, graphml);
            FileWriter writer = new FileWriter(new File(labelDirPath, "undirected" + ".graphmls"), true);
            writer.append(String.valueOf(fileName)).append("\n");
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

From source file:org.sonar.server.startup.GenerateBootstrapIndex.java

void writeIndex(File indexFile) throws IOException {
    FileUtils.forceMkdir(indexFile.getParentFile());
    FileWriter writer = new FileWriter(indexFile, false);
    try {//from  w  w w  .java2s .c  om
        for (String path : getLibs(servletContext)) {
            writer.append(path);
            InputStream is = servletContext.getResourceAsStream("/WEB-INF/lib/" + path);
            writer.append("|").append(new FileHashes().of(is));
            writer.append(CharUtils.LF);
        }
        writer.flush();

    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:org.fcrepo.importexport.ArgParserTest.java

@Test
public void parseConfigFile() throws IOException {
    // Create test config file
    final File configFile = File.createTempFile("config-test", ".txt");
    final FileWriter writer = new FileWriter(configFile);
    writer.append("-d\n");
    writer.append("/tmp/desc\n");
    writer.append("-m\n");
    writer.append("export\n");
    writer.append("-r\n");
    writer.append("http://localhost:8080/rest/test\n");
    writer.append("-b\n");
    writer.append("/tmp/bin\n");
    writer.flush();// w w w.j  a va 2 s .c o  m

    final String[] args = new String[] { "-c", configFile.getAbsolutePath() };
    final Config config = parser.parseConfiguration(args);
    Assert.assertTrue(config.isExport());
    Assert.assertEquals(new File("/tmp/desc"), config.getDescriptionDirectory());
    Assert.assertEquals(new File("/tmp/bin"), config.getBinaryDirectory());
    Assert.assertEquals(".ttl", config.getRdfExtension());
    Assert.assertEquals("text/turtle", config.getRdfLanguage());
    Assert.assertEquals(URI.create("http://localhost:8080/rest/test"), config.getResource());

    Assert.assertTrue("Config file should be created!",
            new File(getProperty("java.io.tmpdir"), CONFIG_FILE_NAME).exists());
}

From source file:org.mgenterprises.openbooks.saving.server.FileBackedSaveManager.java

public void createLock(String holder, String type, String id) {
    File saveFile = new File(saveRootDirectory + File.separator + type + File.separator + id + ".lock");
    try {/*from   w  w  w . jav  a  2 s  .  c o m*/
        saveFile.createNewFile();
        FileWriter fw = new FileWriter(saveFile);
        fw.append(holder);
        fw.append("\n");
        fw.flush();
        fw.close();
    } catch (IOException ex) {
        Logger.getLogger(FileBackedSaveManager.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.projectforge.core.CreateI18nKeys.java

public void run() throws IOException {
    log.info("Create file with all detected i18n keys.");
    final Map<String, Set<String>> i18nKeyUsage = new HashMap<String, Set<String>>();
    parseHtml(i18nKeyUsage);/*from   w  w  w  . j a v  a2 s.c o m*/
    parseJava(i18nKeyUsage);
    final FileWriter writer = new FileWriter(I18N_KEYS_FILE);
    writer.append(
            "# Don't edit this file. This file is only for developers for checking i18n keys and detecting missed and unused ones.\n");
    final Set<String> i18nKeys = new TreeSet<String>(i18nKeyUsage.keySet());
    for (final String i18nKey : i18nKeys) {
        writer.append(i18nKey).append("=");
        final Set<String> set = i18nKeyUsage.get(i18nKey);
        boolean first = true;
        for (final String filename : set) {
            if (first == false) {
                writer.append(',');
            } else {
                first = false;
            }
            writer.append(filename);
        }
        writer.append("\n");
    }
    IOUtils.closeQuietly(writer);
    log.info("Creation of file of found i18n keys done: " + I18N_KEYS_FILE);
}

From source file:org.nuxeo.opensocial.service.impl.OpenSocialServiceImpl.java

protected File createTempFileForAKey(String keyValue) throws IOException {
    File f = File.createTempFile("nxkey", ".txt");
    f.deleteOnExit();/* w  w  w . j a  va  2s .c om*/
    FileWriter writer = new FileWriter(f);
    writer.append(keyValue);
    writer.flush();
    writer.close();
    return f;
}