Package java.io

Examples of java.io.Writer


            HttpServletResponse response) throws ServletException, IOException {
        if (!this.errorAtInit)
            throw new UnavailableException(
                    "Error thrown deliberately during get");

        Writer out = response.getWriter();
        out
                .write("This should not be shown, because we've thrown unavailable exceptions");
        out.close();
    }
View Full Code Here


                        final String crawlingFileContent = post.get("crawlingFile$file", "");
                        try {
                            // check if the crawl filter works correctly
                            Pattern.compile(newcrawlingMustMatch);
                            final ContentScraper scraper = new ContentScraper(new DigestURI(crawlingFile));
                            final Writer writer = new TransformerWriter(null, null, scraper, null, false);
                            if (crawlingFile != null && crawlingFile.exists()) {
                                FileUtils.copy(new FileInputStream(crawlingFile), writer);
                            } else {
                                FileUtils.copy(crawlingFileContent, writer);
                            }
                            writer.close();

                            // get links and generate filter
                            final Map<MultiProtocolURI, Properties> hyperlinks = scraper.getAnchors();
                            if (fullDomain && newcrawlingdepth > 0) newcrawlingMustMatch = siteFilter(hyperlinks.keySet());
View Full Code Here

    try {
      br=BoboRequestBuilder.buildRequest(params,query,sort);
      logger.info("REQ: "+BrowseProtobufConverter.toProtoBufString(br));
      BrowseResult result=_svc.browse(br);
      res.setCharacterEncoding("UTF-8");
      Writer writer=res.getWriter();
     
      String outputFormat=req.getParameter("output");
      if ("json".equals(outputFormat)){
        try{
          String val=BrowseJSONSerializer.serialize(result);
          writer.write(val);
        }
        catch(JSONException je){
          throw new IOException(je.getMessage());
        }
      }
      else{
        XStream xstream=XStreamDispenser.getXMLXStream();
        writer.write(xstream.toXML(result));
      }
      return null;
    } catch (BrowseException e) {
      throw new ServletException(e.getMessage(),e);
    }
View Full Code Here

    try {
      br=BoboRequestBuilder.buildRequest(params,query,sort);
      logger.info("REQ: "+BrowseProtobufConverter.toProtoBufString(br));
      BrowseResult result=_svc.browse(br);
      res.setCharacterEncoding("UTF-8");
      Writer writer=res.getWriter();
     
      String outputFormat=req.getParameter("output");
      if ("json".equals(outputFormat)){
        try{
          String val=BrowseJSONSerializer.serialize(result);
          writer.write(val);
        }
        catch(JSONException je){
          throw new IOException(je.getMessage());
        }
      }
      else{
        XStream xstream=XStreamDispenser.getXMLXStream();
        writer.write(xstream.toXML(result));
      }
     
     
     
    } catch (BrowseException e) {
View Full Code Here

  public void out(String viewFileName) {
    try {
      Template template = config.getTemplate(viewFileName, defaultEncoding);

      if (template != null) {
        Writer writer = douyuContext.getHttpServletResponse().getWriter();

        //TODO
        //template.process内部会自动调用writer.flush,
        //如果在输出ftl文件后又接着输出jsp,那么jsp会出异常:
        //java.lang.IllegalStateException: Cannot create a session after the response has been committed
View Full Code Here

  public void out(String viewFileName) {
    try {
      Template template = Velocity.getTemplate(viewFileName, defaultEncoding);

      if (template != null) {
        Writer writer = douyuContext.getHttpServletResponse().getWriter();
        template.merge(velocityContext, writer);

        //writer.flush();
        //writer.close();
      }
View Full Code Here

        String output = Launcher.RESOURCES.getString("WinstoneResponse.ErrorPage",
                new String[] { sc + "", (msg == null ? "" : msg), "",
                        Launcher.RESOURCES.getString("ServerVersion"),
                        "" + new Date() });
        setContentLength(output.getBytes(getCharacterEncoding()).length);
        Writer out = getWriter();
        out.write(output);
        out.flush();
    }
View Full Code Here

            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentLength((int) res.length());
//            response.addHeader(ACCEPT_RANGES_HEADER, "bytes");
            response.addDateHeader(LAST_MODIFIED_DATE_HEADER, res.lastModified());
            OutputStream out = null;
            Writer outWriter = null;
            try {
                out = response.getOutputStream();
            } catch (IllegalStateException err) {
                outWriter = response.getWriter();
            } catch (IllegalArgumentException err) {
                outWriter = response.getWriter();
            }
            byte buffer[] = new byte[4096];
            int read = resStream.read(buffer);
            while (read > 0) {
                if (out != null) {
                    out.write(buffer, 0, read);
                } else {
                    outWriter.write(new String(buffer, 0, read,
                            response.getCharacterEncoding()));
                }
                read = resStream.read(buffer);
            }
            resStream.close();
View Full Code Here

                        path.equals("") ? "/" : path,
                        rowString.toString() });

        response.setContentLength(out.getBytes().length);
        response.setContentType("text/html");
        Writer w = response.getWriter();
        w.write(out);
        w.close();
    }
View Full Code Here

    public static void flush(String name) {
        if (!initialised) {
            init(INFO);
        }

        Writer stream = getStreamByName(name);
        if (stream != null) {
            try {stream.flush();} catch (IOException err) {}
        }
    }
View Full Code Here

TOP

Related Classes of java.io.Writer

Copyright © 2015 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.