Package java.io

Examples of java.io.StringWriter


  @Override
  public ChartOutput getChart(ChartInput getChartInput) {
    try {
      Transformer transformer = TransformerFactory.newInstance()
          .newTransformer();
      StringWriter reader = new StringWriter();

      CategoryDataset dataset = null;

      transformer.transform(getChartInput.getXmlData(), new StreamResult(
          reader));
      dataset = DatasetReader
          .readCategoryDatasetFromXML(new ByteArrayInputStream(reader
              .getBuffer().toString().getBytes()));

      // create the chart...
      final JFreeChart chart = ChartFactory.createBarChart("Bar Chart", // chart
                                        // title
View Full Code Here


        return reader.loadDocument(istream);
    }   
   
    private String saveMappingDocument(MappingDocument doc)
        throws IOException {
        StringWriter sw = new StringWriter();
        MappingOutputter out = new MappingOutputter();
        out.write(doc, new PrintWriter(sw));
        return sw.toString();
    }
View Full Code Here

                throw DbException.getInvalidValueException("pos", pos);
            }
            if (length < 0) {
                throw DbException.getInvalidValueException("length", length);
            }
            StringWriter writer = new StringWriter(Math.min(Constants.IO_BUFFER_SIZE, length));
            Reader reader = value.getReader();
            try {
                IOUtils.skipFully(reader, pos - 1);
                IOUtils.copyAndCloseInput(reader, writer, length);
            } finally {
                reader.close();
            }
            return writer.toString();
        } catch (Exception e) {
            throw logAndConvert(e);
        }
    }
View Full Code Here

        File windowsScriptFile = new File(scriptDestinationDir, "gradlew.bat");
        FileUtils.writeStringToFile(windowsScriptFile, transformIntoWindowsNewLines(windowsScript));
    }

    private String transformIntoWindowsNewLines(String s) {
        StringWriter writer = new StringWriter();
        for (char c : s.toCharArray()) {
            if (c == '\n') {
                writer.write('\r');
                writer.write('\n');
            } else if (c != '\r') {
                writer.write(c);
            }
        }       
        return writer.toString();
    }
View Full Code Here

        final StopWatch sw = new StopWatch("[Xbird] " + queryFile);
        queryFile = XMARK_HOME + '/' + queryFile;
        final XQueryProcessor processor = new XQueryProcessor();
        XQueryModule mod = processor.parse(new FileInputStream(queryFile), new File(queryFile).toURI());
        Sequence result = processor.execute(mod);
        StringWriter res_sw = new StringWriter();
        final Serializer ser = new SAXSerializer(new SAXWriter(res_sw), res_sw);
        ser.emit(result);
        String swresult = sw.toString();
        long used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(before GC): " + StringUtils.displayBytesSize(used));
        if(RUN_ONLY) {
            res_sw.close();
            res_sw = null;
        }
        System.gc();
        used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(after GC): " + StringUtils.displayBytesSize(used));
        int gcCalled = SystemUtils.countGC() - gcBefore;
        stdbuf.append(", total gc count: " + gcCalled);
        System.out.println(swresult);
        System.out.println(stdbuf.toString());
        if(RUN_ONLY) {
            return "";// dummy
        }
        return res_sw.toString();
    }
View Full Code Here

        config.setHostLanguage(Configuration.XQUERY);
        final StaticQueryContext staticContext = new StaticQueryContext(config);
        staticContext.setBaseURI(new File(queryFile).toURI().toString());
        XQueryExpression exp = staticContext.compileQuery(IOUtils.toString(new FileInputStream(queryFile)));
        final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
        StringWriter res_sw = new StringWriter();
        Properties props = new Properties();
        //props.setProperty(OutputKeys.METHOD, "text");
        props.setProperty(SaxonOutputKeys.WRAP, "no");
        props.setProperty(OutputKeys.INDENT, "no");
        props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        exp.run(dynamicContext, new StreamResult(res_sw), props);
        String swresult = sw.toString();
        long used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(before GC): " + StringUtils.displayBytesSize(used));
        if(RUN_ONLY) {
            res_sw.close();
            res_sw = null;
        }
        System.gc();
        used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(after GC): " + StringUtils.displayBytesSize(used));
        int gcCalled = SystemUtils.countGC() - gcBefore;
        stdbuf.append(", total gc count: " + gcCalled);
        System.out.println(swresult);
        System.out.println(stdbuf.toString());
        if(RUN_ONLY) {
            return "";//dummy
        }
        return res_sw.toString();
    }
View Full Code Here

    try
    {
      final DefaultTagDescription tagDescription = new DefaultTagDescription();
      tagDescription.setDefaultNamespace(LibXmlInfo.XHTML_NAMESPACE);
      tagDescription.addDefaultDefinition(LibXmlInfo.XHTML_NAMESPACE, false);
      final StringWriter sbwriter = new StringWriter(5000);
      final XmlWriter writer = new XmlWriter(sbwriter);
      writer.setHtmlCompatiblityMode(true);
      writer.setWriteFinalLinebreak(true);
      writeImageMap(writer, imageMap, 1);
      writer.close();
      return sbwriter.toString();
    }
    catch (IOException ioe)
    {
      // now where does a StringWriter get its IO troubles from?
      throw new IllegalStateException("Failed to write ImageMap - I am confused.");
View Full Code Here

public class PrintWriterResponseData implements ResponseData {
    PrintWriter writer;
    StringWriter backEnd;

    public PrintWriterResponseData() {
        backEnd = new StringWriter();
        writer = new PrintWriter( backEnd );
    }
View Full Code Here

   * Generates a stacktrace in the form of a string
   * @param exception Exception to make stacktrace of
   * @return Stacktrace of exception in the form of a string
   */
  private static String generateStacktrace(Exception exception) {
    Writer result = new StringWriter();
    PrintWriter printWriter = new PrintWriter(result);
    exception.printStackTrace(printWriter);
    return result.toString();
  }
View Full Code Here

    public String toXML() {
        return element.asXML();
    }

    public String toString() {
        StringWriter out = new StringWriter();
        XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint());
        try {
            writer.write(element);
        }
        catch (Exception e) { }
        return out.toString();
    }
View Full Code Here

TOP

Related Classes of java.io.StringWriter

Copyright © 2018 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.