Package groovy.lang

Examples of groovy.lang.Writable


   @Deprecated
   public void merge(Template template, BindingContext context) throws Exception
   {
      context.put("_ctx", context);
      context.setGroovyTemplateService(this);
      Writable writable = template.make(context);
      writable.writeTo(context.getWriter());
   }
View Full Code Here


            throw new ScriptException("Unable to compile GSP script: " + e.getMessage());
        }

        Bindings bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE);

        Writable result = template.make(bindings);

        try {
            result.writeTo(ctx.getWriter());
        } catch (IOException e) {
            throw new ScriptException("Unable to write result of script execution: " + e.getMessage());
        }

        return null;
View Full Code Here

     * @param chunked whether or not the Base64 encoded data should be MIME chunked
     * @return object which will write the Base64 encoding of the byte array
     * @since 1.5.7
     */
    public static Writable encodeBase64(final byte[] data, final boolean chunked) {
        return new Writable() {
            public Writer writeTo(final Writer writer) throws IOException {
                int charCount = 0;
                final int dLimit = (data.length / 3) * 3;

                for (int dIndex = 0; dIndex != dLimit; dIndex += 3) {
View Full Code Here

    private static String asString(GPathResult node) {
        // little bit of hackery to avoid Groovy dependency in this file
        try {
            Object builder = ((Class) Class.forName("groovy.xml.StreamingMarkupBuilder")).newInstance();
            Writable w = (Writable) InvokerHelper.invokeMethod(builder, "bindNode", node);
            return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + w.toString();
        } catch (Exception e) {
            return "Couldn't convert node to string because: " + e.getMessage();
        }
    }
View Full Code Here

    private static String asString(GPathResult node) {
        // little bit of hackery to avoid Groovy dependency in this file
        try {
            Object builder = ((Class) Class.forName("groovy.xml.StreamingMarkupBuilder")).newInstance();
            Writable w = (Writable) InvokerHelper.invokeMethod(builder, "bindNode", node);
            return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + w.toString();
        } catch (Exception e) {
            return "Couldn't convert node to string because: " + e.getMessage();
        }
    }
View Full Code Here

     * @param chunked whether or not the Base64 encoded data should be MIME chunked
     * @return object which will write the Base64 encoding of the byte array
     * @since 1.5.7
     */
    public static Writable encodeBase64(final byte[] data, final boolean chunked) {
        return new Writable() {
            public Writer writeTo(final Writer writer) throws IOException {
                int charCount = 0;
                final int dLimit = (data.length / 3) * 3;

                for (int dIndex = 0; dIndex != dLimit; dIndex += 3) {
View Full Code Here

    public void marshalObject(Object object, XML xml) throws ConverterException {
        xml.attribute("encoding", "BASE-64");
        xml.chars("");

        Writable w;
        if (object instanceof byte[]) {
            w = EncodingGroovyMethods.encodeBase64((byte[])object);
        }
        else {
            w = EncodingGroovyMethods.encodeBase64((Byte[])object);
        }

        try {
            w.writeTo(xml.getStream());
        }
        catch (IOException e) {
            throw new ConverterException(e);
        }
    }
View Full Code Here

    public static void writeSlurperResult(GPathResult result, Writer output) throws IOException {
        Binding b = new Binding();
        b.setVariable("node", result);
        // this code takes the XML parsed by XmlSlurper and writes it out using StreamingMarkupBuilder
        // don't ask me how it works, refer to John Wilson ;-)
        Writable w = (Writable)new GroovyShell(b).evaluate(
                "new groovy.xml.StreamingMarkupBuilder().bind {" +
                " mkp.declareNamespace(\"\":  \"http://java.sun.com/xml/ns/j2ee\");" +
                " mkp.yield node}");
        w.writeTo(output);
    }
View Full Code Here

    private static String asString(GPathResult node) {
        // little bit of hackery to avoid Groovy dependency in this file
        try {
            Object builder = ((Class) Class.forName("groovy.xml.StreamingMarkupBuilder")).newInstance();
            InvokerHelper.setProperty(builder, "encoding", "UTF-8");
            Writable w = (Writable) InvokerHelper.invokeMethod(builder, "bindNode", node);
            return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + w.toString();
        } catch (Exception e) {
            return "Couldn't convert node to string because: " + e.getMessage();
        }
    }
View Full Code Here

     *         from the reader when the Writable#writeTo(Writer) is called.
     * @since 1.0
     */
    public static Writable filterLine(Reader reader, final @ClosureParams(value=SimpleType.class, options="java.lang.String") Closure closure) {
        final BufferedReader br = new BufferedReader(reader);
        return new Writable() {
            public Writer writeTo(Writer out) throws IOException {
                BufferedWriter bw = new BufferedWriter(out);
                String line;
                BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
                while ((line = br.readLine()) != null) {
View Full Code Here

TOP

Related Classes of groovy.lang.Writable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.