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:org.ow2.mind.doc.DocumentationIndexGenerator.java

public void generateOverviewSummary(final File targetDir) throws IOException {
    overviewSummaryTemplate.reset();/*from  ww w . j  ava 2 s  .  c  o  m*/
    overviewSummaryTemplate.setAttribute("packages", packages);
    overviewSummaryTemplate.setAttribute("docTitle", docTitle);
    overviewSummaryTemplate.registerRenderer(String.class, new HTMLRenderer());

    setPackageDocumentation("", overviewFile, overviewSummaryTemplate);

    final File targetFile = new File(targetDir, OVERVIEW_SUMMARY_HTML);
    final FileWriter writer = new FileWriter(targetFile);
    writer.append(overviewSummaryTemplate.toString());
    writer.close();
}

From source file:com.ibm.responseclassifier.MainPage.java

public void classifyUpload() throws Exception {
    try {//from   ww  w. java2  s .c  om
        fileDownloadPath = servletContext.getRealPath("/") + fileUpload.getFileName() + "_download";

        FileReader fr = new FileReader(fileUploadPath);
        BufferedReader br = new BufferedReader(fr);
        FileWriter fw = new FileWriter(fileDownloadPath, false);

        String line = "";
        String classification = "";
        while ((line = br.readLine()) != null) {
            classification = getWatsonClassification(line);
            fw.append(line + "," + classification + "\n");
        }

        /* THIS SNIPPET READS THE UPLOADED FILE INTO THE VARIABLE 'fileUploadContent'
        fileUploadContent = fileUpload.getFileName();
                
        String line = "";
        while((line = br.readLine()) != null)
        {
           fileUploadContent = fileUploadContent + "<br/>" + line;
        }
          */
        br.close();
        fw.close();
    } catch (Exception e) {
        throw e;
    }
}

From source file:org.ow2.mind.doc.DocumentationIndexGenerator.java

public void generateOverviewFrame(final File targetDir) throws IOException {
    overviewFrameTemplate.reset();/*  w  ww .  j  a  va2 s  . com*/
    overviewFrameTemplate.setAttribute("packages", packages);
    overviewFrameTemplate.registerRenderer(String.class, new HTMLRenderer());

    final FileWriter writer = new FileWriter(new File(targetDir, OVERVIEW_FRAME_HTML));
    writer.append(overviewFrameTemplate.toString());
    writer.close();
}

From source file:org.ow2.mind.doc.DocumentationIndexGenerator.java

public void generateAllDefinitionFrame(final File targetDir) throws IOException {

    allDefinitionTemplate.reset();/*from  w  w  w  . j  a va2  s.c  o m*/

    if (!adlDefinitionEntries.isEmpty())
        allDefinitionTemplate.setAttribute("adl", adlDefinitionEntries);
    if (!itfDefinitionEntries.isEmpty())
        allDefinitionTemplate.setAttribute("itf", itfDefinitionEntries);

    final FileWriter writer = new FileWriter(new File(targetDir, ALL_DEF_FRAME_HTML));
    writer.append(allDefinitionTemplate.toString());
    writer.close();

}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.SystemMonitor.java

private void writeStringToLogFile(String text) {
    File root = Environment.getExternalStorageDirectory();
    File file = new File(root, "SystemBatteryMonitor.txt");
    try {/*from   ww w .  j a va 2  s. c  o m*/
        if (!file.exists())
            file.createNewFile();
        FileWriter filewriter = new FileWriter(file, true);
        filewriter.append(text);
        filewriter.close();
    } catch (IOException e) {
        Toast.makeText(this, "Unable to write file: " + e.toString(), Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
}

From source file:org.ow2.mind.doc.DocumentationIndexGenerator.java

/**
 * generate the html frames for all packages.
 * @param targetDir destination directory. Each html page will be in a subdirectory corresponding to the package.
 * @throws IOException/*from   w w w .  j  a va2  s  .  c  o m*/
 */
public void generatePackageFrame(final File targetDir) throws IOException {
    for (final IndexEntry packageEntry : packages) {
        packageFrameTemplate.reset();
        packageFrameTemplate.setAttribute("name", packageEntry.name);
        packageFrameTemplate.setAttribute("summaryFileName", packageEntry.summaryHtmlFileName);
        packageFrameTemplate.setAttribute("pathToRoot",
                HTMLDocumentationHelper.getPackagePathToRoot(packageEntry.name));

        if (!packageEntry.adl.isEmpty())
            packageFrameTemplate.setAttribute("adl", packageEntry.adl);
        if (!packageEntry.itf.isEmpty())
            packageFrameTemplate.setAttribute("itf", packageEntry.itf);

        final File directory = new File(targetDir, PathHelper.packageNameToDirName(packageEntry.name));

        directory.mkdirs();
        final FileWriter writer = new FileWriter(new File(directory, PACKAGE_FRAME_HTML));
        writer.append(packageFrameTemplate.toString());
        writer.close();
    }
}

From source file:org.ow2.mind.doc.DocumentationIndexGenerator.java

/**
 * generate the html frames for all packages.
 * @param targetDir destination directory. Each html page will be in a subdirectory corresponding to the package.
 * @throws IOException/*from w  w w.j av  a2  s  . c  o m*/
 */
public void generatePackageSummary(final File targetDir) throws IOException {
    for (final IndexEntry packageEntry : packages) {
        packageSummaryTemplate.reset();
        packageSummaryTemplate.setAttribute("name", packageEntry.name);
        packageSummaryTemplate.setAttribute("pathToRoot",
                HTMLDocumentationHelper.getPackagePathToRoot(packageEntry.name));
        packageSummaryTemplate.setAttribute("adl", packageEntry.adl);
        packageSummaryTemplate.setAttribute("itf", packageEntry.itf);
        packageSummaryTemplate.registerRenderer(String.class, new HTMLRenderer());

        final File directory = new File(targetDir, PathHelper.packageNameToDirName(packageEntry.name));

        setPackageDocumentation(packageEntry.name, new File(packageEntry.file, PACKAGE_DOC_HTML),
                packageSummaryTemplate);

        directory.mkdirs();
        final FileWriter writer = new FileWriter(new File(directory, PACKAGE_SUMMARY_HTML));
        writer.append(packageSummaryTemplate.toString());
        writer.close();
    }
}

From source file:com.ibm.jaggr.core.impl.cache.GzipCacheImplTest.java

@Test
public void testGetInputStreamLastModified() throws Exception {
    GzipCacheImpl impl = new GzipCacheImpl();
    latch2 = new CountDownLatch(2);
    long oldLastMod = new Date().getTime() - 10000;
    tempfile.setLastModified(oldLastMod);

    EasyMock.replay(mockAggregator, mockCacheManager);
    impl.setAggregator(mockAggregator);// www  . j  a  v  a2 s  .  c om
    MutableInt retLength = new MutableInt();

    // Get the input stream.  Should be a ByteArrayInputStream until
    // the async thread waiting on latch1 gets to write the cache file.
    InputStream is = impl.getInputStream("key", tempfile.toURI(), retLength);
    Assert.assertTrue(is instanceof ByteArrayInputStream);

    // Validate the gzipped data
    Assert.assertEquals(testData, unzipInputStream(is, retLength.getValue()));

    // Validate the cache entry fields
    IGzipCache.ICacheEntry cacheEntry = impl.get("key");
    Assert.assertNotNull(Whitebox.getInternalState(cacheEntry, "bytes"));
    Assert.assertEquals(Long.valueOf(tempfile.lastModified()),
            (Long) Whitebox.getInternalState(cacheEntry, "lastModified"));
    Assert.assertNull(Whitebox.getInternalState(cacheEntry, "ex"));
    Assert.assertNull(Whitebox.getInternalState(cacheEntry, "file"));

    // Now update the last-modified date of the input resource
    FileWriter writer = new FileWriter(tempfile);
    writer.append(newTestData);
    writer.close();

    // Get the input stream again and ensure it returns the updated contents
    is = impl.getInputStream("key", tempfile.toURI(), retLength);
    Assert.assertTrue(is instanceof ByteArrayInputStream);
    Assert.assertEquals(newTestData, unzipInputStream(is, retLength.getValue()));

    // Validate the cache entry fields
    Assert.assertNotSame(cacheEntry, impl.get("key"));
    cacheEntry = impl.get("key");
    Assert.assertNotNull(Whitebox.getInternalState(cacheEntry, "bytes"));
    Assert.assertEquals(Long.valueOf(tempfile.lastModified()),
            (Long) Whitebox.getInternalState(cacheEntry, "lastModified"));
    Assert.assertNull(Whitebox.getInternalState(cacheEntry, "ex"));
    Assert.assertNull(Whitebox.getInternalState(cacheEntry, "file"));

    // now write the cache file to disk
    // now release the cache file writer thread and wait for it to complete
    latch1.countDown();
    latch2.await();

    // The input stream this time should be a FileInputStream
    is = impl.getInputStream("key", tempfile.toURI(), retLength);
    Assert.assertTrue(is instanceof FileInputStream);
    // validate the data
    Assert.assertEquals(newTestData, unzipInputStream(is, retLength.getValue()));

    Assert.assertNull(Whitebox.getInternalState(cacheEntry, "bytes"));
    Assert.assertNull(Whitebox.getInternalState(cacheEntry, "ex"));
    File cacheFile1 = (File) Whitebox.getInternalState(cacheEntry, "file");
    Assert.assertTrue(cacheFile1.getName().startsWith("source.gzip."));
    Assert.assertTrue(cacheFile1.getName().endsWith(".cache"));
    long newTestDataLastMod = cacheFile1.lastModified();
    Assert.assertTrue("oldLastMod = " + oldLastMod + ", newTestDataLastMod = " + newTestDataLastMod,
            Math.abs(oldLastMod - newTestDataLastMod) >= 9000 /* account for rounding on unix */);

    // reset the latches
    latch1 = new CountDownLatch(1);
    latch2 = new CountDownLatch(1);
    // Now update the last-modified date of the input resource
    writer = new FileWriter(tempfile);
    writer.append(newTestData2);
    writer.close();
    tempfile.setLastModified(new Date().getTime() + 10000);

    // The input stream this time should be a ByteArrayInputStream
    is = impl.getInputStream("key", tempfile.toURI(), retLength);
    Assert.assertTrue(is instanceof ByteArrayInputStream);
    Assert.assertNotSame(cacheEntry, impl.get("key"));
    cacheEntry = impl.get("key");
    // validate the data
    Assert.assertEquals(newTestData2, unzipInputStream(is, retLength.getValue()));
    Assert.assertEquals(tempfile.lastModified(), Whitebox.getInternalState(cacheEntry, "lastModified"));

    // now write the cache file to disk
    // now release the cache file writer thread and wait for it to complete
    latch1.countDown();
    latch2.await();

    is = impl.getInputStream("key", tempfile.toURI(), retLength);
    Assert.assertTrue(is instanceof FileInputStream);
    Assert.assertSame(cacheEntry, impl.get("key"));
    Assert.assertEquals(newTestData2, unzipInputStream(is, retLength.getValue()));

    Assert.assertNull(Whitebox.getInternalState(cacheEntry, "bytes"));
    Assert.assertNull(Whitebox.getInternalState(cacheEntry, "ex"));
    File cacheFile2 = (File) Whitebox.getInternalState(cacheEntry, "file");
    Assert.assertTrue(cacheFile2.getName().startsWith("source.gzip."));
    Assert.assertTrue(cacheFile2.getName().endsWith(".cache"));
    Assert.assertFalse(cacheFile1.getName().equals(cacheFile2.getName()));
    long newTestData2LastMod = cacheFile2.lastModified();
    Assert.assertTrue(
            "newTestDataLastMod = " + newTestDataLastMod + ", newTestData2LastMod = " + newTestData2LastMod,
            Math.abs(newTestDataLastMod - newTestData2LastMod) >= 9000 /* account for rounding on unix */);
    Assert.assertEquals(cacheFile1.getName(), deletedCacheFiles.get(0));

}

From source file:com.inovex.zabbixmobile.push.NotificationService.java

private void logNotification(String status, String message, Long triggerid, String source) {
    // Logging incoming notifications for Debuggin
    // timestamp status message triggerid network
    try {/* ww w  . j  av a2 s  .c o  m*/
        File folder = new File(Environment.getExternalStorageDirectory() + "/zax");
        boolean var = false;
        if (!folder.exists()) {
            var = folder.mkdir();
        }
        final String filename = folder.toString() + "/" + "push_logs.csv";
        File csv = new File(filename);
        if (!csv.exists() || !csv.isFile()) {
            csv.createNewFile();
        }
        FileWriter fw = new FileWriter(csv, true);
        String date = Calendar.getInstance().getTime().toString();
        fw.append(date);
        fw.append('\t');
        fw.append(source);
        fw.append('\t');
        fw.append(Long.toString(triggerid));
        fw.append('\t');
        fw.append(status);
        fw.append('\t');
        fw.append(message);
        fw.append('\t');

        ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();

        String net = null;
        switch (activeNetwork.getType()) {
        case ConnectivityManager.TYPE_WIFI:
            String ssid = ((WifiManager) getSystemService(WIFI_SERVICE)).getConnectionInfo().getSSID();
            net = "wifi - ssid: " + ssid;
            break;
        case ConnectivityManager.TYPE_MOBILE:
            net = "mobile";
            break;
        default:
            net = "other network type";
        }
        fw.append(net);
        fw.append("\t\n");
        fw.flush();
        fw.close();
        Log.d(TAG, "writing to logfile " + date + "" + source + " " + status + " " + message + " " + net);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.fusesource.cloudmix.testing.TestController.java

protected void onProfileIdCreated(String profileid) throws IOException {
    String fileName = PROFILE_ID_FILENAME;
    try {// ww  w. j a  v a  2 s  .  c  om
        FileWriter writer = new FileWriter(fileName, true);
        writer.append(profileid);
        writer.append("\n");
        writer.close();
    } catch (IOException e) {
        LOG.error("Failed to write profileId to file: " + fileName);
    }
}