These code examples were ranked by Codota’s semantic indexing as the best open source examples for StringWriter close method.
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(); }
} 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()); }
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); } }
*/ 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; } }
} 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);
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)
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());
*/ 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 } } } }
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");
/** * @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());