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.bstek.dorado.web.loader.RunModeConsoleStartedMessageOutputter.java

@Override
public void output(Writer writer) throws Exception {
    String runMode = Configure.getString("core.runMode");
    if (StringUtils.isNotEmpty(runMode) && !"production".equalsIgnoreCase(runMode)) {
        writer.append("WARN:\n").append("Dorado is currently running in " + runMode
                + " mode, you may need to change the setting for \"core.runMode\".");
    }// ww w  .j a  v a2s.  c o m
}

From source file:org.sonar.api.profiles.XMLProfileSerializer.java

private void appendRules(RulesProfile profile, Writer writer) throws IOException {
    if (!profile.getActiveRules().isEmpty()) {
        writer.append("<rules>");
        for (ActiveRule activeRule : profile.getActiveRules()) {
            appendRule(activeRule, writer);
        }/*from   www .  ja v a2  s. c om*/
        writer.append("</rules>");
    }
}

From source file:com.palantir.stash.stashbot.servlet.BuildStatusReportingServlet.java

private void printOutput(JSONObject output, HttpServletRequest req, HttpServletResponse res)
        throws IOException {
    res.reset();//from  w  ww  . j a  v  a  2s .  c om
    res.setStatus(200);
    res.setContentType("application/json;charset=UTF-8");
    Writer w = res.getWriter();
    try {
        w.append(output.toString(4));
    } catch (JSONException e) {
        w.append(output.toString());
    }
    w.close();
}

From source file:org.sonar.plugins.csharp.stylecop.profiles.StyleCopProfileExporter.java

private void printRule(Writer writer, StyleCopRule styleCopRule) throws IOException {
    writer.append("                <Rule Name=\"");
    StringEscapeUtils.escapeXml(writer, styleCopRule.getName());
    writer.append("\" SonarPriority=\"");
    StringEscapeUtils.escapeXml(writer, styleCopRule.getPriority());
    writer.append("\">\n");
    writer.append("                    <RuleSettings>\n");
    writer.append("                        <BooleanProperty Name=\"Enabled\">");
    writer.append(styleCopRule.isEnabled() ? "True" : "False");
    writer.append("</BooleanProperty>\n");
    writer.append("                    </RuleSettings>\n");
    writer.append("                </Rule>\n");
}

From source file:gov.nih.nci.ncicb.tcga.dcc.dam.dao.usage.UsageLoggerFileImpl.java

private void log(String msg) throws UsageLoggerException {
    try {/*from   w ww  . j a v a 2 s .  co  m*/
        Writer out = getWriter();
        out.append(msg);
        out.flush();
    } catch (IOException ioe) {
        throw new UsageLoggerException(ioe);
    }
}

From source file:com.stevpet.sonar.plugins.dotnet.resharper.profiles.ReSharperProfileExporter.java

private void printRules(RulesProfile profile, Writer writer) throws IOException {
    //Create a file that matches the format of the ReSharper inspectcode.exe output

    writer.append("<Report>\n");
    writer.append("  <IssueTypes>\n");

    List<ActiveRule> activeRules = profile.getActiveRulesByRepository(getKey());
    List<ReSharperRule> rules = transformIntoReSharperRules(activeRules);

    // print out each rule
    for (ReSharperRule rule : rules) {
        printRule(writer, rule);// w  w  w .  j  a  v  a 2s  . co  m
    }

    writer.append("  </IssueTypes>\n");
    writer.append("</Report>");
}

From source file:com.joliciel.csvLearner.features.BestFeatureFinder.java

public void writeBestFeatures(Writer writer, String outcome, Collection<NameValuePair> bestFeatures) {
    try {/*from   w w w  . ja  v a  2 s .  c  om*/
        writer.append(CSVFormatter.format(outcome) + ",");
        for (NameValuePair pair : bestFeatures) {
            if (!pair.getName().equals(TOTAL_ENTROPY))
                writer.append(CSVFormatter.format(pair.getName()) + ",");
            writer.append(CSVFormatter.format(pair.getValue()) + ",");
        }
        writer.append("\n");
        writer.flush();
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}

From source file:org.apache.sshd.server.FailCommand.java

@Override
public void start(Environment env) throws IOException {
    logger.warn("start(" + errorCode + "): " + errorMsg);

    try {//from  w ww .  j ava2  s.  c  o m
        Writer err = new CloseShieldWriter(new OutputStreamWriter(getErrorStream()));
        try {
            if (StringUtils.isEmpty(errorMsg)) {
                err.append("Status code: ").append(String.valueOf(getErrorCode()));
            } else {
                err.append(errorMsg);
            }
            err.append(SystemUtils.LINE_SEPARATOR);
        } finally {
            err.close();
        }
    } finally {
        ExitCallback cbExit = getExitCallback();
        if (StringUtils.isEmpty(errorMsg)) {
            cbExit.onExit(errorCode);
        } else {
            cbExit.onExit(errorCode, errorMsg);
        }
    }
}

From source file:com.wesley.urban_cuts.services.barber_services.Write_to_file.java

public void write_to_file(String data1, String data2, String data3) {
    Date d = new Date();
    Writer writer = null;
    try {//from   ww w . j a v  a  2 s.  com
        writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream("Urban Cuts Log" + ".txt"), "utf-8"));

        writer.append("");
        writer.append(data1 + "   " + data2 + "   " + data3 + "   " + d);

    } catch (IOException ex) {
        System.out.println("couldn't write to file");
    } finally {
        try {
            writer.close();
        } catch (Exception ex) {
            /*ignore*/}
    }
}

From source file:ca.uhn.fhir.rest.server.RestfulServerUtils.java

public static Object streamResponseAsResource(IRestfulServerDefaults theServer, IBaseResource theResource,
        Set<SummaryEnum> theSummaryMode, int theStausCode, String theStatusMessage,
        boolean theAddContentLocationHeader, boolean respondGzip, RequestDetails theRequestDetails,
        IIdType theOperationResourceId, IPrimitiveType<Date> theOperationResourceLastUpdated)
        throws IOException {
    IRestfulResponse restUtil = theRequestDetails.getResponse();

    // Determine response encoding
    ResponseEncoding responseEncoding = RestfulServerUtils.determineResponseEncodingNoDefault(theRequestDetails,
            theServer.getDefaultResponseEncoding());

    String serverBase = theRequestDetails.getFhirServerBase();
    IIdType fullId = null;//  www.ja  va  2 s  .c  o m
    if (theOperationResourceId != null) {
        fullId = theOperationResourceId;
    } else if (theResource != null) {
        if (theResource.getIdElement() != null) {
            IIdType resourceId = theResource.getIdElement();
            fullId = fullyQualifyResourceIdOrReturnNull(theServer, theResource, serverBase, resourceId);
        }
    }

    if (theAddContentLocationHeader && fullId != null) {
        if (theServer.getFhirContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) {
            restUtil.addHeader(Constants.HEADER_CONTENT_LOCATION, fullId.getValue());
        }
        restUtil.addHeader(Constants.HEADER_LOCATION, fullId.getValue());
    }

    if (theServer.getETagSupport() == ETagSupportEnum.ENABLED) {
        if (fullId != null && fullId.hasVersionIdPart()) {
            restUtil.addHeader(Constants.HEADER_ETAG, "W/\"" + fullId.getVersionIdPart() + '"');
        }
    }

    String contentType;
    if (theResource instanceof IBaseBinary && responseEncoding == null) {
        IBaseBinary bin = (IBaseBinary) theResource;
        if (isNotBlank(bin.getContentType())) {
            contentType = bin.getContentType();
        } else {
            contentType = Constants.CT_OCTET_STREAM;
        }
        // Force binary resources to download - This is a security measure to prevent
        // malicious images or HTML blocks being served up as content.
        restUtil.addHeader(Constants.HEADER_CONTENT_DISPOSITION, "Attachment;");

        return restUtil.sendAttachmentResponse(bin, theStausCode, contentType);
    }

    // Ok, we're not serving a binary resource, so apply default encoding
    if (responseEncoding == null) {
        responseEncoding = new ResponseEncoding(theServer.getFhirContext(),
                theServer.getDefaultResponseEncoding(), null);
    }

    boolean encodingDomainResourceAsText = theSummaryMode.contains(SummaryEnum.TEXT);
    if (encodingDomainResourceAsText) {
        /*
         * If the user requests "text" for a bundle, only suppress the non text elements in the Element.entry.resource
         * parts, we're not streaming just the narrative as HTML (since bundles don't even
         * have one)
         */
        if ("Bundle".equals(theServer.getFhirContext().getResourceDefinition(theResource).getName())) {
            encodingDomainResourceAsText = false;
        }
    }

    /*
     * Last-Modified header
     */

    IPrimitiveType<Date> lastUpdated;
    if (theOperationResourceLastUpdated != null) {
        lastUpdated = theOperationResourceLastUpdated;
    } else {
        lastUpdated = extractLastUpdatedFromResource(theResource);
    }
    if (lastUpdated != null && lastUpdated.isEmpty() == false) {
        restUtil.addHeader(Constants.HEADER_LAST_MODIFIED, DateUtils.formatDate(lastUpdated.getValue()));
    }

    /*
     * Category header (DSTU1 only)
     */

    if (theResource instanceof IResource
            && theServer.getFhirContext().getVersion().getVersion() == FhirVersionEnum.DSTU1) {
        TagList list = (TagList) ((IResource) theResource).getResourceMetadata()
                .get(ResourceMetadataKeyEnum.TAG_LIST);
        if (list != null) {
            for (Tag tag : list) {
                if (StringUtils.isNotBlank(tag.getTerm())) {
                    restUtil.addHeader(Constants.HEADER_CATEGORY, tag.toHeaderValue());
                }
            }
        }
    }

    /*
     * Stream the response body
     */

    if (theResource == null) {
        contentType = null;
    } else if (encodingDomainResourceAsText) {
        contentType = Constants.CT_HTML;
    } else {
        contentType = responseEncoding.getResourceContentType();
    }
    String charset = Constants.CHARSET_NAME_UTF8;

    Writer writer = restUtil.getResponseWriter(theStausCode, theStatusMessage, contentType, charset,
            respondGzip);
    if (theResource == null) {
        // No response is being returned
    } else if (encodingDomainResourceAsText && theResource instanceof IResource) {
        writer.append(((IResource) theResource).getText().getDiv().getValueAsString());
    } else {
        IParser parser = getNewParser(theServer.getFhirContext(), theRequestDetails);
        parser.encodeResourceToWriter(theResource, writer);
    }

    return restUtil.sendWriterResponse(theStausCode, contentType, charset, writer);
}