Example usage for java.io Writer write

List of usage examples for java.io Writer write

Introduction

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

Prototype

public void write(String str) throws IOException 

Source Link

Document

Writes a string.

Usage

From source file:com.amalto.core.storage.record.DataRecordDefaultWriter.java

public void write(DataRecord record, Writer writer) throws IOException {
    boolean isReferenceField;
    writer.write("<result>\n"); //$NON-NLS-1$
    for (FieldMetadata fieldMetadata : record.getSetFields()) {
        if (delegator.hide(fieldMetadata)) {
            continue;
        }/*from   w  w  w . j av a  2  s .c  o m*/
        Object value = record.get(fieldMetadata);
        if (value != null) {
            String name = fieldMetadata.getName();
            writer.append("\t<").append(name).append(">"); //$NON-NLS-1$ //$NON-NLS-2$
            isReferenceField = fieldMetadata instanceof ReferenceFieldMetadata;
            if (value instanceof Object[]) {
                Object[] values = (Object[]) value;
                for (Object currentValue : values) {
                    if (isReferenceField) {
                        writer.append("[").append(StringEscapeUtils.escapeXml(String.valueOf(currentValue))) //$NON-NLS-1$
                                .append("]"); //$NON-NLS-1$
                    } else {
                        writer.append(StringEscapeUtils.escapeXml(String.valueOf(currentValue)));
                    }
                }
            } else {
                if (isReferenceField) {
                    writer.append("[").append(StringEscapeUtils.escapeXml(String.valueOf(value))).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
                } else {
                    writer.append(
                            StringEscapeUtils.escapeXml(StorageMetadataUtils.toString(value, fieldMetadata)));
                }
            }
            writer.append("</").append(name).append(">\n"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
    writer.append("</result>"); //$NON-NLS-1$
    writer.flush();
}

From source file:fedora.server.security.servletfilters.xmluserfile.FedoraUsers.java

public void write(Writer outputWriter) throws IOException {
    outputWriter.write("<?xml version='1.0' ?>\n");

    BeanWriter beanWriter = new BeanWriter(outputWriter);
    beanWriter.getBindingConfiguration().setMapIDs(false);
    beanWriter.setWriteEmptyElements(false);
    beanWriter.enablePrettyPrint();//  w  w w . j  a va 2 s.c  o m
    try {
        beanWriter.getXMLIntrospector().register(getBetwixtMapping());
        beanWriter.write("users", this);
    } catch (IntrospectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    beanWriter.flush();
    beanWriter.close();
}

From source file:com.amalto.core.storage.record.ViewSearchResultsWriter.java

@Override
public void write(DataRecord record, Writer writer) throws IOException {
    writer.write("<result xmlns:metadata=\"" + DataRecordReader.METADATA_NAMESPACE + "\"" //$NON-NLS-1$ //$NON-NLS-2$
            + " xmlns:xsi=\"" + XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
    for (FieldMetadata fieldMetadata : record.getSetFields()) {
        Object value = record.get(fieldMetadata);
        String name = fieldMetadata.getName();
        if (value != null) {
            writer.append("\t<").append(name).append(">"); //$NON-NLS-1$ //$NON-NLS-2$
            processValue(writer, fieldMetadata, value);
            writer.append("</").append(name).append(">\n"); //$NON-NLS-1$ //$NON-NLS-2$
        } else {/*from  w w  w  .java 2s  .c o  m*/
            writer.append("\t<").append(name).append("/>\n"); //$NON-NLS-1$//$NON-NLS-2$
        }
    }
    writer.append("</result>"); //$NON-NLS-1$
    writer.flush();
}

From source file:net.cit.tetrad.resource.CommandResource.java

@RequestMapping("/runServerStatus.do")
public void runServerStatus(HttpServletResponse response, CommonDto dto) throws Exception {
    String serverStatusFromMongo = comandService.allServerStatus(dto.getDeviceCode());

    response.setContentType("text/html;charset=utf-8");
    response.setCharacterEncoding("UTF-8");

    response.setContentType("text/html");
    response.setHeader("Cache-Control", "no-cache");

    Writer writer = response.getWriter();
    writer.write(serverStatusFromMongo);

    writer.flush();/*from   ww  w .  ja v  a 2s .c  om*/
}

From source file:org.cbio.portal.pipelines.foundation.MutationDataWriter.java

@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
    // retrieve list of foundation cases from execution context
    final List<CaseType> fmiCaseList = (List<CaseType>) executionContext.get("fmiCaseList");

    String stagingFile = outputDirectory + "data_mutations_extended.txt";
    PassThroughLineAggregator aggr = new PassThroughLineAggregator();
    flatFileItemWriter.setLineAggregator(aggr);
    flatFileItemWriter.setHeaderCallback(new FlatFileHeaderCallback() {
        @Override/*from w  ww.  j  a  v a  2  s  .  c  om*/
        public void writeHeader(Writer writer) throws IOException {
            writer.write(getHeader(fmiCaseList));
        }
    });
    flatFileItemWriter.setResource(new FileSystemResource(stagingFile));
    flatFileItemWriter.open(executionContext);
}

From source file:com.linuxbox.enkive.message.SinglePartHeaderImpl.java

@Override
public void pushReconstitutedEmail(Writer output) throws IOException {
    try {/*from ww w.ja v a  2 s.com*/
        output.write(getOriginalHeaders());
        output.write(getLineEnding());
        IOUtils.copy(getEncodedContentData().getEncodedContent(), output);
        output.write(getLineEnding());
    } catch (ContentException e) {
        throw new IOException(e);
    } finally {
        output.flush();
    }
}

From source file:bazaar4idea.command.BzrCommitCommand.java

private File saveCommitMessage() throws IOException {
    File systemDir = new File(PathManager.getSystemPath());
    File tempFile = new File(systemDir, TEMP_FILE_NAME);
    Writer output = new BufferedWriter(new FileWriter(tempFile, false));
    try {//from ww  w .j  a v  a2  s  . c om
        output.write(message);
        output.flush();
    } finally {
        output.close();
    }
    tempFile.deleteOnExit();
    return tempFile;
}

From source file:com.ewcms.component.rss.web.RssServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String encoding = DEFAULT_ENCODING;
    initResponseHeader(response, encoding);
    String value = getParameterValue(request, "id");
    String rss = "";
    try {/*  www . j  a  va2 s. c o m*/
        int id = Integer.valueOf(value);
        String dns = request.getServerName();
        rss = constructRss(id, dns);
    } catch (Exception e) {
        StringBuilder builder = new StringBuilder();
        builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>  ");
        builder.append("<rss version=\"2.0\">");
        builder.append("</xml>");
        rss = builder.toString();
    }
    Writer writer = response.getWriter();
    writer.write(rss);
    writer.flush();
}

From source file:com.oauth.servlet.AuthorizationCallbackServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {//from  w  w w  .  jav a2s. com
        System.err.println(req.getQueryString());
        System.err.println(req.getRequestURI());
        String token = null;
        String responseBody = null;
        if (req.getParameter("code") != null) {
            HttpClient httpclient = new DefaultHttpClient();
            String authCode = req.getParameter("code");
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            try {
                if (req.getRequestURI().indexOf("git") > 0) {
                    HttpGet httpget = new HttpGet(client.getAccessTokenUrl(authCode));

                    responseBody = httpclient.execute(httpget, responseHandler);
                    int accessTokenStartIndex = responseBody.indexOf("access_token=")
                            + "access_token=".length();
                    token = responseBody.substring(accessTokenStartIndex,
                            responseBody.indexOf("&", accessTokenStartIndex));

                } else if (req.getRequestURI().indexOf("isam") > 0) {
                    System.err.println(iSAMClient.getAccessTokenUrl());
                    HttpPost httpPost = new HttpPost(iSAMClient.getAccessTokenUrl());
                    httpPost.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");

                    System.err.println("Post Params--------");
                    for (Iterator<NameValuePair> postParamIter = iSAMClient.getPostParams(authCode)
                            .iterator(); postParamIter.hasNext();) {
                        NameValuePair postParam = postParamIter.next();
                        System.err.println(postParam.getName() + "=" + postParam.getValue());
                    }
                    httpPost.setEntity(new UrlEncodedFormEntity(iSAMClient.getPostParams(authCode)));
                    System.err.println("Post Params--------");
                    responseBody = httpclient.execute(httpPost, responseHandler);
                    token = parseJsonString(responseBody);
                } else {
                    resp.sendError(HttpStatus.SC_FORBIDDEN);
                }
                System.err.println(responseBody);
                req.setAttribute("Response", responseBody);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                httpclient.getConnectionManager().shutdown();
            }
            resp.sendRedirect("userDetails.jsp?token=" + token);
        } /*else if(req.getParameter("access_token") != null) {
           Writer w = resp.getWriter();
                    
            w.write("<html><body><center>");
            w.write("<h3>");
            w.write("User Code [" + req.getParameter("access_token") + "] has successfully logged in!");
            w.write("</h3>");
            w.write("</center></body></html>");
                    
            w.flush();
            w.close();   
          } */else {
            Writer w = resp.getWriter();

            w.write("<html><body><center>");
            w.write("<h3>");
            w.write("UNAUTHORIZED Access!");
            w.write("</h3>");
            w.write("</center></body></html>");

            w.flush();
            w.close();
        }

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:de.tudarmstadt.ukp.experiments.dip.wp1.data.QueryResultContainer.java

public String toXML() throws IOException {
    Writer out = new StringWriter();
    out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");

    XStream xStream = initializeXStream();

    xStream.toXML(this, out);
    IOUtils.closeQuietly(out);// w  ww  .j  a va  2 s  .com

    return out.toString();
}