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:org.tec.security.spring.AuthenticationSuccess.java

/**
 * {@inheritDoc}//from  w ww .  j  a  va2  s. c  o  m
 */
@Override()
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    ControllerUtils.clearCurrentUser(request.getSession());

    if (mLogger.isDebugEnabled()) {
        mLogger.debug("succeful login for " + request.getParameter("j_username"));
    }

    Writer out = response.getWriter();
    try {
        out.write("{success:true}");
    } catch (IOException e) {
        mLogger.error("failed to write to response", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "processing failed");
    } finally {
        out.close();
    }
}

From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java

/**
 * Create a temporary file and fill it with Proguard configuration.
 * //from   w  w  w. j a va  2 s . c  om
 * @param pArgsList List of args to push in Proguard configuration file
 * @param pMavenProject current project
 * @exception MojoExecutionException Exception throw if problem occurs on file creation
 */
private static File createFileConfiguration(List<String> pArgsList, MavenProject pMavenProject,
        File pOutputDirectory) throws MojoExecutionException {
    File vTempFile = null;

    try {
        String vFileName = pMavenProject.getName() + "arguments-inlining.proguardconf";

        vTempFile = new File(pOutputDirectory.getAbsolutePath(), vFileName);

        Writer vWriter = new BufferedWriter(new FileWriter(vTempFile));

        // Get iterator
        Iterator<String> vArgsIterator = pArgsList.iterator();

        // Iterate and add each line with a space behind
        while (vArgsIterator.hasNext()) {
            String vNextArg = vArgsIterator.next();
            vWriter.write(vNextArg + " ");
        }

        IOUtils.closeQuietly(vWriter);

    } catch (IOException pException) {
        throw new MojoExecutionException("Unable to create proguard configuration file ", pException);
    }

    return vTempFile;
}

From source file:com.ewcms.component.citizen.web.servlate.JavaScriptServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String encoding = getParameterValue(request, HEADER_ENCODING);
    encoding = (encoding == null ? DEFAULT_ENCODING : encoding);
    initResponseHeader(response, encoding);

    String callback = getParameterValue(request, CALLBACK_PARAMETER_NAME);
    String value;//w ww .j  a  va2s .c  o  m
    if (callback == null) {
        value = "alert('?');";
    } else {
        CitizenService service = getCitizenService();
        String json = service.mainJSON();
        value = String.format("%s(%s);", callback, json);
    }
    Writer writer = response.getWriter();
    writer.write(value);
    writer.flush();
}

From source file:com.ewcms.component.online.web.servlate.JavaScriptServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String encoding = getParameterValue(request, HEADER_ENCODING);
    encoding = (encoding == null ? DEFAULT_ENCODING : encoding);
    initResponseHeader(response, encoding);

    String callback = getParameterValue(request, CALLBACK_PARAMETER_NAME);
    String value;//from  w w w . j av a  2s.co  m
    if (callback == null) {
        value = "alert('?');";
    } else {
        OnlineService service = getOnlineService();
        String json = service.mainJSON();
        value = String.format("%s(%s);", callback, json);
    }
    Writer writer = response.getWriter();
    writer.write(value);
    writer.flush();
}

From source file:org.mitre.openid.connect.view.JWKSetView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) {//  ww w  .  j av a  2  s  . co  m

    response.setContentType(MediaType.APPLICATION_JSON_VALUE);

    //BiMap<String, PublicKey> keyMap = (BiMap<String, PublicKey>) model.get("keys");
    Map<String, JWK> keys = (Map<String, JWK>) model.get("keys");

    JWKSet jwkSet = new JWKSet(new ArrayList<>(keys.values()));

    try {

        Writer out = response.getWriter();
        out.write(jwkSet.toString());

    } catch (IOException e) {

        logger.error("IOException in JWKSetView.java: ", e);

    }

}

From source file:com.jstar.eclipse.processing.annotations.objects.ImportObject.java

@Override
public void generateFile(Writer writer) throws IOException {
    for (final String specFile : specFiles) {
        writer.write("import \"" + StringUtils.replace(specFile, ".", "/") + ".spec\";\n");
    }/*ww w.j  a  v  a  2s.c o m*/
}

From source file:com.ewcms.component.hot.web.JavaScriptServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String encoding = getParameterValue(request, HEADER_ENCODING);
    encoding = (encoding == null ? DEFAULT_ENCODING : encoding);
    initResponseHeader(response, encoding);

    String callback = getParameterValue(request, CALLBACK_PARAMETER_NAME);
    callback = RegexUtil.FilterScriptAndStyle(callback);
    String value;/* ww  w . j ava  2s .c om*/
    if (callback == null) {
        value = "alert('?');";
    } else {
        HotService service = getHotService();
        String json = service.mainJSON();
        value = String.format("%s(%s);", callback, json);
    }
    Writer writer = response.getWriter();
    writer.write(value);
    writer.flush();
}

From source file:com.cloudhopper.sxmp.SxmpWriter.java

static public void write(Writer out, Operation operation, boolean withXmlHeader)
        throws SxmpErrorException, IOException {
    if (withXmlHeader)
        writeXmlHeader(out, operation);//from   w  w  w  .j a v  a 2 s .co m
    writeOperationStartTag(out, operation.getType());

    // let's validate this operation is valid
    operation.validate();

    if (operation instanceof ErrorResponse) {
        // write out just an ErrorResponse
        writeErrorElement(out, (ErrorResponse) operation);

    } else if (operation instanceof Request) {
        // any request requires an account to be printed out
        Request request = (Request) operation;

        if (request.getAccount() != null) {
            out.write(" <account username=\"");
            out.write(StringUtil.escapeXml(request.getAccount().getUsername()));
            out.write("\" password=\"");
            out.write(StringUtil.escapeXml(request.getAccount().getPassword()));
            out.write("\"/>\n");
        }

        if (request.getApplication() != null) {
            out.write(" <application>");
            out.write(StringUtil.escapeXml(request.getApplication().getName()));
            out.write("</application>\n");
        }

        writeRequestResponseStartTag(out, operation);

        // tickets are now supported any any request
        if (request.getTicketId() != null) {
            out.write("  <ticketId>");
            out.write(StringUtil.escapeXml(request.getTicketId()));
            out.write("</ticketId>\n");
        }

        if (operation instanceof DeliveryReportRequest) {
            DeliveryReportRequest deliveryRequest = (DeliveryReportRequest) operation;

            if (deliveryRequest.getStatus() != null) {
                out.write("  <status code=\"");
                out.write(deliveryRequest.getStatus().getCode().toString());
                out.write("\" message=\"");
                out.write(StringUtil.escapeXml(deliveryRequest.getStatus().getMessage()));
                out.write("\"/>\n");
            }

            if (deliveryRequest.getMessageErrorCode() != null) {
                out.write("  <messageError code=\"");
                out.write(deliveryRequest.getMessageErrorCode().toString());
                out.write("\"/>\n");
            }

            if (deliveryRequest.getCreateDate() != null) {
                out.write("  <createDate>");
                out.write(SxmpParser.dateTimeFormat.print(deliveryRequest.getCreateDate()));
                out.write("</createDate>\n");
            }

            if (deliveryRequest.getFinalDate() != null) {
                out.write("  <finalDate>");
                out.write(SxmpParser.dateTimeFormat.print(deliveryRequest.getFinalDate()));
                out.write("</finalDate>\n");
            }

        } else if (operation instanceof MessageRequest) {
            MessageRequest messageRequest = (MessageRequest) operation;

            if (messageRequest.getOperatorId() != null) {
                out.write("  <operatorId>");
                out.write(messageRequest.getOperatorId().toString());
                out.write("</operatorId>\n");
            }

            if (messageRequest.getPriority() != null) {
                out.write("  <priority>");
                out.write(messageRequest.getPriority().getPriorityFlag().toString());
                out.write("</priority>\n");
            }

            if (operation instanceof SubmitRequest) {
                SubmitRequest submitRequest = (SubmitRequest) operation;
                if (submitRequest.getDeliveryReport() != null) {
                    out.write("  <deliveryReport>");
                    out.write(submitRequest.getDeliveryReport().toString().toLowerCase());
                    out.write("</deliveryReport>\n");
                }
            }

            if (messageRequest.getSourceAddress() != null) {
                out.write("  <sourceAddress type=\"");
                out.write(messageRequest.getSourceAddress().getType().toString().toLowerCase());
                out.write("\">");
                out.write(messageRequest.getSourceAddress().getAddress());
                out.write("</sourceAddress>\n");
            }

            if (messageRequest.getDestinationAddress() != null) {
                out.write("  <destinationAddress type=\"");
                out.write(messageRequest.getDestinationAddress().getType().toString().toLowerCase());
                out.write("\">");
                // push dest address is not guaranteed to be XML-safe
                // do minimum-necessary escaping? or better to stay standardized & escape everything?
                if (messageRequest.getDestinationAddress().getType() == MobileAddress.Type.PUSH_DESTINATION) {
                    out.write(XmlEscapeUtil.escapeTextXml(messageRequest.getDestinationAddress().getAddress()));
                } else {
                    out.write(messageRequest.getDestinationAddress().getAddress());
                }
                out.write("</destinationAddress>\n");
            }

            if (messageRequest.getText() != null) {
                String charset = messageRequest.getTextEncoding().getCharset();
                out.write("  <text encoding=\"");
                out.write(charset);
                out.write("\">");
                out.write(HexUtil.toHexString(messageRequest.getText().getBytes(charset)));
                out.write("</text>\n");
            }

            // this is a v1.1 option; only write if version == 1.1
            if (messageRequest.getOptionalParams() != null
                    && messageRequest.getVersion().equals(SxmpParser.VERSION_1_1)) {

                //String charset = messageRequest.getTextEncoding().getCharset();
                out.write("  <optionalParams>");
                JSONObject jsonObj = new JSONObject(messageRequest.getOptionalParams());
                // JSON encoding is not XML-safe
                // do minimum-necessary escaping? or better to stay standardized & escape everything?
                // tradeoff: all " and ' become &quot; and &apos; and all json strings are quoted.
                out.write(XmlEscapeUtil.escapeTextXml(jsonObj.toString()));
                out.write("</optionalParams>\n");
            }
        }

        writeRequestResponseEndTag(out, operation);
    } else {
        writeRequestResponseStartTag(out, operation);

        writeErrorElement(out, (Response) operation);

        // tickets on responses are now supported for submits or delivers
        if (operation instanceof SubmitResponse || operation instanceof DeliverResponse) {
            if (operation.getTicketId() != null) {
                out.write("  <ticketId>");
                out.write(StringUtil.escapeXml(operation.getTicketId()));
                out.write("</ticketId>\n");
            }
        }

        writeRequestResponseEndTag(out, operation);
    }

    writeOperationEndTag(out);
}

From source file:com.jstar.eclipse.processing.annotations.objects.ImportObject.java

public void writeImports(final Writer writer) throws IOException {
    for (final String specFile : specFiles) {
        writer.write(specFile + "\n");
    }/*www .  j  ava2s . c om*/
}

From source file:com.wavemaker.runtime.server.view.DownloadView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    Object result = model.get(ServerConstants.RESULTS_PART);

    if (result == null) {
        return;//  www. ja  va 2  s.c o m
    }

    if (result instanceof Downloadable) {
        sendDownloadable((Downloadable) result, response);
        return;
    }

    Writer writer = response.getWriter();
    writer.write(result.toString());
    writer.close();
}