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:eu.abc4trust.guice.configuration.ConfigurationParserTest.java

@Test
public void testPropertiesConfiguration() throws IOException {
    File tmp = TemporaryFileFactory.createTemporaryFile();
    String filename = tmp.getAbsolutePath();

    String credentialFilename = "credentials.file";
    String keystorageFilename = "keystorage.file";
    String tokensFilename = "tokens.file";
    String pseudonymsFilename = "pseudonyms.file";
    String defaultImagePath = "default.jpg";
    String imageCacheDir = "image_cache_dir";

    FileWriter writer = new FileWriter(tmp);
    writer.write(" credentialstorage_file" + "=" + credentialFilename + "\n");
    writer.write("keystorage_file" + " = " + keystorageFilename + "\n\n");
    writer.write("  pseudonyms_file" + "   =    " + pseudonymsFilename + "    \n");
    writer.write("tokenstorage_file" + "=" + tokensFilename + "\n");
    writer.write("default_image_path" + "=" + defaultImagePath + "\n");
    writer.write("image_cache_dir" + "=" + imageCacheDir + "\n");
    writer.close();//  w  ww .  j  a  v a 2s .  c  o  m

    PropertiesConfiguration config;
    try {
        config = new PropertiesConfiguration(filename);

        config.setReloadingStrategy(new FileChangedReloadingStrategy());

        ConfigurationParser configurationParser = new ConfigurationParser(config);
        AbceConfigurationImpl abceConfiguration = new AbceConfigurationImpl();
        configurationParser.loadConfiguration(abceConfiguration);
        assertEquals(abceConfiguration.getCredentialFile().getName(), credentialFilename);
        assertEquals(abceConfiguration.getKeyStorageFile().getName(), keystorageFilename);
        assertEquals(abceConfiguration.getPseudonymsFile().getName(), pseudonymsFilename);
        assertEquals(abceConfiguration.getTokensFile().getName(), tokensFilename);
        assertEquals(abceConfiguration.getDefaultImagePath(), defaultImagePath);
        assertEquals(abceConfiguration.getImageCacheDir().getName(), imageCacheDir);
    } catch (ConfigurationException e) {
        throw new RuntimeException("Could not load property configuration", e);
    }
}

From source file:voldemort.ServerTestUtils.java

public static VoldemortConfig createServerConfigWithDefs(boolean useNio, int nodeId, String baseDir,
        Cluster cluster, List<StoreDefinition> stores, Properties properties) throws IOException {

    File clusterXml = new File(TestUtils.createTempDir(), "cluster.xml");
    File storesXml = new File(TestUtils.createTempDir(), "stores.xml");

    ClusterMapper clusterMapper = new ClusterMapper();
    StoreDefinitionsMapper storeDefMapper = new StoreDefinitionsMapper();

    FileWriter writer = new FileWriter(clusterXml);
    writer.write(clusterMapper.writeCluster(cluster));
    writer.close();/*from  ww  w. j  ava  2s .  co  m*/

    writer = new FileWriter(storesXml);
    writer.write(storeDefMapper.writeStoreList(stores));
    writer.close();

    return createServerConfig(useNio, nodeId, baseDir, clusterXml.getAbsolutePath(),
            storesXml.getAbsolutePath(), properties);

}

From source file:com.respam.comniq.models.MovieListParser.java

public void JSONWriter(JSONArray JSONarr) {
    try {/*from  www.  ja  va 2s .c o m*/
        String path = System.getProperty("user.home") + File.separator + "comniq" + File.separator + "output";
        File userOutDir = new File(path);
        if (userOutDir.exists()) {
            System.out.println(userOutDir + " already exists");
        } else if (userOutDir.mkdirs()) {
            System.out.println(userOutDir + " was created");
        } else {
            System.out.println(userOutDir + " was not created");
        }

        FileWriter localList = new FileWriter(userOutDir + File.separator + "LocalList.json");
        localList.write(JSONarr.toJSONString());
        localList.flush();
        localList.close();
        System.out.println("Local Processing Complete");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

@Test
public void testFileArchived() throws Exception {
    File src = new File(randName + ".txt");
    FileWriter fw = new FileWriter(src);
    fw.write("12345");
    fw.close();/* w  w w . ja v  a  2  s  . co m*/
    CompressBackupUtil.tar(src, dest);
    Assert.assertTrue("No destination archive created", dest.exists());
    TarArchiveInputStream tai = new TarArchiveInputStream(
            new GZIPInputStream(new BufferedInputStream(new FileInputStream(dest))));
    ArchiveEntry entry = tai.getNextEntry();
    Assert.assertNotNull("No entry found in destination archive", entry);
    Assert.assertEquals("Entry has wrong size", 5, entry.getSize());
}

From source file:idp.file_operator.java

public void save_csv(int file_count) {
    try {//from w  ww.j a v a 2s .  c  om
        for (int i = 0; i < file_count; i++) {
            FileWriter writer = new FileWriter(path + gui.jTabbedPane1.getTitleAt(i));
            writer.write(gui.jta.get(i).getText());
            writer.close();
        }
    } catch (IOException ex) {
    }
}

From source file:info.balajeerc.spellspider.PageChecker.java

private PageChecker(OutputQueue outputQueue) {
    languageTool = null;/* www.java  2  s. c  om*/
    this.outputQueue = outputQueue;
    outputFilePath = FilenameUtils.concat(outputQueue.getOutputDirectory(), "errors.csv");
    try {
        languageTool = new JLanguageTool(Language.AMERICAN_ENGLISH);
        languageTool.activateDefaultPatternRules();
        //Write the header for the output file
        FileWriter outFile = new FileWriter(outputFilePath);
        outFile.write("Url, Description, In Text, Error, Category\n");
        outFile.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:hudson.lifecycle.WindowsServiceLifecycle.java

/**
 * On Windows, hudson.war is locked, so we place a new version under a special name,
 * which is picked up by the service wrapper upon restart.
 *//*from www.java2  s  .co m*/
@Override
public void rewriteHudsonWar(File by) throws IOException {
    File rootDir = Hudson.getInstance().getRootDir();
    File copyFiles = new File(rootDir, "hudson.copies");

    FileWriter w = new FileWriter(copyFiles, true);
    w.write(by.getAbsolutePath() + '>' + getHudsonWar().getAbsolutePath() + '\n');
    w.close();
}

From source file:mn.EngineForge.module.player.java

public void saveRegisteration() throws IOException {
    JSONObject reg = new JSONObject();
    reg.put("ID", id);
    reg.put("USERNAME", username);
    reg.put("PASSWORD", password);
    reg.put("REG_DATE", null);
    reg.put("LAST_LOGIN", null);
    reg.put("POSITION", null);
    /* JSON ARRAY NOTE/*from   w  w  w .  j  a v a2 s  .  c  o  m*/
    JSONArray company = new JSONArray();
    company.add("Compnay: eBay");
    company.add("Compnay: Paypal");
    company.add("Compnay: Google");
    reg.put("Company List", company);
    */
    FileWriter file = new FileWriter(this.path);
    try {
        file.write(reg.toJSONString());
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        file.flush();
        file.close();
    }
}

From source file:facebook4j.internal.http.MockHttpClientWrapper.java

private void registerMockJSON(String json) throws IOException {
    String baseDir = System.getProperty("user.dir");
    if (!baseDir.endsWith("/facebook4j-core")) {
        baseDir += "/facebook4j-core";
    }/*from  ww  w. j a v a 2  s . c  o  m*/
    File file = new File(baseDir + "/src/test/resources/" + mockJSONResourceName);
    new File(file.getParent()).mkdirs();
    FileWriter writer = new FileWriter(file);
    writer.write(json);
    writer.close();
}

From source file:com.googlecode.t7mp.util.CommonsSetupUtilTest.java

@Before
public void setUp() throws IOException {
    catalinaBaseDir = Files.createTempDir();

    source = File.createTempFile("source", ".tmp");
    source.deleteOnExit();/*from   ww w . j  ava 2 s .c o m*/
    target = File.createTempFile("target", ".tmp");
    target.deleteOnExit();
    FileWriter sourceWriter = new FileWriter(source);
    sourceWriter.write(MESSAGE);
    sourceWriter.close();
}