Package java.io

Examples of java.io.Writer


        ByteArrayOutputStream out = new ByteArrayOutputStream();
        store(out, null);
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        InputStreamReader reader = new InputStreamReader(in, "ISO8859-1");
        LineNumberReader r = new LineNumberReader(reader);
        Writer w;
        try {
            w = new OutputStreamWriter(IOUtils.openFileOutputStream(fileName, false));
        } catch (Exception e) {
            throw DbException.convertToIOException(e);
        }
View Full Code Here


        try {
            String location = (String) ActionContext.getContext().get("template");
            Template template = velocityManager.getVelocityEngine().getTemplate(location);

            Writer writer = pageContext.getOut();
            template.merge(resultContext, writer);
            writer.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // perform cleanup
            jspFactory.releasePageContext(pageContext);
View Full Code Here

                m_writer.setIndentSpaces(m_indentCount, m_newLine,
                     m_indentChar);
            }
           
            // handle encoding using standard libraries
            Writer writer = new BufferedWriter
                (new OutputStreamWriter(outs, enc));
            ((GenericXMLWriter)m_writer).setOutput(writer, esc);
            reset();
           
        } catch (IOException ex) {
View Full Code Here

     
      // add new item into the feature list
      homePageContent = homePageContent.replaceAll("<li>Internationalization support</li>", "<li>Internationalization support</li>\n<li id=\"newFeature\">" + newFeature + "</li>");
     
      // write new content
      Writer writer = null;
      try
      {
         writer = new OutputStreamWriter(new FileOutputStream(homePageLocation));
         writer.write(homePageContent);
         writer.flush();
      }
      catch (IOException e)
      {
         throw new RuntimeException("Unable write modified home page " + homePageLocation);
      }
      finally
      {
         try
         {
            writer.close();
         }
         catch (IOException e)
         {
            throw new RuntimeException("Unable to close home page reader.");
         }
View Full Code Here

      conn.setAutoCommit(false);
      stmt = conn.prepareStatement(query);
      rs = stmt.executeQuery();
      int i = 0;
      if (rs.next() && i < parameters.length) {
        Writer writer = null;
        try {
          String param = parameters[i++].toString();
          CLOB clob = (CLOB)rs.getClob(i);
          writer = clob.getCharacterOutputStream();
          writer.write(param.toCharArray(), 0, param.length());
        } finally {
          try {
            if (writer != null) {
              writer.close();
            }
          } catch (Throwable t) {
          }
        }
      }
View Full Code Here

        XQueryModule module = proc.parse(input, baseUri);
        // #2 execute the compiled expression using ``pull'' mode
        Sequence<? extends Item> result = proc.execute(module);

        // prepare SAX result handler
        Writer writer = new NoopWriter();
        SAXWriter saxHandler = new SAXWriter(writer, "UTF-8"); // SAXWriter implements ContentHandler
        saxHandler.setPrettyPrint(true); // enabled formatting
        saxHandler.setXMLDeclaration(true); // insert XML declaration to output
        Serializer ser = new SAXSerializer(saxHandler);
        ser.emit(result); // emit SAX events to SAX handler
View Full Code Here

        XQueryProcessor proc = new XQueryProcessor();
        // #1 parse a query
        XQueryModule module = proc.parse(input);

        // prepare a result handler (StAX)
        Writer writer = new StringWriter();
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter streamWriter = factory.createXMLStreamWriter(writer);
        XQEventReceiver handler = new StAXSerializer(streamWriter);

        // #2 execute the compiled expression using ``push'' mode
        //   In push mode, the result is directed to the events.
        proc.execute(module, handler);

        streamWriter.flush(); // flushing is required
        System.out.println(writer.toString());
    }
View Full Code Here

        // Check to see if the Writer in the Event was used. If it
        // was, then the listeners contributed concatenated text, and
        // the result needs to be retrieved and sent back.
        if (event.isWriterUsed()) {
            Writer writer = event.getWriter();
            String result = writer.toString();
            writeHttpResponse(out, null, result);
        }

        // else - assume that the binary response listeners took care
        // of writing things back on their own,
View Full Code Here

        // Check to see if the Writer in the Event was used. If it
        // was, then the listeners contributed concatenated text, and
        // the result needs to be retrieved and sent back.
        if (event.isWriterUsed()) {
            Writer writer = event.getWriter();
            String result = writer.toString();
            writeHttpResponse(out, contentType, result);
        }

        // else - assume that the binary response listeners took care
        // of writing things back on their own,
View Full Code Here

    }

    public void writeTo(String className) {
      try {
        JavaFileObject jfo = filer.createSourceFile(className, (Element[]) null);
        Writer w = jfo.openWriter();
        w.write(p.toString());
        //在com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing中会调用filer.warnIfUnclosedFiles()
        //所以必需要close,否则JavacProcessingEnvironment会出错
        w.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
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.