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:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java

private void writeHeader(Writer writer) throws IOException {
    // Bash Header
    writer.append("#!/bin/bash").append(DOUBLE_NEWLINE);
    writer.append("# Generated by airline BashCompletionGenerator").append(DOUBLE_NEWLINE);
}

From source file:dk.deck.remoteconsole.SshRemoteConsole.java

private void output(String data, Writer liveOutput, StringBuilder output) throws IOException {
    if (liveOutput != null) {
        liveOutput.append(data);
        liveOutput.flush();/* w ww.j  a  v a  2 s  .  c  om*/
    }
    if (output.toString().length() < MAX_CONTENT_LENGTH) {
        output.append(data);
    }
}

From source file:org.teavm.tooling.TeaVMTool.java

private void additionalJavaScriptOutput(Writer writer) throws IOException {
    if (mainClass != null) {
        writer.append("main = $rt_mainStarter(main);\n");
    }/*from w  w  w .  j  av a 2s. co  m*/

    if (debugInformationGenerated) {
        assert debugEmitter != null;
        DebugInformation debugInfo = debugEmitter.getDebugInformation();
        File debugSymbolFile = new File(targetDirectory, getResolvedTargetFileName() + ".teavmdbg");
        try (OutputStream debugInfoOut = new BufferedOutputStream(new FileOutputStream(debugSymbolFile))) {
            debugInfo.write(debugInfoOut);
        }
        generatedFiles.add(debugSymbolFile);
        log.info("Debug information successfully written");
    }
    if (sourceMapsFileGenerated) {
        assert debugEmitter != null;
        DebugInformation debugInfo = debugEmitter.getDebugInformation();
        String sourceMapsFileName = getResolvedTargetFileName() + ".map";
        writer.append("\n//# sourceMappingURL=").append(sourceMapsFileName);
        File sourceMapsFile = new File(targetDirectory, sourceMapsFileName);
        try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(sourceMapsFile), "UTF-8")) {
            debugInfo.writeAsSourceMaps(sourceMapsOut, "src", getResolvedTargetFileName());
        }
        log.info("Source maps successfully written");
    }
    if (sourceFilesCopied) {
        copySourceFiles();
        log.info("Source files successfully written");
    }

    if (runtime == RuntimeCopyOperation.SEPARATE) {
        resourceToFile("org/teavm/backend/javascript/runtime.js", "runtime.js");
    }
    if (mainPageIncluded) {
        String text;
        try (Reader reader = new InputStreamReader(
                classLoader.getResourceAsStream("org/teavm/tooling/main.html"), "UTF-8")) {
            text = IOUtils.toString(reader).replace("${classes.js}", getResolvedTargetFileName());
        }
        File mainPageFile = new File(targetDirectory, "main.html");
        try (Writer mainPageWriter = new OutputStreamWriter(new FileOutputStream(mainPageFile), "UTF-8")) {
            mainPageWriter.append(text);
        }
    }
}

From source file:org.formix.dsx.XmlElement.java

private void writeAttribute(Writer writer, String name) throws IOException {
    writer.append(name);
    String value = this.attributes.get(name);
    if (value != null) {
        writer.append("=\"");
        writer.append(StringEscapeUtils.escapeXml(value));
        writer.append("\"");
    }/*from w  ww  .  j  a  v a  2 s  . c  o  m*/
}

From source file:nl.armatiek.xslweb.saxon.functions.ExtensionFunctionCall.java

protected void serialize(Sequence seq, Writer w, Properties outputProperties) throws XPathException {
    try {//from   ww  w.ja va  2 s .c o m
        SequenceIterator iter = seq.iterate();
        Item item;
        while ((item = iter.next()) != null) {
            if (item instanceof NodeInfo) {
                serialize((NodeInfo) item, new StreamResult(w), outputProperties);
            } else {
                w.append(item.getStringValue());
            }
        }
    } catch (Exception e) {
        throw new XPathException(e);
    }
}

From source file:org.formix.dsx.XmlElement.java

@Override
public void write(Writer writer) throws IOException {
    writer.append("<");
    writer.append(this.name);

    for (String name : this.attributes.keySet()) {
        writer.write(' ');
        this.writeAttribute(writer, name);
    }//from  w  w w .j ava2  s .  c o m

    if (this.childs.size() == 0)
        writer.append("/");

    writer.append(">");

    for (XmlContent content : this.childs)
        content.write(writer);

    if (this.childs.size() > 0) {
        writer.append("</");
        writer.append(this.name);
        writer.append(">");
    }
}

From source file:com.bizosys.hsearch.index.DocMeta.java

public void toXml(Writer writer) throws IOException {
    writer.append("<meta>");

    if (StringUtils.isNonEmpty(this.docType))
        writer.append("<type>").append(this.docType).append("</type>");
    if (0 != this.weight)
        writer.append("<weight>").append(new Integer(this.weight).toString()).append("</weight>");
    if (null != this.createdOn)
        writer.append("<created>").append(this.createdOn.toString()).append("</created>");
    if (null != this.validTill)
        writer.append("<validtill>").append(this.validTill.toString()).append("</validtill>");
    if (StringUtils.isNonEmpty(this.geoHouse))
        writer.append("<geo>").append(this.geoHouse).append("</geo>");
    if (null != this.modifiedOn)
        writer.append("<modified>").append(this.modifiedOn.toString()).append("</modified>");
    if (StringUtils.isNonEmpty(this.team))
        writer.append("<team>").append(this.team).append("</team>");

    if (null != this.tags) {
        writer.append("<tags>").append(
                this.tags.replace(DataConstants.TAG_SEPARATOR_STORED, DataConstants.TAG_SEPARATOR_SHOWN))
                .append("</tags>");
    }//from   w  w w  .  ja  v a  2  s .  c  o m
    if (null != this.socialText) {
        writer.append("<social>").append(
                this.socialText.replace(DataConstants.TAG_SEPARATOR_STORED, DataConstants.TAG_SEPARATOR_SHOWN))
                .append("</social>");
    }
    if (StringUtils.isNonEmpty(this.state))
        writer.append("<state>").append(this.state).append("</state>");
    writer.append("<secure>");
    if (securityHigh)
        writer.append("true");
    else
        writer.append("false");
    writer.append("</secure>");
    if (!sentimentPositive) {
        writer.append("<sentiment>false</sentiment>");
    }
    writer.append("</meta>");
}

From source file:com.github.rvesse.airline.help.cli.bash.BashCompletionGenerator.java

private void writeHelperFunctions(Writer writer) throws IOException {
    // Helper functions
    writer.append("containsElement () {\n");
    indent(writer, 2);/* w  ww . j av  a2  s.  c o m*/
    writer.append("# This function from http://stackoverflow.com/a/8574392/107591\n");
    indent(writer, 2);
    writer.append("local e\n");
    indent(writer, 2);
    writer.append("for e in \"${@:2}\"; do [[ \"$e\" == \"$1\" ]] && return 0; done\n");
    indent(writer, 2);
    writer.append("return 1\n");
    writer.append("}\n\n");
}

From source file:org.apache.hyracks.maven.license.freemarker.LoadFileDirective.java

@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {

    String fileParam = null;/* w  w  w  . j av  a 2 s . c o  m*/
    String defaultParam = null;
    boolean trimParam = false;

    for (Object paramObj : params.entrySet()) {
        Map.Entry param = (Map.Entry) paramObj;

        String paramName = (String) param.getKey();
        TemplateModel paramValue = (TemplateModel) param.getValue();

        switch (paramName) {
        case PARAM_FILE:
            if (paramValue instanceof TemplateScalarModel) {
                fileParam = ((TemplateScalarModel) paramValue).getAsString();
            } else {
                throw new TemplateModelException(PARAM_FILE + " must be a string");
            }
            break;

        case PARAM_DEFAULT_TEXT:
            if (paramValue instanceof TemplateScalarModel) {
                defaultParam = ((TemplateScalarModel) paramValue).getAsString();
            } else {
                throw new TemplateModelException(PARAM_DEFAULT_TEXT + " must be a string");
            }
            break;

        case PARAM_TRIM:
            if (paramValue instanceof TemplateBooleanModel) {
                trimParam = ((TemplateBooleanModel) paramValue).getAsBoolean();
            } else {
                throw new TemplateModelException(PARAM_TRIM + " must be a boolean");
            }
            break;

        default:
            throw new TemplateModelException("Unknown param: " + paramName);
        }
    }
    if (fileParam == null) {
        throw new TemplateModelException("The required \"" + PARAM_FILE + "\" parameter" + "is missing.");
    }
    if (body != null) {
        throw new TemplateModelException("Body is not supported by this directive");
    }
    Writer out = env.getOut();
    File baseDir = ((FileTemplateLoader) ((Configuration) env.getTemplate().getParent())
            .getTemplateLoader()).baseDir;
    File file = new File(baseDir, fileParam);
    if (file.exists()) {
        if (trimParam) {
            LicenseUtil.readAndTrim(out, file);
            out.write('\n');
        } else {
            IOUtils.copy(new FileInputStream(file), out, StandardCharsets.UTF_8);
        }
    } else if (defaultParam != null) {
        out.append(defaultParam).append("\n");
    } else {
        throw new IOException("File not found: " + file);
    }
}

From source file:net.pandoragames.far.ui.MimeConfParser.java

private void writeNode(MimeTreeNode node, Writer writer, int indent) throws IOException {
    String indention = "";
    if (indent > 0) {
        StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < indent; i++)
            buffer.append('\t');
        indention = buffer.toString();/*ww w. j  a  va 2s  .  co  m*/
    }
    writer.append(indention).append('<').append(node.getNodeName());
    if (node.isMimeType())
        writer.append(" name='").append(node.getName()).append("'");
    if (node.getEncoding() != null)
        writer.append(" encoding='").append(node.getEncoding().name()).append("'");
    if (FileType.BUILDIN.FILE.name().equals(node.getName()))
        writer.append(" xmlns='").append(XMLNS).append("'");
    // file extensions
    if (node.isMimeType() && node.getFileExtensions().size() > 0) {
        writer.append(" extensions='");
        for (int i = 0; i < node.getFileExtensions().size(); i++) {
            if (i > 0)
                writer.append(' ');
            writer.append(node.getFileExtensions().get(i));
        }
        writer.append("'");
    }
    // children
    if (node.getChildren().size() > 0) {
        writer.append('>');
        if (indent >= 0)
            writer.append('\n');
        for (MimeTreeNode child : node.getChildren()) {
            writeNode(child, writer, indent >= 0 ? indent + 1 : indent);
        }
        writer.append(indention).append("</").append(node.getNodeName()).append('>');
    } else {
        writer.append("/>");
    }
    if (indent >= 0)
        writer.append('\n');
}