List of usage examples for org.apache.commons.io.output StringBuilderWriter toString
@Override
public String toString()
From source file:com.yahoo.glimmer.util.ReadersWriterMergeSortTest.java
@Test public void noReadersTest() throws IOException { List<BufferedReader> sourceReaders = new ArrayList<BufferedReader>(); StringBuilderWriter writer = new StringBuilderWriter(); ReadersWriterMergeSort.mergeSort(sourceReaders, writer); assertEquals("", writer.toString()); }
From source file:com.yahoo.glimmer.util.ReadersWriterMergeSortTest.java
@Test public void emptyReadersTest() throws IOException { List<BufferedReader> sourceReaders = new ArrayList<BufferedReader>(); sourceReaders.add(new BufferedReader(new StringReader(""))); sourceReaders.add(new BufferedReader(new StringReader(""))); sourceReaders.add(new BufferedReader(new StringReader(""))); StringBuilderWriter writer = new StringBuilderWriter(); ReadersWriterMergeSort.mergeSort(sourceReaders, writer); assertEquals("", writer.toString()); }
From source file:com.yahoo.glimmer.util.ReadersWriterMergeSortTest.java
@Test public void noNewLinesTest() throws IOException { List<BufferedReader> sourceReaders = new ArrayList<BufferedReader>(); sourceReaders.add(new BufferedReader(new StringReader("B"))); sourceReaders.add(new BufferedReader(new StringReader("A"))); sourceReaders.add(new BufferedReader(new StringReader("1"))); sourceReaders.add(new BufferedReader(new StringReader(""))); StringBuilderWriter writer = new StringBuilderWriter(); ReadersWriterMergeSort.mergeSort(sourceReaders, writer); assertEquals("1\nA\nB\n", writer.toString()); }
From source file:com.yahoo.glimmer.util.ReadersWriterMergeSortTest.java
@Test public void newLinesFirstTest() throws IOException { List<BufferedReader> sourceReaders = new ArrayList<BufferedReader>(); sourceReaders.add(new BufferedReader(new StringReader("A%1"))); sourceReaders.add(new BufferedReader(new StringReader("A1"))); sourceReaders.add(new BufferedReader(new StringReader("A"))); StringBuilderWriter writer = new StringBuilderWriter(); ReadersWriterMergeSort.mergeSort(sourceReaders, writer); assertEquals("A\nA%1\nA1\n", writer.toString()); }
From source file:com.yahoo.glimmer.util.ReadersWriterMergeSortTest.java
@Test public void simple1Test() throws IOException { List<BufferedReader> sourceReaders = new ArrayList<BufferedReader>(); sourceReaders.add(new BufferedReader(new StringReader("Hello\nWorld!"))); sourceReaders.add(new BufferedReader(new StringReader("Baa\nBaz\nFoo"))); sourceReaders.add(new BufferedReader(new StringReader("2\n6\n8\nZ\n"))); StringBuilderWriter writer = new StringBuilderWriter(); ReadersWriterMergeSort.mergeSort(sourceReaders, writer); assertEquals("2\n" + "6\n" + "8\n" + "Baa\n" + "Baz\n" + "Foo\n" + "Hello\n" + "World!\n" + "Z\n", writer.toString()); }
From source file:com.meltmedia.rodimus.RodimusCli.java
public static void transformDocument(File inputFile, File outputDir, boolean verbose) throws Exception { StreamSource xhtmlHandlerSource = createStreamSource(RodimusCli.class.getResource("/rodimus.xsl")); File indexFile = new File(outputDir, "index.html"); File assetDir = new File(outputDir, IMAGE_DIR_NAME); assetDir.mkdirs();/*from www . j av a 2 s. com*/ // Set up the output buffer. StringBuilderWriter output = new StringBuilderWriter(); // Set up the serializer. ToXMLStream serializer = new ToXMLStream(); serializer.setOutputProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, String.valueOf(2)); serializer.setOutputProperty(OutputPropertiesFactory.S_KEY_LINE_SEPARATOR, "\n"); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputPropertiesFactory.S_KEY_ENTITIES, "yes"); serializer.setOutputProperty(OutputKeys.ENCODING, "US-ASCII"); serializer.setWriter(output); // Set up the xhtmlStructure handler. TransformerHandler xhtmlHandler = getContentHandler(xhtmlHandlerSource); xhtmlHandler.setResult(new SAXResult(serializer)); // build the Tika handler. ParseContext context = createParseContext(assetDir, verbose); PostTikaHandler cleanUp = new PostTikaHandler(IMAGE_DIR_NAME); cleanUp.setContentHandler(xhtmlHandler); parseInput(createInputStream(inputFile), cleanUp, context, verbose); // Do some regular expression cleanup. String preOutput = output.toString(); preOutput = preOutput.replaceAll("/>", " />"); // TODO: img is in this list, but it is not a block level element. String blockLevel = "(?:address|article|aside|audio|blockquote|canvas|dd|div|dl|fieldset|figcaption|figure|footer|form|h[1-6]|header|hgroup|hr|noscript|ol|output|p|pre|sectop|table|tfoot|ul|video|img)"; preOutput = preOutput.replaceAll("(</" + blockLevel + ">)(\\s*)(<" + blockLevel + ")", "$1$2$2$3"); preOutput = "<!doctype html>\n" + preOutput; FileUtils.write(indexFile, preOutput, "UTF-8"); // Clean out images dir if it's empty if (assetDir.list().length == 0) { FileUtils.deleteQuietly(assetDir); } }
From source file:ezbake.amino.cli.Main.java
public String getJarName() { StringBuilderWriter stringBuilderWriter = new StringBuilderWriter(); stringBuilderWriter.append("java -jar jarFilename "); cmdLineParser.printSingleLineUsage(stringBuilderWriter, null); return stringBuilderWriter.toString(); }
From source file:com.codeabovelab.dm.mail.template.VelocityMailTemplateEngine.java
private String evaluate(MailSource source, Reader reader) { StringBuilderWriter writer = new StringBuilderWriter(); VelocityContext context = new VelocityContext(); final Map<String, Object> variables = source.getVariables(); fillContext(context, variables);/*from w w w .java 2 s. c o m*/ String templateUri = source.getTemplateUri(); if (templateUri == null) { // velocity does not allow null template name templateUri = "<unknown template>"; } velocityEngine.evaluate(context, writer, templateUri, reader); return writer.toString(); }
From source file:launcher.net.CustomIOUtils.java
/** * Get the contents of a <code>Reader</code> as a String. * <p>/*from w w w .j a v a2 s. com*/ * This method buffers the input internally, so there is no need to use a * <code>BufferedReader</code>. * * @param input the <code>Reader</code> to read from * @return the requested String * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs */ public static String toString(Reader input) throws IOException { StringBuilderWriter sw = new StringBuilderWriter(); copy(input, sw); return sw.toString(); }
From source file:launcher.net.CustomIOUtils.java
/** * Get the contents of an <code>InputStream</code> as a String * using the specified character encoding. * <p>//ww w . j a v a 2s.co m * This method buffers the input internally, so there is no need to use a * <code>BufferedInputStream</code>. * </p> * @param input the <code>InputStream</code> to read from * @param encoding the encoding to use, null means platform default * @return the requested String * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since 2.3 */ public static String toString(InputStream input, Charset encoding) throws IOException { StringBuilderWriter sw = new StringBuilderWriter(); copy(input, sw, encoding); return sw.toString(); }