Search in sources :

Example 1 with FastCharArrayWriter

use of jodd.io.FastCharArrayWriter in project jodd by oblac.

the class DecoraParserTest method testDecoraParser.

@Test
public void testDecoraParser() throws IOException {
    DecoraParser decoraParser = new DecoraParser();
    FindFile ff = new WildcardFindFile().include("*.*ml");
    ff.setMatchType(FindFile.Match.NAME);
    ff.searchPath(testDataRoot);
    File file;
    while ((file = ff.nextFile()) != null) {
        System.out.println("+" + file.getName());
        char[] page = FileUtil.readString(file).toCharArray();
        String decoratorFileName = StringUtil.replace(file.getAbsolutePath(), ".html", "-decora.htm");
        char[] decorator = FileUtil.readString(decoratorFileName).toCharArray();
        FastCharArrayWriter writer = new FastCharArrayWriter();
        decoraParser.decorate(writer, page, decorator);
        String out = writer.toString();
        String outFileName = StringUtil.replace(file.getAbsolutePath(), ".html", "-out.htm");
        String outExpected = FileUtil.readString(outFileName);
        assertEquals(trimLines(outExpected), trimLines(out));
    }
}
Also used : FastCharArrayWriter(jodd.io.FastCharArrayWriter) WildcardFindFile(jodd.io.findfile.WildcardFindFile) FindFile(jodd.io.findfile.FindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) File(java.io.File) FindFile(jodd.io.findfile.FindFile) WildcardFindFile(jodd.io.findfile.WildcardFindFile) Test(org.junit.Test)

Example 2 with FastCharArrayWriter

use of jodd.io.FastCharArrayWriter in project jodd by oblac.

the class Props method load.

/**
	 * Loads properties from input stream and provided encoding.
	 * Stream is not closed at the end.
	 */
public void load(final InputStream in, final String encoding) throws IOException {
    final Writer out = new FastCharArrayWriter();
    StreamUtil.copy(in, out, encoding);
    parse(out.toString());
}
Also used : FastCharArrayWriter(jodd.io.FastCharArrayWriter) FastCharArrayWriter(jodd.io.FastCharArrayWriter) Writer(java.io.Writer)

Example 3 with FastCharArrayWriter

use of jodd.io.FastCharArrayWriter in project jodd by oblac.

the class BasePropsTest method readDataFile.

protected String readDataFile(String fileName) throws IOException {
    String dataFolder = this.getClass().getPackage().getName() + ".data.";
    dataFolder = dataFolder.replace('.', '/');
    InputStream is = ClassLoaderUtil.getResourceAsStream(dataFolder + fileName);
    Writer out = new FastCharArrayWriter();
    String encoding = "UTF-8";
    if (fileName.endsWith(".properties")) {
        encoding = "ISO-8859-1";
    }
    StreamUtil.copy(is, out, encoding);
    StreamUtil.close(is);
    return out.toString();
}
Also used : InputStream(java.io.InputStream) FastCharArrayWriter(jodd.io.FastCharArrayWriter) FastCharArrayWriter(jodd.io.FastCharArrayWriter) Writer(java.io.Writer)

Example 4 with FastCharArrayWriter

use of jodd.io.FastCharArrayWriter in project jodd by oblac.

the class DomBuilderTest method testAppendable.

@Test
public void testAppendable() {
    LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder();
    Document document = lagartoDOMBuilder.parse("<div foo=\"123\">some <b>nice</b> text</div>");
    Element div = (Element) document.getFirstChild();
    String textContent = div.getTextContent();
    StringBuilder stringBuilder = new StringBuilder();
    div.appendTextContent(stringBuilder);
    assertEquals(textContent, stringBuilder.toString());
    FastCharArrayWriter charBuffer = new FastCharArrayWriter();
    div.appendTextContent(charBuffer);
    assertEquals(textContent, charBuffer.toString());
}
Also used : FastCharArrayWriter(jodd.io.FastCharArrayWriter) Test(org.junit.Test)

Example 5 with FastCharArrayWriter

use of jodd.io.FastCharArrayWriter in project jodd by oblac.

the class Buffer method getWriter.

/**
	 * Returns a writer.
	 */
public PrintWriter getWriter() {
    if (outWriter == null) {
        if (outStream != null) {
            throw new IllegalStateException("Can't call getWriter() after getOutputStream()");
        }
        bufferedWriter = new FastCharArrayWriter();
        outWriter = new PrintWriter(bufferedWriter) {

            @Override
            public void close() {
            // do not close the print writer after rendering
            // since it will remove reference to bufferedWriter
            }
        };
    }
    return outWriter;
}
Also used : FastCharArrayWriter(jodd.io.FastCharArrayWriter) PrintWriter(java.io.PrintWriter)

Aggregations

FastCharArrayWriter (jodd.io.FastCharArrayWriter)9 Writer (java.io.Writer)3 PrintWriter (java.io.PrintWriter)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 FindFile (jodd.io.findfile.FindFile)1 WildcardFindFile (jodd.io.findfile.WildcardFindFile)1 FileUpload (jodd.upload.FileUpload)1 MultipartStreamParser (jodd.upload.MultipartStreamParser)1 RandomString (jodd.util.RandomString)1