Package java.io

Examples of java.io.StringWriter


    JAXBContext jc = JAXBContext.newInstance(new Class<?>[] {VDBMetaData.class});
    Marshaller marshell = jc.createMarshaller();
    marshell.setSchema(schema);
    marshell.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,new Boolean(true));
   
    StringWriter sw = new StringWriter();
    marshell.marshal(vdb, sw);
       
    //System.out.println(sw.toString());

    // UnMarshell
    Unmarshaller un = jc.createUnmarshaller();
    un.setSchema(schema);
    vdb = (VDBMetaData)un.unmarshal(new StringReader(sw.toString()));
   
    assertEquals("myVDB", vdb.getName()); //$NON-NLS-1$
    assertEquals("vdb description", vdb.getDescription()); //$NON-NLS-1$
    assertEquals(1, vdb.getVersion());
    assertEquals("vdb-value", vdb.getPropertyValue("vdb-property")); //$NON-NLS-1$ //$NON-NLS-2$
View Full Code Here


        }
        objects.clear();
    }

    private void printError(int seed, int id, Throwable t) {
        StringWriter writer = new StringWriter();
        t.printStackTrace(new PrintWriter(writer));
        String s = writer.toString();
        TestBase.logError("new TestCrashAPI().init(test).testCase(" +
                seed + "); // Bug " + s.hashCode() + " id=" + id +
                " callCount=" + callCount + " openCount=" + openCount +
                " " + t.getMessage(), t);
        throw new RuntimeException(t);
View Full Code Here

        // TODO call right constructor
        // TODO use the right package
        ProxyCodeGenerator cg = new ProxyCodeGenerator();
        cg.setPackageName("bytecode");
        cg.generateClassProxy(c);
        StringWriter sw = new StringWriter();
        cg.write(new PrintWriter(sw));
        String code = sw.toString();
        String proxy = "bytecode."+ c.getSimpleName() + "Proxy";
        compiler.setSource(proxy, code);
        // System.out.println(code);
        Class<?> px = compiler.getClass(proxy);
        proxyMap.put(c, px);
View Full Code Here

    }

    private void testDataSource() throws SQLException {
        deleteDb("dataSource");
        JdbcDataSource ds = new JdbcDataSource();
        PrintWriter p = new PrintWriter(new StringWriter());
        ds.setLogWriter(p);
        assertTrue(p == ds.getLogWriter());
        ds.setURL(getURL("dataSource", true));
        ds.setUser(getUser());
        ds.setPassword(getPassword());
View Full Code Here

    }

    private void testShutdown() throws SQLException {
        String url = getURL("connectionPool2", true), user = getUser(), password = getPassword();
        JdbcConnectionPool cp = JdbcConnectionPool.create(url, user, password);
        StringWriter w = new StringWriter();
        cp.setLogWriter(new PrintWriter(w));
        Connection conn1 = cp.getConnection();
        Connection conn2 = cp.getConnection();
        conn1.close();
        conn2.createStatement().execute("shutdown immediately");
        cp.dispose();
        assertTrue(w.toString().length() > 0);
        cp.dispose();
    }
View Full Code Here

        man.setLoginTimeout(0);
        assertEquals(30, man.getLoginTimeout());
        assertEquals(10, man.getMaxConnections());

        PrintWriter old = man.getLogWriter();
        PrintWriter pw = new PrintWriter(new StringWriter());
        man.setLogWriter(pw);
        assertTrue(pw == man.getLogWriter());
        man.setLogWriter(old);

        Connection conn1 = man.getConnection();
View Full Code Here

       
        try {
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            StringWriter output = new StringWriter();
            transformer.transform(new DOMSource(target), new StreamResult(output));
           
            return output.toString();
        } catch (TransformerConfigurationException e) {
            // Things must be in pretty bad shape to get here so
            // rethrow as runtime exception
            throw new RuntimeException(e);
        } catch (TransformerException e) {
View Full Code Here

    incl_tmpl.setLoaderContext(context);

    // If the included section has modifiers applied, we buffer it into a
    // string so that we can apply the modifiers.
    PrintWriter previous_printwriter = null;
    StringWriter sw = null;
    if (modifiers.size() > 0) {
      previous_printwriter = collector;
      sw = new StringWriter();
      collector = new PrintWriter(sw);
    }

    List<TemplateDictionary> child_dicts = dict.getChildDicts(includeName);
    if (child_dicts.size() == 0) {
      incl_tmpl.render(dict, collector);
    } else {
      for (TemplateDictionary subdict : child_dicts) {
        incl_tmpl.render(subdict, collector);
      }
    }

    if (previous_printwriter != null) {
      String results = sw.toString();
      collector = previous_printwriter;
      collector.write(Modifiers.applyModifiers(results, modifiers));
    }
  }
View Full Code Here

    EztDefineNode edn = (EztDefineNode) list.get(define_node_idx);
    String var_name = edn.getVariableName();

    Range range = edn.advise(list, define_node_idx);
    List<TemplateNode> view = list.subList(range.getStart(), range.getStop());
    StringWriter sw = new StringWriter();
    render(view, td, new PrintWriter(sw));

    String new_value = sw.toString();
    td.put(var_name, new_value);

    return range.getSkipTo();
  }
View Full Code Here

  }

  private String renderToString(final List<TemplateNode> list,
                                final TemplateDictionary td)
      throws TemplateException {
    StringWriter k = new StringWriter();
    PrintWriter pw = new PrintWriter(k);
    render(list, td, pw);
    pw.flush();
    return k.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.