Example usage for java.io Writer append

List of usage examples for java.io Writer append

Introduction

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

Prototype

public Writer append(char c) throws IOException 

Source Link

Document

Appends the specified character to this writer.

Usage

From source file:de.dfki.km.perspecting.obie.corpus.LabeledTextCorpus.java

/**
 * Writes a single example to a corpus file.
 * /*from w ww.  j av a  2  s  .  com*/
 * @param corpusWriter
 * @param exampleLabel
 * @param exampleName
 * @param exampleData
 * @throws IOException
 */
public static void serializeExample(Writer corpusWriter, String exampleLabel, String exampleName,
        List<String> exampleData) throws IOException {
    if (!exampleData.isEmpty()) {

        corpusWriter.append(exampleName);
        corpusWriter.append(SPACE);
        corpusWriter.append(exampleLabel);
        for (String ft : exampleData) {

            corpusWriter.append(SPACE);
            corpusWriter.append(ft);
        }
        corpusWriter.append(NEWLINE);
    }
}

From source file:org.apache.hyracks.maven.license.LicenseUtil.java

private static void doTrim(Writer out, BufferedReader reader, int extraPadding, int wrapLength)
        throws IOException {
    boolean head = true;
    int empty = 0;
    for (String line = reader.readLine(); line != null; line = reader.readLine()) {
        if ("".equals(line.trim())) {
            if (!head) {
                empty++;/*from   w w w .ja v  a2  s  .  co m*/
            }
        } else {
            head = false;
            for (; empty > 0; empty--) {
                out.append('\n');
            }
            String trimmed = line.substring(extraPadding);
            int leadingWS = trimmed.length() - trimmed.trim().length();
            while (trimmed.length() > wrapLength) {
                int cut = trimmed.lastIndexOf(' ', wrapLength);
                cut = Math.max(cut, trimmed.lastIndexOf('\t', wrapLength));
                if (cut != -1) {
                    out.append(trimmed.substring(0, cut));
                    out.append('\n');
                    trimmed = trimmed.substring(cut + 1);
                } else {
                    out.append(trimmed.substring(0, wrapLength));
                    out.append('\n');
                    trimmed = trimmed.substring(wrapLength);
                }
                for (int i = 0; i < leadingWS; i++) {
                    trimmed = ' ' + trimmed;
                }
            }
            out.append(trimmed);
            empty++;
        }
    }
}

From source file:dataGen.DataGen.java

/**
 * Save the Date with the FileWriter// w w w. ja va  2s .  c  o  m
 * @param values
 * @param fw
 * @param nf
 * @throws IOException
 */
public static void saveData(TupleList values, Writer fw, NumberFormat nf) throws IOException {
    for (int i = 0; i < values.size(); i++) {
        String row = i + 1 + " ";
        //String row = "";

        for (int j = 0; j < values.get(i).size(); j++) {
            row = row + nf.format(values.get(i).getValue(j)) + " ";
        }
        fw.write(row);
        fw.append(System.getProperty("line.separator"));
    }
    fw.close();
}

From source file:net.officefloor.plugin.web.http.server.HttpServerAutoWireOfficeFloorSourceTest.java

/**
 * Writes the response.//from  w  w  w. ja va  2  s.  c om
 * 
 * @param response
 *            Response.
 * @param connection
 *            {@link ServerHttpConnection}.
 */
private static void writeResponse(String response, ServerHttpConnection connection) throws IOException {
    Writer writer = new OutputStreamWriter(connection.getHttpResponse().getEntity());
    writer.append(response);
    writer.flush();
}

From source file:dataGen.DataGen.java

/**
 * Saves the Data/* www  . j  a  va2  s  . com*/
 * @param values
 *       The values which should be saved.
 * @param fw
 *       The File-Writer including the File location
 * @param nf
 *       How should the data get formatted?
 * @throws IOException
 *       If Stream to a File couldn't be written/closed 
 */
public static void saveData(Array2DRowRealMatrix values, Writer fw, NumberFormat nf) throws IOException {
    for (int i = 0; i < values.getRowDimension(); i++) {
        String row = i + 1 + " ";
        //String row = "";

        for (int j = 0; j < values.getColumnDimension(); j++) {
            row = row + nf.format(values.getEntry(i, j)) + " ";
        }
        fw.write(row);
        fw.append(System.getProperty("line.separator"));
    }
    fw.close();
}

From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java

@Nullable
private static String buildBrokenAppFilter(Context context, File folder) {
    try {/*  w w w .  j  a v a  2 s  .  c om*/
        AssetManager asset = context.getAssets();
        InputStream stream = asset.open("appfilter.xml");
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(stream);
        NodeList list = doc.getElementsByTagName("item");

        File fileDir = new File(folder.toString() + "/" + "broken_appfilter.xml");
        Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8"));

        boolean first = true;
        for (int i = 0; i < list.getLength(); i++) {
            Node nNode = list.item(i);
            if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                Element eElement = (Element) nNode;

                if (first) {
                    first = false;
                    out.append("<!-- BROKEN APPFILTER -->");
                    out.append("\n\n\n");
                }

                int drawable = context.getResources().getIdentifier(eElement.getAttribute("drawable"),
                        "drawable", context.getPackageName());
                if (drawable == 0) {
                    out.append("Activity : ").append(
                            eElement.getAttribute("component").replace("ComponentInfo{", "").replace("}", ""));
                    out.append("\n");
                    out.append("Drawable : ").append(eElement.getAttribute("drawable"));
                    out.append("\n");
                    out.append("Reason : Drawable Not Found!");
                    out.append("\n\n");
                }
            }
        }
        out.flush();
        out.close();

        return fileDir.toString();
    } catch (Exception | OutOfMemoryError e) {
        Log.d(Tag.LOG_TAG, Log.getStackTraceString(e));
    }
    return null;
}

From source file:com.sshtools.common.vomanagementtool.common.VOHelper.java

private static void appendLineToFavourites(String line) throws IOException {
    Writer output;
    output = new BufferedWriter(new FileWriter(favouritesFile, true));
    output.append(line + "\n");
    output.close();//from w w w  . java 2  s  .c  o m
}

From source file:hu.qgears.xtextdoc.util.EscapeString.java

public static void escapeHtml(Writer out, String str) throws IOException {
    for (int i = 0; i < str.length(); ++i) {
        char ch = str.charAt(i);
        switch (ch) {
        case '<':
            out.append("&lt;");
            break;
        case '>':
            out.append("&gt;");
            break;
        case '&':
            out.append("&amp;");
            break;
        case '"':
            out.append("&quot;");
            break;
        default:/*from  www.  ja  v a 2 s  .c  o  m*/
            out.append(ch);
            break;
        }
    }
}

From source file:org.onehippo.forge.jcrshell.console.Terminal.java

public static final void run(InputStream input, OutputStream output) {
    String cr = System.getProperty("line.separator");
    Writer writer = new OutputStreamWriter(output);
    BufferedReader br = new BufferedReader(new InputStreamReader(input));
    try {//  w ww . j  a v  a2  s. c o m
        consoleReader = new ConsoleReader(new FileInputStream(FileDescriptor.in), new PrintWriter(writer), null,
                new UnsupportedTerminal());
        while (br.ready()) {
            String line = br.readLine();
            if (line != null && !line.startsWith("#") && line.trim().length() > 0) {
                writer.append("Executing: ").append(line).append(cr);
                writer.flush();
                try {
                    if (!handleCommand(line)) {
                        writer.append("Command failed, exiting..").append(cr);
                        handleCommand("Exit" + cr);
                        break;
                    }
                } catch (JcrShellShutdownException e) {
                    break;
                }
            }
        }
        writer.append("Finished.").append(cr).flush();
    } catch (IOException e) {
        PrintWriter pw = new PrintWriter(writer);
        e.printStackTrace(pw);
        pw.flush();
    } finally {
        IOUtils.closeQuietly(input);
        IOUtils.closeQuietly(output);
        JcrWrapper.logout();
    }
}

From source file:cz.lbenda.dataman.db.ExportTableData.java

/** Write rows to CSV file
 * @param sqlQueryRows rows//from   w ww .  j  a  v a 2  s  .c  o m
 * @param writer writer where are data write */
public static void writeSqlQueryRowsToTXT(SQLQueryRows sqlQueryRows, Writer writer) throws IOException {
    String joined = sqlQueryRows.getMetaData().getColumns().stream()
            .map(cd -> fixedString(cd.getName(), cd.getSize())).collect(Collectors.joining(""));
    writer.append(joined).append(Constants.CSV_NEW_LINE_SEPARATOR);
    for (RowDesc row : sqlQueryRows.getRows()) {
        joined = sqlQueryRows.getMetaData().getColumns().stream()
                .map(cd -> fixedString(row.getColumnValueStr(cd), cd.getSize()))
                .collect(Collectors.joining(""));
        writer.append(joined).append(Constants.CSV_NEW_LINE_SEPARATOR);
        writer.flush();
    }
}