Package java.io

Examples of java.io.Writer


      throw new RuntimeException(message);
    }
    ServletActionContext.getResponse().setContentType("text/javascript; charset=UTF-8");
    JSON json = (JSON)actionInvocation.getStack().findValue(jsonName);
    if(json != null){
      Writer out = null;
      try{
        out = ServletActionContext.getResponse().getWriter();
        out.append(json.toString());
      }catch(Exception e){
        logger.error("Error write json object: " + e.getMessage(), e);
      }finally{
        if(out != null){
          out.close();
        }
      }                   
    }else{
      logger.error("Can't find json object on stack with name '" + jsonName +"'");
    }
View Full Code Here


            if (feedType != null) // if the feedType is specified, we'll override the one set in the feed object
                feed.setFeedType(feedType);

            SyndFeedOutput output = new SyndFeedOutput();
            // we'll need the writer since Rome doesn't support writing to an outputStream yet
            Writer out = null;
            try {
                out = ServletActionContext.getResponse().getWriter();
                preprocess(feed);
                output.output(feed, out);
                postprocess(feed);
            } catch (Exception e) {
                // Woops, couldn't write the feed ?
                logger.error("Could not write the feed: " + e.getMessage(), e);
            } finally {
                // close the output writer (will flush automatically)
                if (out != null)
                    out.close();
            }
        } else {
            // woops .. no object found on the stack with that name ?
            final String message = "Did not find object on stack with name '" + feedName + "'";
            logger.error(message);
View Full Code Here

        }
        try {
            prepareForSerialization(ser, node);
            ser._format.setEncoding(encoding);
            OutputStream outputStream = destination.getByteStream();
            Writer writer = destination.getCharacterStream();
            String uri =  destination.getSystemId();
            if (writer == null) {
                if (outputStream == null) {
                    if (uri == null) {
                        String msg = DOMMessageFormatter.formatMessage(
View Full Code Here

      }

      MessageBundle messageBundle = Util.bundleMessages(alertSink, messages);
      PropertiesBundleWriter pbw = new PropertiesBundleWriter(messageBundle);
      try {
        Writer writer = propertiesFile.openWriter(Charsets.US_ASCII);
        try {
          pbw.write(writer);
        } finally {
          writer.close();
        }
      } catch (UnmappableCharacterException uce) {
        // These are caused by coding errors, not user error.
        throw new AssertionError(uce);
      } catch (IOException iox) {
View Full Code Here

        String suffix = String.format(".%02d.%s.dot", i,
                                      phase.name().toLowerCase().replace("_", "-"));
        for (CompilationUnit compilationUnit : compilationUnits) {
          FileRef fileRef = compilationUnit.getSourceFileRef().removeExtension().addSuffix(suffix);
          try {
            Writer writer = fileRef.openWriter(Charsets.US_ASCII);
            try {
              DotWriter out = new DotWriter(writer);
              GraphRenderer<Object> renderer =
                  new ReflectiveGraphRenderer(phase.name().toLowerCase());
              renderer.renderGraph(out, phase.getForest(compilationUnit).getChildren());
            } finally {
              writer.close();
            }
          } catch (IOException iox) {
            alertSink.add(new IOError(fileRef, iox));
          }
        }
View Full Code Here

    InMemoryFileSystem schemaFs = new InMemoryFileSystem();
    String sourceName = "/" + pkgDir + "/" + name + ".xml";
    source = schemaFs.parseFilename(sourceName);

    // write GXP
    Writer writer = source.openWriter(Charsets.US_ASCII);
    writer.write(contents);
    writer.close();

    return source;
  }
View Full Code Here

  private FileRef addFileToSourceFs(String path, String content)
      throws IOException {
    FileRef fileRef = sourcePathFs.parseFilename(path);
    OutputStream out = fileRef.openOutputStream();
    try {
      Writer outW = new OutputStreamWriter(out, "UTF-8");
      outW.write(content);
      outW.flush();
    } finally {
      out.close();
    }
    return fileRef;
  }
View Full Code Here

        response.setStatus(HttpServletResponse.SC_OK);

        //
        // Get the output stream writer from the binding.
        //
        Writer out = (Writer) binding.getVariable("out");
        if (out == null) {
            out = response.getWriter();
        }

        //
        // Evaluate the template.
        //
        if (verbose) {
            log("Making template \"" + name + "\"...");
        }
        // String made = template.make(binding.getVariables()).toString();
        // log(" = " + made);
        long makeMillis = System.currentTimeMillis();
        template.make(binding.getVariables()).writeTo(out);
        makeMillis = System.currentTimeMillis() - makeMillis;

        if (generateBy) {
            StringBuffer sb = new StringBuffer(100);
            sb.append("\n<!-- Generated by Groovy TemplateServlet [create/get=");
            sb.append(Long.toString(getMillis));
            sb.append(" ms, make=");
            sb.append(Long.toString(makeMillis));
            sb.append(" ms] -->\n");
            out.write(sb.toString());
        }

        //
        // flush the response buffer.
        //
View Full Code Here

    // Write a couple of files, and make sure we can read them back.
    // Two files used to ensure the file system keeps them separate.
    String helloText = "hello, world!";
    String goodbyeText = "goodbye, world!";

    Writer out = hello.openWriter(Charsets.US_ASCII);
    out.write(helloText);
    out.close();
    out = goodbye.openWriter(Charsets.US_ASCII);
    out.write(goodbyeText);
    out.close();

    // Re-create filenames, just to make sure we aren't relying on object
    // identity.
    hello = fs.parseFilename("/foo/bar/baz");
    goodbye = fs.parseFilename("/snarf/quux");
View Full Code Here

  public void testOpenWriter_overwriteExistingFile() throws Exception {
    FileRef fnam = fs.parseFilename("/foo/bar/baz");

    String oldText = "that was then";
    Writer out = fnam.openWriter(Charsets.US_ASCII);
    out.write(oldText);
    out.close();
    MoreAsserts.assertEquals(oldText.getBytes(),
                             ByteStreams.toByteArray(fnam.openInputStream()));

    String newText = "this is now";
    out = fnam.openWriter(Charsets.US_ASCII);
    out.write(newText);
    out.close();
    MoreAsserts.assertEquals(newText.getBytes(),
                             ByteStreams.toByteArray(fnam.openInputStream()));
  }
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.