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));
}
}
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());
}
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();
}
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());
}
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;
}
Aggregations