Example usage for java.io BufferedWriter append

List of usage examples for java.io BufferedWriter append

Introduction

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

Prototype

public Writer append(CharSequence csq) throws IOException 

Source Link

Document

Appends the specified character sequence to this writer.

Usage

From source file:br.bireme.ngrams.NGrams.java

private static void writeOutput(final Parameters parameters, final Set<Result> results,
        final BufferedWriter writer) throws IOException {
    assert parameters != null;
    assert results != null;
    assert writer != null;

    boolean first = true;

    writer.newLine();/*from w  ww .  j  a va  2 s .  com*/
    for (String pipe : results2pipe(parameters, results)) {
        if (first) {
            first = false;
        } else {
            writer.newLine();
        }
        writer.append(pipe);
    }
}

From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java

/**
 * Upload a single file to the test bucket.
 * @throws java.lang.Exception/*  ww w  .  j a va 2s .  c  om*/
 */
@Test
public void A001_uploadFile() throws Exception {
    String currAccountStr = testProperties.getProperty("s3.access.id");
    String currKey = testProperties.getProperty("s3.access.secret");
    String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name");
    String currHost = testProperties.getProperty("s3.host");
    String currRegion = testProperties.getProperty("s3.region");
    String currFileNameStr;

    File temp = File.createTempFile("uploadFile01", ".tmp");
    try (FileWriter fw = new FileWriter(temp)) {
        BufferedWriter bw = new BufferedWriter(fw);
        bw.append("testing...");
        bw.flush();
    }

    SS3FileProvider currSS3 = new SS3FileProvider();

    // Optional set endpoint
    //currSS3.setEndpoint(currHost);

    // Optional set region
    //currSS3.setRegion(currRegion);

    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(SS3Constants.S3SCHEME, currSS3);
    currMan.addProvider("file", new DefaultLocalFileProvider());
    currMan.init();

    StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey);
    FileSystemOptions opts = new FileSystemOptions();
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

    currFileNameStr = "test01.tmp";
    String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr,
            currFileNameStr);
    FileObject currFile = currMan.resolveFile(currUriStr, opts);
    FileObject currFile2 = currMan.resolveFile(String.format("file://%s", temp.getAbsolutePath()));

    currFile.copyFrom(currFile2, Selectors.SELECT_SELF);
    temp.delete();
}

From source file:com.pieframework.runtime.utils.azure.CsdefGenerator.java

private void printFooter(BufferedWriter out) {
    String footer = "</ServiceDefinition>";
    try {//  w w  w  .  j a v a2 s. c  om
        out.append(footer);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.kalypso.wspwin.core.WspCfg.java

private void writeContent() throws IOException {
    final File wspCfgFile = m_project.getWspCfgFile();

    final BufferedWriter pw = new BufferedWriter(new FileWriter(wspCfgFile));

    final int numProfiles = m_profProj.getProfiles().length;
    final int yyyy = 0;
    pw.append(String.format("%5d %4d %4d %s%n", numProfiles, m_zustaende.size(), yyyy, getType().getCode())); //$NON-NLS-1$

    for (final WspWinZustand zustand : m_zustaende) {
        final ZustandBean zustandBean = zustand.getBean();
        pw.append(zustandBean.formatLine()).append(SystemUtils.LINE_SEPARATOR);
    }//from   w  ww  .j  av a2s.c  o m

    pw.close();
}

From source file:org.openengsb.openengsbplugin.ExtractDocSourceMojo.java

private void extractAnnotatedCode(File file, AnnotatedSourceExtractor extractor) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
    String line = null;//w ww .j av a 2s  .  c o  m
    boolean extract = false;
    BufferedWriter writer = null;
    while ((line = reader.readLine()) != null) {
        if (extract) {
            if (extractor.isStopLine(line)) {
                closeFile(writer);
                extract = false;
                writer = null;
                continue;
            } else {
                writer.append(line);
                writer.newLine();
            }
        } else {
            if (extractor.isStartLine(line)) {
                String name = extractor.extractTargetFilenameFromLine(line);
                if (StringUtils.isEmpty(name)) {
                    continue;
                }
                extract = true;
                writer = createXiIncludeFile(name, extractor.getLanguage());
            }
        }
    }
    if (writer != null) {
        closeFile(writer);
    }
}

From source file:com.github.niltz.maven.plugins.mongodb.AbstractMongoDBMojo.java

/**
 * //ww  w. ja  va  2  s.com
 * @param outputFileWriter
 * @param scriptFile
 * @param scriptData
 * @throws IOException
 */
private void appendScriptToFileWriter(BufferedWriter outputFileWriter, File scriptFile, StringBuffer scriptData)
        throws IOException {
    outputFileWriter.append("//").append("\n");
    outputFileWriter.append("// -------------------- " + scriptFile.getName()).append("\n");
    outputFileWriter.append("//").append("\n");
    outputFileWriter.append(scriptData.toString());
    outputFileWriter.flush();
}

From source file:com.qcadoo.maven.plugins.tomcat.TomcatMojo.java

private void updateSetenvShForSaas() throws IOException {
    BufferedWriter writer = null;

    try {/*from   www  .  j  a v  a2s.  c  om*/
        writer = new BufferedWriter(new FileWriter(new File(rootDirectory, "bin/setenv.sh"), true));
        writer.append("JAVA_OPTS=\"$JAVA_OPTS -Dspring.profiles.active=saas\"\n");
    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:ie.pars.nlp.sketchengine.interactions.WordlistSKEInteraction.java

/**
 * Get all the results and dump it into files this method can be changed so
 * Here the difference is that all the res are written into one
 *
 * The same parser as freq list can be used here too
 *
 * @throws UnsupportedEncodingException//ww w.  j  a  va  2 s.  c  o  m
 * @throws IOExceptionsket
 * @throws Exception
 */
public void getItemFrequencyList() throws UnsupportedEncodingException, IOException, Exception {
    HttpClient sessionID = super.getSessionID();

    BufferedWriter writer;// this.writer;

    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(this.fileOutput),
            StandardCharsets.UTF_8);
    writer = new BufferedWriter(outputStreamWriter);
    if (!writeParsed) {
        writer.append("{\"results\": [\n");
    }
    int pageNumer = 1;
    while (true) {
        JSONObject jsonObjP = super.getHTTP(sessionID, encodeFreqQuery(pageNumer));
        //System.out.println(jsonObjP);
        if (!writeParsed) {
            writer.append(jsonObjP.toString(1));
        } else {
            WordlistMethodJsonParser fjpm = new WordlistMethodJsonParser(jsonObjP.toString());
            FrequencyLine fl;

            while ((fl = fjpm.getNext()) != null) {
                totalFreq += fl.getFreq();
                countItemFetched++;
                writer.append(fl.toStringLine()).append("\n");

            }
            //   writer.flush();

        }
        boolean hasError = jsonObjP.has("error");
        if (hasError) {
            String message = (String) jsonObjP.get("error");
            if ("Empty list".equals(message)) {
                System.out.println("No result for current query: " + this.query); // retrun null etc
                break;
            } else {
                System.out.println("* NOT SEEN * " + jsonObjP.toString(1));
                throw new Exception("not seen " + jsonObjP.toString(1));
            }
        } else {
            int isLastPage = 0;

            //                int finished = (int) jsonObjP.get("finished");
            if (jsonObjP.has("lastpage")) {
                isLastPage = (int) jsonObjP.get("lastpage");
                //System.out.println("** IS Last TO GO  " + isLastPage);
                if (isLastPage == 0) {
                    if (!writeParsed) {
                        writer.append(",");
                    }
                    pageNumer++;
                } else {
                    //System.out.println("Going to break because last page is not 0");
                    break;
                }
            }

        }
    }
    if (!writeParsed) {
        writer.append("]" + "}"); // to the end the json file}
    }

    writer.flush();
    writer.close();

}

From source file:com.qcadoo.maven.plugins.tomcat.TomcatMojo.java

private void updateSetenvBatForSaas() throws IOException {
    BufferedWriter writer = null;

    try {/*  w  ww.ja  va  2  s.c om*/
        writer = new BufferedWriter(new FileWriter(new File(rootDirectory, "bin/setenv.bat"), true));
        writer.append("set \"JAVA_OPTS=%JAVA_OPTS% -Dspring.profiles.active=saas\"\n");
    } finally {
        IOUtils.closeQuietly(writer);
    }
}

From source file:com.pieframework.runtime.utils.azure.CsdefGenerator.java

private void printImports(BufferedWriter out, Role r, boolean includeForwarder) {
    //print imports
    try {/*  ww  w  . j  a v  a  2s .  c  o m*/
        out.append("<Imports>");
        //out.append("<Import moduleName=\"Diagnostics\" />");
        out.append("<Import moduleName=\"RemoteAccess\" />");
        if (includeForwarder) {
            out.append("<Import moduleName=\"RemoteForwarder\" />");
        }
        out.append("</Imports>");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}