Package webit.script.util

Examples of webit.script.util.ByteArrayOutputStream


    public Object execute(final Context context) {

        final Out current = context.out;
        final Object result;
        if (current.isByteStream()) {
            ByteArrayOutputStream out = new ByteArrayOutputStream(256);
            context.out = new OutputStreamOut(out, (OutputStreamOut) current);
            result = srcExpr.execute(context);
            toExpr.setValue(context, out.toArray());
        } else {
            CharArrayWriter writer = new CharArrayWriter(256);
            context.out = current instanceof WriterOut
                    ? new WriterOut(writer, (WriterOut) current)
                    : new WriterOut(writer, context.encoding, context.template.engine.getCoderFactory());
View Full Code Here


                } else {
                    methodArgs = EMPTY_ARRAY;
                }
                preOut = context.out;
                if (preOut.isByteStream()) {
                    final ByteArrayOutputStream out = new ByteArrayOutputStream(256);

                    context.out = new OutputStreamOut(out, (OutputStreamOut) preOut);

                    try {
                        returned = methodDeclare.invoke(context, methodArgs);
                    } finally {
                        context.out = preOut;
                    }
                    outted = out.toArray();
                } else {
                    final CharArrayWriter writer = new CharArrayWriter(256);

                    context.out = preOut instanceof WriterOut
                            ? new WriterOut(writer, (WriterOut) preOut)
View Full Code Here

        coderFactory = engine.getCoderFactory();
    }

    public void startTemplateParser(Template template) {
        encoders.set(coderFactory.newEncoder(encoding));
        outputs.set(new ByteArrayOutputStream(512));
    }
View Full Code Here

        outputs.remove();
    }

    protected byte[] getBytes(char[] text) {
        try {
            final ByteArrayOutputStream out = outputs.get();
            encoders.get().write(text, 0, text.length, out);
            final byte[] bytes = out.toArray();
            out.reset();
            return bytes;
        } catch (IOException ex) {
            throw new ScriptRuntimeException(ex);
        }
    }
View Full Code Here

    public void test() throws ResourceNotFoundException, IOException {

        Map<String, String> templates = collectAutoTestTemplates();
        ClassLoader classLoader = ClassUtil.getDefaultClassLoader();

        final ByteArrayOutputStream bytesBuffer = new ByteArrayOutputStream();
        final byte[] buffer = new byte[BUFFER_SIZE];

        try {

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            for (Map.Entry<String, String> entry : templates.entrySet()) {
                String templatePath = entry.getKey();
                String outPath = entry.getValue();
                if (outPath != null) {
                    out.reset();
                    mergeTemplate(templatePath, out);

                    //read outNotNull
                    InputStream in;
                    if ((in = classLoader.getResourceAsStream(AUTO_TEST_PATH.concat(outPath))) != null) {
                        int read;
                        bytesBuffer.reset();
                        while ((read = in.read(buffer, 0, BUFFER_SIZE)) >= 0) {
                            bytesBuffer.write(buffer, 0, read);
                        }
                        assertArrayEquals(bytesBuffer.toArray(), out.toArray());
                        System.out.println("\tresult match to: " + outPath);

                        bytesBuffer.reset();
                    }
                    out.reset();
                } else {
                    mergeTemplate(templatePath, new DiscardOut());
                }
            }
        } catch (ParseException e) {
View Full Code Here

    public void test() throws ResourceNotFoundException, IOException {

        Map<String, String> templates = collectAutoTestTemplates();
        ClassLoader classLoader = ClassUtil.getDefaultClassLoader();

        final ByteArrayOutputStream bytesBuffer = new ByteArrayOutputStream();
        final byte[] buffer = new byte[BUFFER_SIZE];

        try {

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            for (Map.Entry<String, String> entry : templates.entrySet()) {
                String templatePath = entry.getKey();
                String outPath = entry.getValue();
                if (outPath != null) {
                    out.reset();
                    mergeTemplate(templatePath, out);

                    //read outNotNull
                    InputStream in;
                    if ((in = classLoader.getResourceAsStream(AUTO_TEST_PATH.concat(outPath))) != null) {
                        int read;
                        bytesBuffer.reset();
                        while ((read = in.read(buffer, 0, BUFFER_SIZE)) >= 0) {
                            bytesBuffer.write(buffer, 0, read);
                        }
                        assertArrayEquals(bytesBuffer.toArray(), out.toArray());
                        System.out.println("\tresult match to: " + outPath);

                        bytesBuffer.reset();
                    }
                    out.reset();
                } else {
                    mergeTemplate(templatePath, new DiscardOut());
                }
            }
        } catch (ParseException e) {
View Full Code Here

    }

    public Object execute(final Context context) {
        final Out current = context.out;
        if (current.isByteStream()) {
            ByteArrayOutputStream out = new ByteArrayOutputStream(256);
            context.out = new OutputStreamOut(out, (OutputStreamOut) current);
            srcStatement.execute(context);
            toExpr.setValue(context, out.toArray());
        } else {
            CharArrayWriter writer = new CharArrayWriter(256);
            context.out = current instanceof WriterOut
                    ? new WriterOut(writer, (WriterOut) current)
                    : new WriterOut(writer, context.encoding, context.template.engine.getCoderFactory());
View Full Code Here

    public void test() throws ResourceNotFoundException, IOException, ParseException, ScriptRuntimeException {

        Map<String, String> templates = collectAutoTestTemplates();
        ClassLoader classLoader = ClassUtil.getDefaultClassLoader();

        final ByteArrayOutputStream bytesBuffer = new ByteArrayOutputStream();
        final byte[] buffer = new byte[BUFFER_SIZE];

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        for (Map.Entry<String, String> entry : templates.entrySet()) {
            String templatePath = entry.getKey();
            String outPath = entry.getValue();
            if (outPath != null) {
                out.reset();
                mergeTemplate(templatePath, out);

                //read outNotNull
                InputStream in;
                if ((in = classLoader.getResourceAsStream(AUTO_TEST_PATH.concat(outPath))) != null) {
                    int read;
                    bytesBuffer.reset();
                    while ((read = in.read(buffer, 0, BUFFER_SIZE)) >= 0) {
                        bytesBuffer.write(buffer, 0, read);
                    }
                    assertArrayEquals(bytesBuffer.toArray(), out.toArray());
                    System.out.println("\tresult match to: " + outPath);

                    bytesBuffer.reset();
                }
                out.reset();
            } else {
                mergeTemplate(templatePath, new DiscardOut());
            }
        }
    }
View Full Code Here

TOP

Related Classes of webit.script.util.ByteArrayOutputStream

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.