Example usage for java.io StringWriter append

List of usage examples for java.io StringWriter append

Introduction

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

Prototype

public StringWriter append(char c) 

Source Link

Document

Appends the specified character to this writer.

Usage

From source file:org.apache.hadoop.hive.common.log.InPlaceUpdate.java

private String getInPlaceProgressBar(double percent) {
    StringWriter bar = new StringWriter();
    bar.append("[");
    int remainingChars = PROGRESS_BAR_CHARS - 4;
    int completed = (int) (remainingChars * percent);
    int pending = remainingChars - completed;
    for (int i = 0; i < completed; i++) {
        bar.append("=");
    }/*from  w  ww  .ja v a2s.c o m*/
    bar.append(">>");
    for (int i = 0; i < pending; i++) {
        bar.append("-");
    }
    bar.append("]");
    return bar.toString();
}

From source file:net.sourceforge.subsonic.controller.JAXBWriter.java

public void writeResponse(HttpServletRequest request, HttpServletResponse httpResponse, Response jaxbResponse)
        throws Exception {

    String format = getStringParameter(request, "f", "xml");
    String jsonpCallback = request.getParameter("callback");
    boolean json = "json".equals(format);
    boolean jsonp = "jsonp".equals(format) && jsonpCallback != null;
    Marshaller marshaller;//w  ww .j  av  a  2  s.  c om

    if (json) {
        marshaller = createJsonMarshaller();
        httpResponse.setContentType("application/json");
    } else if (jsonp) {
        marshaller = createJsonMarshaller();
        httpResponse.setContentType("text/javascript");
    } else {
        marshaller = createXmlMarshaller();
        httpResponse.setContentType("text/xml");
    }

    httpResponse.setCharacterEncoding(StringUtil.ENCODING_UTF8);

    try {
        StringWriter writer = new StringWriter();
        if (jsonp) {
            writer.append(jsonpCallback).append('(');
        }
        marshaller.marshal(new ObjectFactory().createSubsonicResponse(jaxbResponse), writer);
        if (jsonp) {
            writer.append(");");
        }
        httpResponse.getWriter().append(writer.getBuffer());
    } catch (Exception x) {
        LOG.error("Failed to marshal JAXB", x);
        throw x;
    }
}

From source file:com.galenframework.xml.XmlBuilder.java

public String build() {
    StringWriter sw = new StringWriter();

    if (firstLine != null) {
        sw.append(firstLine);
        sw.append('\n');
    }//from  ww w .ja va 2  s .  com
    rootNode.toXml("", sw);

    return sw.toString();
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTRole.java

private String generateSummeryReport(WSRole[] roles) throws ServiceException {
    try {/*from ww w .  j a va 2 s.  c o  m*/
        StringWriter sw = new StringWriter();

        sw.append("<roles>");
        for (int i = 0; i < roles.length; i++) {
            restUtils.getMarshaller(WSUser.class, WSRole.class).marshal(roles[i], sw);
            if (log.isDebugEnabled()) {
                log.debug("finished marshaling role: " + roles[i].getTenantId());
            }
        }

        sw.append("</roles>");
        return sw.toString();
    } catch (JAXBException e) {
        throw new ServiceException(e.getLocalizedMessage());
    }
}

From source file:org.n0pe.ruby.AbstractRubyMojo.java

protected String getClasspath() throws MojoExecutionException {
    try {/*  ww  w .  j ava  2 s.  c  o m*/
        final List classpath = new ArrayList();
        // Loading self dependencies
        final List scopesToUse = new ArrayList();
        scopesToUse.add(Artifact.SCOPE_COMPILE);
        scopesToUse.add(Artifact.SCOPE_RUNTIME);
        Iterator it = pluginArtifactMap.keySet().iterator();
        while (it.hasNext()) {
            Artifact artifact = (Artifact) pluginArtifactMap.get((String) it.next());
            if (scopesToUse.contains(artifact.getScope())) {
                artifactResolver.resolve(artifact, remoteRepositories, localRepository);
                classpath.add(artifact.getFile().getAbsolutePath());
            }
        }
        // Loading self
        final Artifact self = artifactFactory.createArtifact("org.n0pe.mojo", "ruby-maven-plugin",
                "0.1-SNAPSHOT", Artifact.SCOPE_RUNTIME, "maven-plugin");
        artifactResolver.resolve(self, remoteRepositories, localRepository);
        classpath.add(self.getFile().getAbsolutePath());
        // Building the classpath string
        it = classpath.iterator();
        final StringWriter sw = new StringWriter();
        while (it.hasNext()) {
            sw.append((String) it.next());
            if (it.hasNext()) {
                sw.append(File.pathSeparator);
            }
        }
        return sw.toString();
    } catch (ArtifactResolutionException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex);
    } catch (ArtifactNotFoundException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex);
    }
}

From source file:com.espertech.esper.epl.expression.ExprNodeUtility.java

public static String printEvaluators(ExprEvaluator[] evaluators) {
    StringWriter writer = new StringWriter();
    String delimiter = "";
    for (int i = 0; i < evaluators.length; i++) {
        writer.append(delimiter);
        writer.append(evaluators[i].getClass().getSimpleName());
        delimiter = ", ";
    }/*from w ww .  ja  va 2  s  . c  o  m*/
    return writer.toString();
}

From source file:com.espertech.esper.epl.expression.ExprNodeUtility.java

public static void toExpressionStringParams(StringWriter writer, ExprNode[] params, boolean isWildcard,
        String streamWildcard, boolean firstParamOnly) {
    writer.append('(');
    if (isWildcard) {
        writer.append('*');
    } else if (streamWildcard != null) {
        writer.append(streamWildcard);/* w w w . ja  v a2 s  . com*/
        writer.append(".*");
    } else {
        String delimiter = "";
        for (ExprNode childNode : params) {
            writer.append(delimiter);
            delimiter = ",";
            writer.append(childNode.toExpressionString());
            if (firstParamOnly) {
                break;
            }
        }
    }
    writer.append(')');
}

From source file:org.openremote.controller.protocol.samsungtv.SamsungTVSession.java

private String getRegistrationPayload(String ip) throws IOException {
    StringWriter writer = new StringWriter();
    writer.append((char) 0x64);
    writer.append((char) 0x00);
    writeBase64Text(writer, ip);//  ww w .  j  a v a  2s  .  c  o  m
    writeBase64Text(writer, ip);
    writeBase64Text(writer, applicationName);
    writer.flush();
    return writer.toString();
}

From source file:eu.sisob.uma.restserver.services.crawler.CrawlerTask.java

public static boolean launch(String user, String pass, String task_code, String code_task_folder, String email,
        StringWriter message) {
    if (message == null) {
        return false;
    }/*  ww w.j  av a  2s. co m*/
    boolean success = false;
    message.getBuffer().setLength(0);
    File code_task_folder_dir = new File(code_task_folder);

    File csv_data_source_file = FileSystemManager.getFileIfExists(code_task_folder_dir,
            input_data_source_filename_prefix_csv, input_data_source_filename_ext_csv);

    boolean validate = csv_data_source_file != null;

    if (!validate) {
        success = false;
        message.write("You have not uploaded 'data-researchers-urls.csv' file"); //FIXME
    }

    org.dom4j.Document document = null;

    String middle_data_folder = code_task_folder + File.separator + AuthorizationManager.middle_data_dirname;
    File middle_data_dir = null;
    try {
        middle_data_dir = FileSystemManager.createFileAndIfExistsDelete(middle_data_folder);
    } catch (Exception ex) {
        ProjectLogger.LOGGER.error(ex.toString(), ex);
        message.append("The file couldn't be created " + middle_data_dir.getName() + "\r\n");
        return false;
    }

    String results_data_folder = code_task_folder + File.separator + AuthorizationManager.results_dirname;
    File results_data_dir = null;
    try {
        results_data_dir = FileSystemManager.createFileAndIfExistsDelete(results_data_folder);
    } catch (Exception ex) {
        ProjectLogger.LOGGER.error(ex.toString(), ex);
        message.append("The file couldn't be created " + results_data_dir.getName() + "\r\n");
        return false;
    }

    try {
        File middle_data_source_file = new File(middle_data_dir, middle_data_source_filename_xml);
        validate = FileFormatConversor.createResearchersXMLFileFromCSV(csv_data_source_file,
                middle_data_source_file);
    } catch (Exception ex) {
        ProjectLogger.LOGGER.error(ex.getMessage(), ex);
        validate = false;
    }

    if (!validate) {
        message.append("The format of '" + csv_data_source_file.getName()
                + "' does not seems be correct. Please check the headers of the csv file (read in the instructions which are optionals) and be sure that the field separators are ';'. Please read the intructions of the task."
                + "\r\n");
        return false;
    }

    try {
        File xmlFile = new File(middle_data_folder, middle_data_source_filename_xml);
        org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
        document = reader.read(xmlFile);
    } catch (Exception ex) {
        message.write("The format of '" + csv_data_source_file.getName() + "' does not seems be correct"); //FIXME
        ProjectLogger.LOGGER.error(message.toString(), ex);
        return false;
    }

    String out_filename = csv_data_source_file.getName().replace(input_data_source_filename_prefix_csv,
            output_data_source_filename_csv);
    File csv_data_output_file = new File(results_data_dir, out_filename);
    ResearchersCrawlerTaskInRest task = new ResearchersCrawlerTaskInRest(document,
            new File(ResearchersCrawlerService.CRAWLER_DATA_PATH), middle_data_dir, results_data_dir,
            csv_data_output_file, user, pass, task_code, code_task_folder, email);
    try {

        ResearchersCrawlerService.getInstance().addExecution(new CallbackableTaskExecution(task));
        success = true;
        message.write(TheResourceBundle.getString("Jsp Task Executed Msg"));

    } catch (InterruptedException ex) {

        message.write(TheResourceBundle.getString("Jsp Task Executed Error Msg"));
        ProjectLogger.LOGGER.error(message.toString(), ex);
        return false;
    }

    return true;
}

From source file:edu.harvard.i2b2.crc.axis2.RequestDataMessage.java

/**
 * Function to generate i2b2 message header message number
 * /* w w w  . j  av a  2s .  co  m*/
 * @return String
 */
protected String generateMessageId() {
    StringWriter strWriter = new StringWriter();
    for (int i = 0; i < 20; i++) {
        int num = getValidAcsiiValue();
        strWriter.append((char) num);
    }
    return strWriter.toString();
}