StringWriter close - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for StringWriter close method.

This code example shows how to use the following methods:close, toString
 
  public static String generateRegisterResponse(RegisterResponseEntry... entries)
      throws JsonGenerationException, JsonMappingException, IOException 
  { 
    ObjectMapper mapper = new ObjectMapper();
    StringWriter w = new StringWriter();
    mapper.writeValue(w, entries);
    w.close();
    return w.toString();
  } 
 
  public static String generateRegisterResponseV4(HashMap<String, List<Object>> entries)
      throws JsonGenerationException, JsonMappingException, IOException 
  { 
    ObjectMapper mapper = new ObjectMapper();
    StringWriter w = new StringWriter();
    mapper.writeValue(w, entries);
    w.close();
    return w.toString();
  } 
8
CodeRank
This code example shows how to use the following methods:close, toString
	} 
	 
	private void serializeConfig(ServerContainer.RuntimeConfig config, 
	                             WritableByteChannel destChannel) throws IOException
	{ 
      StringWriter out  = new StringWriter(10240);
      ObjectMapper mapper = new ObjectMapper();
      mapper.writeValue(out, config);
      out.close();
      byte[] dataBytes = out.toString().getBytes();
      destChannel.write(ByteBuffer.wrap(dataBytes));
	} 
	 
	private void doGetConfig(DatabusRequest request) throws IOException, 
			RequestProcessingException 
	{ 
		ServerContainer.RuntimeConfig config = request.getConfig();
		serializeConfig(config, request.getResponseContent());
	} 
 
8
CodeRank
This code example shows how to use the following methods:close, toString
	private void paintSnapshot() { 
		if (paintSnapshot) {
			String text = null;
 
			if (lastSnapshot != null) {
				final StringWriter writer = new StringWriter();
				final XmlWriter xmlWriter = new XmlWriter(writer, true);
 
				try { 
					((IXmlSerializable) lastSnapshot).writeXml(xmlWriter, new SerializableOptions(false));
					writer.close();
				} catch (IOException e) {
					Logger.logError(e);
				} 
				text = writer.toString();
			} 
			getTurnSnapshotScrollPane().setText(text);
		} 
	} 
 
8
CodeRank
This code example shows how to use the following methods:close, toString
     */ 
    private String convertJson(String entityText) throws IOException {
        HierarchicalStreamDriver driver = new JettisonMappedXmlDriver();
        StringReader reader = new StringReader(entityText);
        HierarchicalStreamReader hsr = driver.createReader(reader);
        StringWriter writer = new StringWriter();
        new HierarchicalStreamCopier().copy(hsr, new PrettyPrintWriter(writer));
        writer.close();
        return writer.toString();
    } 
 
    public void setXmlConfig(XMLConfiguration xmlConfig) {
        this.xmlConfig = xmlConfig;
    } 
 
    public void setTileBreeder(TileBreeder seeder) {
        this.seeder = seeder;
    } 
} 
8
CodeRank
This code example shows how to use the following methods:close, flush, toString
    } 
 
    private String toCOBieLite(COBIEDocument coBieDocument) throws IOException
    { 
        FacilityFactory factory = new FacilityFactory();
        StringWriter wrt = new StringWriter();
        factory.parse(coBieDocument).save(wrt, org.erdc.cobie.cobielite.Settings.XML_Beans_Settings
                .getSaveSettings());  
        wrt.flush();
        wrt.close();
        return wrt.toString();
    } 
     
    @Override 
    protected void writeCOBIE(OutputStream outputStream)
            throws SerializerException 
    { 
        try 
        { 
            executeTransform(outputStream);
7
CodeRank
This code example shows how to use the following methods:close, toString
        PrintWriter printwriter = null;
        String s = this.cause.toString();
 
        try 
        { 
            stringwriter = new StringWriter();
            printwriter = new PrintWriter(stringwriter);
            this.cause.printStackTrace(printwriter);
            s = stringwriter.toString();
        } 
        finally 
        { 
            try 
            { 
                if (stringwriter != null)
                { 
                    stringwriter.close();
                } 
 
                if (printwriter != null)

7
CodeRank
This code example shows how to use the following methods:close, toString
	assertTrue(key.isEncrypted());
 
    } 
 
    private String toString(OpenSSLKey key) throws Exception {
        StringWriter writer = new StringWriter();
        key.writeTo(writer);
        writer.close();
        String s = writer.toString();
        logger.debug(s);
        return s;
    } 
 
    public void testDecryptedToString() throws Exception { 
        KeyPair keyPair = getKeyPair();
	OpenSSLKey inKey = new BouncyCastleOpenSSLKey(keyPair.getPrivate());
	assertTrue(!inKey.isEncrypted());
         
        ByteArrayInputStream in = null;
        in = new ByteArrayInputStream(toString(inKey).getBytes());
7
CodeRank
This code example shows how to use the following methods:close, toString
	 */ 
	public static String fromJSONtoXML(String json) {
		HierarchicalStreamDriver driver = new JettisonMappedXmlDriver();
		StringReader reader = new StringReader(json);
		HierarchicalStreamReader hsr = driver.createReader(reader);
		StringWriter writer = new StringWriter();
		try { 
			new HierarchicalStreamCopier().copy(hsr, new PrettyPrintWriter(
					writer));
			return writer.toString();
		} finally { 
			if (writer != null) {
				try { 
					writer.close();
				} catch (IOException e) {
					// ignore 
				} 
			} 
		} 
	} 
6
CodeRank
This code example shows how to use the following methods:close, flush, toString
		try { 
			resp.setContentType("application/javascript");
			resp.setCharacterEncoding("utf-8");		
			if (desktopDefinitions == null)
			{ 
				StringWriter sw = new StringWriter();
				uio.emitDesktop(sw);
				sw.flush();
				sw.close();
				desktopDefinitions = sw.toString();
			} 
			resp.getWriter().write(desktopDefinitions);
		} catch (IOException e) {
			throw new UioException(e);
		}	 
	} 
 
	private void serveMobileDefinitions(HttpServletRequest req, HttpServletResponse resp) {
		try { 
			resp.setContentType("application/javascript");
7
CodeRank
This code example shows how to use the following methods:append, close, toString
	/** 
	 * @tests java.io.StringWriter#append(char) 
	 */ 
	public void test_appendChar() throws IOException { 
	    char testChar = ' ';
	    StringWriter stringWriter = new StringWriter(20);
	    stringWriter.append(testChar);
	    assertEquals(String.valueOf(testChar), stringWriter.toString());
	    stringWriter.close();
	} 
 
	/** 
	 * @tests java.io.PrintWriter#append(CharSequence) 
	 */ 
	public void test_appendCharSequence() throws IOException { 
 
	    String testString = "My Test String";
	    StringWriter stringWriter = new StringWriter(20);
	    stringWriter.append(testString);
	    assertEquals(String.valueOf(testString), stringWriter.toString());
6
CodeRank

Related StringWriter close Questions & Answers:

close Method Overview
Closing a StringWriter has no effect.
See Code Examples for other Java 8 StringWriter Methods: