public void writeHtmlParts(File filename) throws IOException { DataOutputStream dataOut = null; try { dataOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename))); dataOut.writeInt(htmlParts.size()); for (String part : htmlParts) { dataOut.writeUTF(part); } } finally { SpringIOUtils.closeQuietly(dataOut); } }
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); } }
public void writeLineNumbers(File filename) throws IOException { DataOutputStream dataOut = null; try { dataOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(filename))); int lineNumbersCount = out.getCurrentLineNumber() - 1; int[] lineNumbers = out.getLineNumbers(); dataOut.writeInt(lineNumbersCount); for (int i = 0; i < lineNumbersCount; i++) { dataOut.writeInt(lineNumbers[i]); } } finally { SpringIOUtils.closeQuietly(dataOut); } }