use of org.grails.buffer.StreamCharBuffer in project grails-core by grails.
the class MockGrailsApplication method testPrintStreamCharBufferWithClosure.
@Test
public void testPrintStreamCharBufferWithClosure() throws IOException {
FastStringWriter stringwriter = new FastStringWriter();
CodecPrintWriter writer = new CodecPrintWriter(stringwriter, getEncoder(new MockGrailsApplication(), CodecWithClosureProperties.class), registry);
StreamCharBuffer buf = new StreamCharBuffer();
buf.getWriter().write("hola");
writer.write(buf);
writer.flush();
assertEquals("-> hola <-", stringwriter.getValue());
}
use of org.grails.buffer.StreamCharBuffer in project grails-core by grails.
the class ChainedEncoders method chainMixedEncode.
private static void chainMixedEncode(StreamEncodeable streamEncodeable, EncodedAppender appender, List<Encoder> encoders) throws IOException {
if (encoders == null || encoders.isEmpty()) {
streamEncodeable.encodeTo(appender, null);
} else {
StreamEncodeable lastStreamEncodeable = streamEncodeable;
if (encoders.size() > 1) {
StreamCharBuffer buffer;
if (streamEncodeable instanceof StreamCharBuffer) {
buffer = (StreamCharBuffer) streamEncodeable;
} else {
buffer = new StreamCharBuffer();
streamEncodeable.encodeTo(((StreamCharBuffer.StreamCharBufferWriter) buffer.getWriter()).getEncodedAppender(), null);
}
for (int i = 0; i < encoders.size() - 1; i++) {
buffer = buffer.encodeToBuffer(encoders.get(i));
}
lastStreamEncodeable = buffer;
}
lastStreamEncodeable.encodeTo(appender, encoders.get(encoders.size() - 1));
}
}
use of org.grails.buffer.StreamCharBuffer in project grails-core by grails.
the class GroovyPageParser method parse.
public InputStream parse() {
resolveKeepGeneratedDirectory();
StreamCharBuffer streamBuffer = new StreamCharBuffer(1024);
StreamByteBuffer byteOutputBuffer = new StreamByteBuffer(1024, StreamByteBuffer.ReadMode.RETAIN_AFTER_READING);
try {
streamBuffer.connectTo(new OutputStreamWriter(byteOutputBuffer.getOutputStream(), GROOVY_SOURCE_CHAR_ENCODING), true);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Grails cannot run unless your environment supports UTF-8!");
}
File keepGeneratedFile = null;
Writer keepGeneratedWriter = null;
if (keepGeneratedDirectory != null) {
keepGeneratedFile = new File(keepGeneratedDirectory, className);
try {
keepGeneratedWriter = new OutputStreamWriter(new FileOutputStream(keepGeneratedFile), GROOVY_SOURCE_CHAR_ENCODING);
} catch (IOException e) {
LOG.warn("Cannot open keepgenerated file for writing. File's absolute path is '" + keepGeneratedFile.getAbsolutePath() + "'");
keepGeneratedFile = null;
}
streamBuffer.connectTo(keepGeneratedWriter, true);
}
Writer target = streamBuffer.getWriter();
try {
generateGsp(target, false);
if (LOG.isDebugEnabled()) {
if (keepGeneratedFile != null) {
LOG.debug("Compiled GSP into Groovy code. Source is in " + keepGeneratedFile);
} else {
LOG.debug("Configure " + CONFIG_PROPERTY_GSP_KEEPGENERATED_DIR + " property to view generated source.");
}
}
return byteOutputBuffer.getInputStream();
} finally {
SpringIOUtils.closeQuietly(keepGeneratedWriter);
}
}
Aggregations