private static List<String> getPublicKeys() throws Exception { return new JschConfigSessionFactory() { @Override protected void configure(OpenSshConfig.Host hc, Session session) { } List<String> getPublicKeys() throws Exception { JSch jSch = createDefaultJSch(FS.DETECTED); List<String> keys = new ArrayList<>(); for (Object o : jSch.getIdentityRepository().getIdentities()) { Identity i = (Identity) o; KeyPair keyPair = KeyPair.load(jSch, i.getName(), null); StringBuilder sb = new StringBuilder(); try (StringBuilderWriter sbw = new StringBuilderWriter(sb); OutputStream os = new WriterOutputStream(sbw, "UTF-8")) { keyPair.writePublicKey(os, keyPair.getPublicKeyComment()); } finally { keyPair.dispose(); } keys.add(sb.toString().trim()); } return keys; } }.getPublicKeys(); }
private void assertOutputConversion_viaCharsetName(String charsetName, boolean conversionErrorsExpected) throws Exception { byte[] originalBytes = createBytes(); { // byte array as byte stream ByteArrayOutputStream targetByteStream = new ByteArrayOutputStream(); // byte stream as character stream Writer targetWriter = new OutputStreamWriter(targetByteStream, charsetName); // modifying writer (we don't modify here) Writer modifyingWriter = new ModifyingWriter(targetWriter, new RegexModifier("a", 0, "a")); // character stream as byte stream OutputStream modifyingByteStream = new WriterOutputStream(modifyingWriter, charsetName); // byte stream as byte array IOUtils.write(originalBytes, modifyingByteStream); modifyingByteStream.close(); assertBytes(originalBytes, targetByteStream.toByteArray(), conversionErrorsExpected); } }
@Override public <C extends ICommand> void commandFailed(Class<C> command, Throwable cause) { try { StringWriter writer = new StringWriter(); writer.write("Command " + command.getName() + " failed"); if (cause.getMessage() != null) { writer.write(" with message " + cause.getMessage() + "\n"); } else { writer.write("\n"); } writer.write("Time stamp: " + DateTime.now() + "\n"); writer.write("Stacktrace: "); cause.printStackTrace(new PrintStream(new WriterOutputStream(writer))); fMailService.sendASAP(fDestinationEmailAddress, fSourceEmailAddress, writer.toString(), SCHEDULED_ERROR_SUBJECT); } catch (EmailException exception) { // The system failed at failing (looks like Windows) LOGGER.error("Error while reporting error for cron", exception); } }
public static String toString(ExpressionNode node) { StringWriter writer = new StringWriter(); try (PrintStream os = new PrintStream(new WriterOutputStream(writer, StandardCharsets.UTF_8))) { print(node, os); } return writer.toString(); }
@Override public void launch() throws IOException, InterruptedException { if (launchCommand == null) { commandField.setText("This launcher does not support launch in test mode."); showAndWait(); return; } launchCommand.copyOutputTo(new WriterOutputStream(new TextAreaWriter(outputArea), Charset.defaultCharset())); launchCommand.setMessageArea(new WriterOutputStream(new TextAreaWriter(errorArea), Charset.defaultCharset())); if (launchCommand.start() == ITestLauncher.OK_OPTION) { commandField.setText(launchCommand.toString()); showAndWait(); } }
@Test public void test() throws Exception { String config; try(StringWriter sw = new StringWriter(); OutputStream osw = new WriterOutputStream(sw, StandardCharsets.UTF_8)) { service.write(MimeTypeUtils.APPLICATION_JSON_VALUE, osw); config = sw.toString(); } System.out.println(config); try (StringReader sr = new StringReader(config); InputStream is = new ReaderInputStream(sr, StandardCharsets.UTF_8)) { service.read(MimeTypeUtils.APPLICATION_JSON_VALUE, is); } sampleBean.check(); }
/** * Dekodiert einen UTF-8-QUOTED-PRINTABLE-String in einen Java-Unicode-String. */ public String decode(String in) { try { InputStream input = MimeUtility.decode(new ReaderInputStream(new StringReader(in), "UTF-8"), "quoted-printable"); StringWriter sw = new StringWriter(); OutputStream output = new WriterOutputStream(sw, "UTF-8"); copyAndClose(input, output); return sw.toString(); } catch (Exception e) { throw new RuntimeException("Exception caught in VntConverter.encode(in):", e); } }
/** * Enkodiert einen Java-Unicode-String in einen UTF-8-QUOTED-PRINTABLE-String. */ public String encode(String in) { try { InputStream input = new ReaderInputStream(new StringReader(in), "UTF-8"); StringWriter sw = new StringWriter(); OutputStream output = MimeUtility.encode(new WriterOutputStream(sw), "quoted-printable"); copyAndClose(input, output); return sw.toString().replaceAll("=\\x0D\\x0A", "").replaceAll("\\x0D\\x0A", "=0D=0A"); } catch (Exception e) { throw new RuntimeException("Exception caught in VntConverter.encode(in):", e); } }
private Future<CommandResult> executeCommand(String command, File executionDirectory, boolean silent) throws IOException { StringWriter writer = new StringWriter(); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); try (WriterOutputStream outputStream = new WriterOutputStream(writer)) { String outerCommand = "/bin/bash -lc"; CommandLine outer = CommandLine.parse(outerCommand); outer.addArgument(command, false); DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(executionDirectory); executor.setStreamHandler(new PumpStreamHandler(silent ? outputStream : System.out, null)); executor.execute(outer, ENVIRONMENT, resultHandler); resultHandler.waitFor(); } catch (InterruptedException e) { throw new IllegalStateException(e); } return new AsyncResult<CommandResult>( new CommandResult(resultHandler.getExitValue(), writer.toString(), resultHandler.getException())); }
private void assertOutputConversion_viaCharsetEncoder(String charsetName, boolean conversionErrorsExpected) throws Exception { // find charset Charset charset = Charset.forName(charsetName); // // configure decoder // CharsetDecoder decoder = charset.newDecoder(); // decoder.onUnmappableCharacter(CodingErrorAction.REPORT); // configure encoder CharsetEncoder encoder = charset.newEncoder(); encoder.onUnmappableCharacter(CodingErrorAction.REPORT); byte[] originalBytes = createBytes(); boolean conversionErrorsFound; try { // byte array as byte stream ByteArrayOutputStream targetByteStream = new ByteArrayOutputStream(); // byte stream as character stream Writer targetWriter = new OutputStreamWriter(targetByteStream, encoder); // modifying writer (we don't modify here) Writer modifyingWriter = new ModifyingWriter(targetWriter, new RegexModifier("a", 0, "a")); // character stream as byte stream OutputStream modifyingByteStream = new WriterOutputStream(modifyingWriter, charset); // encoder // not // supported // here!!! // byte stream as byte array IOUtils.write(originalBytes, modifyingByteStream); modifyingByteStream.close(); assertBytes(originalBytes, targetByteStream.toByteArray(), conversionErrorsExpected); conversionErrorsFound = false; } catch (MalformedInputException e) { conversionErrorsFound = true; } assertEquals(conversionErrorsExpected, conversionErrorsFound); }
@Override protected void doSave(XMISerializer serializer, CDOTransaction trans, String realCdoRepositoryPath) throws IOException { CDOTextResource textRes = trans.getOrCreateTextResource(realCdoRepositoryPath); textRes.setEncoding(DEFAULT_CHARSET_NAME); StringWriter writer = new StringWriter(); try (WriterOutputStream wos = new WriterOutputStream(writer, DEFAULT_CHARSET)) { serializer.serialize(wos); try (StringReader reader = new StringReader(writer.getBuffer().toString())) { CDOClob clob = new CDOClob(reader); textRes.setContents(clob); } } }
/** * Writes out a given name / value pair. * This is similar to {@link XMLWriter#writeVal(String, Object)}. * This is needed because that similar method is not extensible and cannot be overriden * (it is called recursively by other methods). * * @param name the name of the attribute. * @param value the value of the attribute. * @param data the complete set of response values. * @throws IOException in case of I/O failure. */ public void writeValue(final String name, final Object value, final NamedList<?> data) throws IOException { if (value == null) { writeNull(name); } else if (value instanceof ResultSet) { final int start = req.getParams().getInt(CommonParams.START, 0); final int rows = req.getParams().getInt(CommonParams.ROWS, 10); writeStartDocumentList("response", start, rows, (Integer) data.remove(Names.NUM_FOUND), 1.0f); final XMLOutput outputter = new XMLOutput(false); outputter.format(new WriterOutputStream(writer), (ResultSet)value); writeEndDocumentList(); } else if (value instanceof String || value instanceof Query) { writeStr(name, value.toString(), false); } else if (value instanceof Number) { if (value instanceof Integer || value instanceof Short || value instanceof Byte) { writeInt(name, value.toString()); } else if (value instanceof Long) { writeLong(name, value.toString()); } else if (value instanceof Float) { writeFloat(name, ((Float) value).floatValue()); } else if (value instanceof Double) { writeDouble(name, ((Double) value).doubleValue()); } } else if (value instanceof Boolean) { writeBool(name, value.toString()); } else if (value instanceof Date) { writeDate(name, (Date) value); } else if (value instanceof Map) { writeMap(name, (Map<?,?>) value, false, true); } else if (value instanceof NamedList) { writeNamedList(name, (NamedList<?>) value); } else if (value instanceof Iterable) { writeArray(name, ((Iterable<?>) value).iterator()); } else if (value instanceof Object[]) { writeArray(name, (Object[]) value); } else if (value instanceof Iterator) { writeArray(name, (Iterator<?>) value); } }
public static void setupLogging(Session session, Log log, ParameterInclude params) throws AxisFault { // Note that debugging might already be enabled by the mail.debug property and we should // take care to override it. if (log.isTraceEnabled()) { // This is the old behavior: just set debug to true session.setDebug(true); } if (ParamUtils.getOptionalParamBoolean(params, MailConstants.TRANSPORT_MAIL_DEBUG, false)) { // Redirect debug output to where it belongs, namely to the logs! session.setDebugOut(new PrintStream(new WriterOutputStream(new LogWriter(log)), true)); // Only enable debug afterwards since the call to setDebug might already cause debug output session.setDebug(true); } }
@BeforeClass public static void beforeClass() { realSystemOut = System.out; WriterOutputStream wout = new WriterOutputStream(out); PrintStream pw = new PrintStream(wout); System.setOut(pw); }
/** * Output the data of the table as a JSON * * @param table * the {@link ConsoleTable} to output * * @param writer * the {@link PrintWriter} to write to */ public void writeJson(ConsoleTable table, PrintWriter writer) { OutputStream os = new WriterOutputStream(writer); PrintStream ps = new PrintStream(os); try { writeJson(table, ps); } finally { ps.close(); } }
/** * Output the data of the table as a CSV * * @param table * the {@link ConsoleTable} to output * * @param writer * the {@link PrintWriter} to write to */ public void writeCsv(ConsoleTable table, PrintWriter writer) { OutputStream os = new WriterOutputStream(writer); PrintStream ps = new PrintStream(os); try { writeCsv(table, ps); } finally { ps.close(); } }
@Test public void testSerializeEquals() throws IOException, JAXBException { StringWriter serialized = new StringWriter(); WriterOutputStream outputStream = new WriterOutputStream(serialized); ProfileSerializer.serialize(outputStream, simulation); outputStream.close(); Simulation copy = ProfileSerializer.deserialize(new ReaderInputStream(new StringReader(serialized.toString()))); Assert.assertEquals("Simulation equals serialized-deserialized copy", simulation, copy); }
private static OutputStream toOutputStream(Writer standardOutput) { return new WriterOutputStream(standardOutput, Charset.defaultCharset()); }
public void write( ImportData data, Writer writer ) throws IOException { write( data, new WriterOutputStream( writer ) ); }
/** * Tests configuring the server w/o xml but configuring the JAXB objects directly. */ @Test public void embeddedServerProgrammatic() throws Exception { File homeDir = util.createTempDir("orientdb-home").getCanonicalFile(); System.setProperty("orient.home", homeDir.getPath()); System.setProperty(Orient.ORIENTDB_HOME, homeDir.getPath()); OServer server = new OServer(); OServerConfiguration config = new OServerConfiguration(); // Unsure what this is used for, its apparently assigned to xml location, but forcing it here config.location = "DYNAMIC-CONFIGURATION"; File databaseDir = new File(homeDir, "db"); config.properties = new OServerEntryConfiguration[] { new OServerEntryConfiguration("server.database.path", databaseDir.getPath()) }; config.handlers = Lists.newArrayList(); config.hooks = Lists.newArrayList(); config.network = new OServerNetworkConfiguration(); config.network.protocols = Lists.newArrayList( new OServerNetworkProtocolConfiguration("binary", ONetworkProtocolBinary.class.getName()) ); OServerNetworkListenerConfiguration binaryListener = new OServerNetworkListenerConfiguration(); binaryListener.ipAddress = "0.0.0.0"; binaryListener.portRange = "2424-2430"; binaryListener.protocol = "binary"; binaryListener.socket = "default"; config.network.listeners = Lists.newArrayList( binaryListener ); config.storages = new OServerStorageConfiguration[] {}; config.users = new OServerUserConfiguration[] { new OServerUserConfiguration("admin", "admin", "*") }; config.security = new OServerSecurityConfiguration(); config.security.users = Lists.newArrayList(); config.security.resources = Lists.newArrayList(); server.startup(config); // Dump config to log stream StringWriter buff = new StringWriter(); OGlobalConfiguration.dumpConfiguration(new PrintStream(new WriterOutputStream(buff), true)); log("Global configuration:\n{}", buff); server.activate(); server.shutdown(); }
@Override protected void init() throws IOException { super.init(); this.commandFactory = new CommandFactoryWithIO(this.commandFactory, new PrintStream(new WriterOutputStream(out)), System.err); }
@Override public Object eval(String userExecutableClassName, ScriptContext context) throws ScriptException { try { JavaExecutable javaExecutable = getExecutable(userExecutableClassName); JavaStandaloneExecutableInitializer execInitializer = new JavaStandaloneExecutableInitializer(); PrintStream output = new PrintStream(new WriterOutputStream(context.getWriter()), true); execInitializer.setOutputSink(output); PrintStream error = new PrintStream(new WriterOutputStream(context.getErrorWriter()), true); execInitializer.setErrorSink(error); Map<String, byte[]> propagatedVariables = null; if (context.getAttribute(SchedulerConstants.VARIABLES_BINDING_NAME) != null) { propagatedVariables = SerializationUtil.serializeVariableMap(((VariablesMap) context.getAttribute(SchedulerConstants.VARIABLES_BINDING_NAME)).getPropagatedVariables()); execInitializer.setPropagatedVariables(propagatedVariables); } else { execInitializer.setPropagatedVariables(Collections.<String, byte[]> emptyMap()); } if (context.getAttribute(Script.ARGUMENTS_NAME) != null) { execInitializer.setSerializedArguments((Map<String, byte[]>) ((Serializable[]) context.getAttribute(Script.ARGUMENTS_NAME))[0]); } else { execInitializer.setSerializedArguments(Collections.<String, byte[]> emptyMap()); } if (context.getAttribute(SchedulerConstants.CREDENTIALS_VARIABLE) != null) { execInitializer.setThirdPartyCredentials((Map<String, String>) context.getAttribute(SchedulerConstants.CREDENTIALS_VARIABLE)); } else { execInitializer.setThirdPartyCredentials(Collections.<String, String> emptyMap()); } if (context.getAttribute(SchedulerConstants.MULTI_NODE_TASK_NODESURL_BINDING_NAME) != null) { List<String> nodesURLs = (List<String>) context.getAttribute(SchedulerConstants.MULTI_NODE_TASK_NODESURL_BINDING_NAME); execInitializer.setNodesURL(nodesURLs); } else { execInitializer.setNodesURL(Collections.<String> emptyList()); } javaExecutable.internalInit(execInitializer, context); Serializable execute = javaExecutable.execute((TaskResult[]) context.getAttribute(SchedulerConstants.RESULTS_VARIABLE)); if (propagatedVariables != null) { ((Map<String, Serializable>) context.getAttribute(SchedulerConstants.VARIABLES_BINDING_NAME)).putAll(javaExecutable.getVariables()); } output.close(); error.close(); return execute; } catch (Throwable e) { throw new ScriptException(new TaskException(getStackTraceAsString(e), e)); } }
public void testHomepageExample_OutputStream() throws Exception { String charsetName = "ISO-8859-1"; byte[] originalBytes = new byte[] { 1, 2, "\r".getBytes("ISO-8859-1")[0], 4, 5 }; // get byte stream ByteArrayOutputStream targetByteStream = new ByteArrayOutputStream(); // byte stream as character stream Writer targetWriter = new OutputStreamWriter(targetByteStream, charsetName); // create the modifying writer Writer modifyingWriter = new ModifyingWriter(targetWriter, new RegexModifier("\r", 0, "")); // character stream as byte stream OutputStream modifyingByteStream = new WriterOutputStream(modifyingWriter, charsetName); modifyingByteStream.write(originalBytes); // modifyingByteStream.flush(); modifyingByteStream.close(); byte[] expectedBytes = new byte[] { 1, 2, 4, 5 }; assertBytes(expectedBytes, targetByteStream.toByteArray(), false); }
@Override public void writeTo(Writer writer, Syntax syntax) throws IOException, ModelRuntimeException, SyntaxNotSupportedException { WriterOutputStream stream = new WriterOutputStream(writer, StandardCharsets.UTF_8); writeTo(stream, syntax); }
@BeforeTest public void recompile() throws IOException, NoSuchMethodException, NoSuchFieldException, ClassNotFoundException, InvocationTargetException, IllegalAccessException { libJar = createJar(LIB_CLASSES); examJar = createJar(TEST_CLASSES); tempDir = new File(FileUtils.getTempDirectory(), File.createTempFile("stubgen", "").getName() + "dir"); tempDir.mkdirs(); URLClassLoader nonTestCl = getNonTestCL(); Class<?> stubGenClass = nonTestCl.loadClass(StubGen.class.getName()); Method mainMethod = stubGenClass.getMethod("main", String[].class); Object args = new String[]{"-e", examJar.getAbsolutePath(), "-l", libJar.getAbsolutePath(), "-o", tempDir.getAbsolutePath()}; mainMethod.invoke(null, args); System.out.println(libJar); System.out.println(examJar); System.out.println(tempDir); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); Collection<File> allJavaFiles = FileUtils.listFiles(tempDir, new String[]{"java"}, true); if (allJavaFiles.isEmpty()) { fail("StubGen output is empty"); } String[] allJavaPaths = new String[allJavaFiles.size()]; int i = 0; for (File file : allJavaFiles) { allJavaPaths[i++] = file.getAbsolutePath(); } StringWriter errorWriter = new StringWriter(); compiler.run(null, null, new WriterOutputStream(errorWriter), allJavaPaths); String errors = errorWriter.toString(); if (!errors.isEmpty()) { fail(errors); } stubClassLoader = new URLClassLoader(new URL[]{new URL("file:" + tempDir.getAbsolutePath() + "/")}, getClass().getClassLoader().getParent()); }
public static OutputStream outputStream(StringBuilder output) { return new WriterOutputStream(new StringBuilderWriter(output), Charset.defaultCharset(), 1024, true); }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { return new WriterOutputStream(writer, "UTF-8"); }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { return new WriterOutputStream(writer, StandardCharsets.UTF_8); }
@Test public void workWithStream() { InputStream in = null; try { String content = "Stream testing"; //String - > InputStream. in = IOUtils.toInputStream(content, "UTF-8"); //String - > OutputStream System.out.println("String to OutputStram:"); IOUtils.write(content, System.out, "UTF-8"); //////////////////// //InputStream/Reader -> String System.out.println("\nInputStram to String:"); System.out.println(IOUtils.toString(in, "UTF-8")); //InputStream/Reader -> OutputStream/Writer, 四者间可任意组合. InputStream in2 = IOUtils.toInputStream(content); //重新准备inputSteam System.out.println("InputStream to OutputStream:"); IOUtils.copy(in2, System.out); /////////////////// //InputStream ->Reader InputStreamReader reader = new InputStreamReader(in, Charsets.UTF_8); //Reader->InputStream ReaderInputStream in3 = new ReaderInputStream(reader, Charsets.UTF_8); //OutputStream ->Writer OutputStreamWriter writer = new OutputStreamWriter(System.out, Charsets.UTF_8); //Writer->OutputStream WriterOutputStream out2 = new WriterOutputStream(writer, Charsets.UTF_8); ////////////////////// //收集Writer的输出内容到String. StringWriter sw = new StringWriter(); sw.write("I am String writer"); System.out.println("\nCollect writer content:"); System.out.println(sw.toString()); } catch (IOException e) { Exceptions.unchecked(e); } finally { //安静的关闭Stream IOUtils.closeQuietly(in); } }
/** * Start all listeners */ private synchronized void start() { if (started) { // Someone jumped in ahead of us return; } // We start no matter what started = true; StringBuffer sb = new StringBuffer(1024); sb.append("\nStarting ..."); if (logger.isDebugEnabled()) { logger.debug("Starting components: " + name); } for (LifecycleListener listener : lifecycleListeners) { String listenerName = listener.getClass().getName(); if (logger.isDebugEnabled()) { logger.debug(" Starting component: " + listenerName); } try { listener.start(); if (logger.isDebugEnabled()) { logger.debug(" Started component: " + listenerName); } sb.append("\n Started component: " + listenerName); } catch (Exception e) { // Absorb the exception logger.error(" Failed to start component: " + listenerName, e); sb.append("\n Failed to start component: " + listenerName); StringWriter stackWriter = new StringWriter(1024); WriterOutputStream wos = new WriterOutputStream(stackWriter); PrintWriter pw = new PrintWriter(wos); try { e.printStackTrace(pw); } finally { try { pw.close(); } catch (Exception ee) {} } sb.append("\n").append(stackWriter.getBuffer().toString()); // Now respect the forceStart option if (!forceStart) { throw new RuntimeException("Component failed to start: " + listenerName, e); } } } if (logger.isDebugEnabled()) { logger.debug("Started components: " + name); } log.append(sb.toString()); }
/** * Stop all listeners */ private synchronized void stop() { if (!started) { // Someone jumped in ahead of us return; } // We have stopped no matter what started = false; StringBuffer sb = new StringBuffer(1024); sb.append("\nStopping ..."); if (logger.isDebugEnabled()) { logger.debug("Stopping components: " + name); } for (LifecycleListener listener : lifecycleListeners) { String listenerName = listener.getClass().getName(); if (logger.isDebugEnabled()) { logger.debug(" Stopping component: " + listenerName); } try { listener.stop(); if (logger.isDebugEnabled()) { logger.debug(" Stopped component: " + listenerName); } sb.append("\n Stopped component: " + listenerName); } catch (Exception e) { // Absorb the exception logger.error(" Failed to stop component: " + listenerName, e); sb.append("\n Failed to stop component: " + listenerName); StringWriter stackWriter = new StringWriter(1024); WriterOutputStream wos = new WriterOutputStream(stackWriter); PrintWriter pw = new PrintWriter(wos); try { e.printStackTrace(pw); } finally { try { pw.close(); } catch (Exception ee) {} } sb.append("\n").append(stackWriter.getBuffer().toString()); } } if (logger.isDebugEnabled()) { logger.debug("Stopped components: " + name); } log.append(sb.toString()); }
/** * Output the data as an XML. * * @param table * the {@link ConsoleTable} to output * * @param writer * the {@link PrintStream} to write to * * @param parentXmlTag * the uber XML tag to wrap items into * * @param rowTag * the tag to use for wrapping each row of data */ public void writeXml(ConsoleTable table, PrintWriter writer, String parentXmlTag, String rowTag) { OutputStream os = new WriterOutputStream(writer); PrintStream ps = new PrintStream(os); try { writeJson(table, ps); } finally { ps.close(); } }
/** * Outputs the Document associated with this node to an XML string and writes it to the given Writer. An OutputStream * is preferred when writing XML as the XML serialiser can control exactly which bytes are written as characters and * which should be escaped. * @param pWriter Writer for serialization destination. * @param pPrettyPrint If true, the XML is pretty-printed. This should only be used when the XML is being output to a * location where it needs to be human-readable. Pretty-printing introduces extra whitespace, potentially corrupting a * document, so it should be used with care. */ public void outputDocumentToWriter(Writer pWriter, boolean pPrettyPrint) { outputDocumentToOutputStream(new WriterOutputStream(pWriter, "UTF-8"), pPrettyPrint); }
/** * Outputs this node to an XML string and writes it to the given Writer. An OutputStream is preferred when writing XML * as the XML serialiser can control exactly which bytes are written as characters and which should be escaped. * * @param pWriter Writer for serialization destination. * @param pPrettyPrint If true, the XML is pretty-printed. This should only be used when the XML is being output to a * location where it needs to be human-readable. Pretty-printing introduces extra whitespace, potentially corrupting a * document, so it should be used with care. */ public void outputNodeToWriter(Writer pWriter, boolean pPrettyPrint) { DocControl.getDocControl(mXOMNode).mActuate.outputNode(mXOMNode, new WriterOutputStream(pWriter, "UTF-8"), pPrettyPrint, false); }
/** * Writes an instance of a dawg to a Writer. Once the data is written to the Writer, it is flushed, but the writer is * not closed. * * @param writer the Writer to write the dawg to * @throws IOException if writing the dawg to the writer causes an IOException */ public void store (Writer writer) throws IOException { store (new WriterOutputStream (writer)); }