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:miage.ecom.web.security.ExtJsAuthenticationFailureHandler.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {

    HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response);

    Writer out = responseWrapper.getWriter();

    out.write("{success:false, errors: { reason: 'Login failed. Try again.' }}");
    out.close();/* w ww  . j  a v a 2s.  c om*/

}

From source file:miage.ecom.web.security.ExtJsAuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {

    HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response);

    Writer out = responseWrapper.getWriter();

    out.write("{success:true}");
    out.close();//from ww w.  java  2  s. co  m

}

From source file:com.dbx.feedlab.getFeedJSONServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String feedId = req.getParameter("id");
    //System.out.println("Feed ID=" + feedId);
    DataService ds;//from   w  w  w  .j a v a2s  .co  m
    try {
        ds = DataService.getInstance();
        Feed feed = ds.getFeed(Integer.parseInt(feedId));
        //Gson gson = new Gson();
        ObjectMapper mapper = new ObjectMapper();

        String json = mapper.writeValueAsString(feed);

        Writer writer = resp.getWriter();
        writer.write(json);

    } catch (NamingException ex) {
        Logger.getLogger(getFeedJSONServlet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(getFeedJSONServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.msopentech.odatajclient.testauthproxy.esigate.LinkRewriteRenderer.java

@Override
public void render(final HttpEntityEnclosingRequest httpRequest, final String src, final Writer out)
        throws IOException {

    out.write(src.replaceAll(baseUrl, replacementUrl));
}

From source file:net.groupbuy.template.directive.FlashMessageDirective.java

@SuppressWarnings("rawtypes")
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {
    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    if (requestAttributes != null) {
        Message message = (Message) requestAttributes.getAttribute(FLASH_MESSAGE_ATTRIBUTE_NAME,
                RequestAttributes.SCOPE_REQUEST);
        if (body != null) {
            setLocalVariable(VARIABLE_NAME, message, env, body);
        } else {//from  w w  w .ja v a 2  s .c om
            if (message != null) {
                Writer out = env.getOut();
                out.write("$.message(\"" + message.getType() + "\", \"" + message.getContent() + "\");");
            }
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.json.JsonArrayProducer.java

public final void process(HttpServletResponse resp) throws IOException {
    JSONArray jsonArray = null;//from ww  w  .  j  a va2  s . c  o m
    try {
        jsonArray = process();
    } catch (Exception e) {
        log.error("Failed to create JSON response" + e);
        resp.setStatus(500 /* HttpURLConnection.HTTP_SERVER_ERROR */);
    }

    if (jsonArray == null) {
        jsonArray = new JSONArray();
    }

    log.debug("Response to JSON request: " + jsonArray.toString());

    resp.setCharacterEncoding("UTF-8");
    resp.setContentType("application/json;charset=UTF-8");
    Writer writer = resp.getWriter();
    writer.write(jsonArray.toString());
}

From source file:com.kingdee.eas.bos.pureflex.manager.sce.SCEContentProvider.java

public void writeTo(OutputStream outstream) throws IOException {
    Writer writer = new OutputStreamWriter(outstream, "UTF-8"); //$NON-NLS-1$
    writer.write(content);
    writer.flush();// w w w .j a  va2 s.com
}

From source file:org.tec.security.spring.AuthenticationFailure.java

/**
 * {@inheritDoc}/*from  w  w  w. j ava2s .c om*/
 */
@Override()
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    if (mLogger.isDebugEnabled()) {
        mLogger.debug("failed login for " + request.getParameter("j_username"));
    }

    Writer out = response.getWriter();
    try {
        out.write("{success:false}");
    } 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.spectralogic.ds3client.helpers.channels.WindowedChannelFactory_Test.java

@Test
public void getReturnsWindow() throws Exception {
    try (final ByteArraySeekableByteChannel channel = new ByteArraySeekableByteChannel()) {
        final Writer writer = Channels.newWriter(channel, "UTF-8");
        writer.write("0123456789");
        writer.close();/* w w  w .j  av  a  2 s  .  c om*/

        try (final WindowedChannelFactory windowedChannelFactory = new WindowedChannelFactory(channel)) {
            try (final SeekableByteChannel window = windowedChannelFactory.get(2L, 6L)) {
                assertThat(IOUtils.toString(Channels.newReader(window, "UTF-8")), is("234567"));
            }
        }
    }
}

From source file:fr.opensagres.xdocreport.template.freemarker.XDocArchiveWithFreemarkerTest.java

public void testWrite() throws IOException, XDocReportException {

    XDocArchive archive = new XDocArchive();
    Writer contentWriter = archive.getEntryWriter("content.xml");
    contentWriter.write("bla bla bla ${var}");
    contentWriter.close();// ww  w.  j ava 2 s  . c om

    ITemplateEngine templateEngine = FreemarkerTemplateEngine.getDefault();
    IContext context = templateEngine.createContext();
    context.put("var", "AAA");

    contentWriter = archive.getEntryWriter("content.xml");
    Reader contentReader = archive.getEntryReader("content.xml");

    templateEngine.process("", context, contentReader, contentWriter, null);

    contentReader = archive.getEntryReader("content.xml");
    assertEquals("bla bla bla AAA", IOUtils.toString(contentReader));
}