Package com.alibaba.citrus.util.io

Examples of com.alibaba.citrus.util.io.ByteArrayOutputStream

@author Michael Zhou

        flushBufferAdapter();

        // 向stream或writer stack中压入新的buffer。
        if (stream != null) {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();

            bytesStack.push(bytes);

            ((BufferedServletOutputStream) stream).updateOutputStream(bytesStack.peek());
View Full Code Here


        if (stream == null) {
            return new ByteArray(EMPTY_BYTE_ARRAY, 0, 0);
        } else {
            flushBufferAdapter();

            ByteArrayOutputStream block = bytesStack.pop();

            if (bytesStack.size() == 0) {
                bytesStack.push(new ByteArrayOutputStream());
            }

            ((BufferedServletOutputStream) stream).updateOutputStream(bytesStack.peek());

            log.debug("Popped the last byte buffer (stack size is " + bytesStack.size() + ")");

            return block.toByteArray();
        }
    }
View Full Code Here

        // getText
        assertEquals(result, templateService.getText(templateName, null));

        // writeTo stream
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        templateService.writeTo(templateName, null, baos);

        assertEquals(result, new String(baos.toByteArray().toByteArray()));

        // writeTo writer
        StringWriter sw = new StringWriter();
        templateService.writeTo(templateName, null, sw);
View Full Code Here

                                          "hello, world"));
    }

    @Test
    public void writeTo() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        builder.writeTo(baos, rawSession);

        String eml = save(new String(baos.toByteArray().toByteArray()));

        assertThat(eml, containsAllRegex( //
                                          "Subject:\\s*" + REGEX_EOL, //
                                          "Content-Type: text/plain; charset=us-ascii" + REGEX_EOL, //
                                          REGEX_EOL + REGEX_EOL + "$"));
View Full Code Here

            // 如果需要改变,只需要改变其下面的bytes流即可。
            if (bytesStack == null) {
                bytesStack = new Stack<ByteArrayOutputStream>();
            }

            ByteArrayOutputStream bytes = new ByteArrayOutputStream();

            bytesStack.push(bytes);
            stream = new BufferedServletOutputStream(bytes);

            log.debug("Created new byte buffer");
View Full Code Here

        if (buffering) {
            flushBufferAdapter();

            if (stream != null) {
                bytesStack.clear();
                bytesStack.add(new ByteArrayOutputStream());
                ((BufferedServletOutputStream) stream).updateOutputStream(bytesStack.peek());
            }

            if (writer != null) {
                charsStack.clear();
View Full Code Here

        flushBufferAdapter();

        // 向stream或writer stack中压入新的buffer。
        if (stream != null) {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();

            bytesStack.push(bytes);

            ((BufferedServletOutputStream) stream).updateOutputStream(bytesStack.peek());
View Full Code Here

        if (stream == null) {
            return new ByteArray(EMPTY_BYTE_ARRAY, 0, 0);
        } else {
            flushBufferAdapter();

            ByteArrayOutputStream block = bytesStack.pop();

            if (bytesStack.size() == 0) {
                bytesStack.push(new ByteArrayOutputStream());
            }

            ((BufferedServletOutputStream) stream).updateOutputStream(bytesStack.peek());

            log.debug("Popped the last byte buffer (stack size is " + bytesStack.size() + ")");

            return block.toByteArray();
        }
    }
View Full Code Here

        }
    }

    /** 编码。 */
    public String encode(Map<String, Object> attrs, StoreContext storeContext) throws SessionEncoderException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        // 1. 序列化
        // 2. 压缩
        Deflater def = new Deflater(Deflater.BEST_COMPRESSION, false);
        DeflaterOutputStream dos = new DeflaterOutputStream(baos, def);

        try {
            serializer.serialize(assertNotNull(attrs, "objectToEncode is null"), dos);
        } catch (Exception e) {
            throw new SessionEncoderException("Failed to encode session state", e);
        } finally {
            try {
                dos.close();
            } catch (IOException e) {
            }

            def.end();
        }

        byte[] plaintext = baos.toByteArray().toByteArray();

        // 3. 加密
        byte[] cryptotext = encrypt(plaintext);

        // 4. base64编码
View Full Code Here

    }

    /** 将javamail邮件对象转换成文本形式,其格式为标准的<code>.eml</code>格式。 */
    public static String toString(Message message, String javaCharset) throws MessagingException,
                                                                              UnsupportedEncodingException {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();

        try {
            message.writeTo(ostream);
        } catch (IOException e) {
            unexpectedException(e);
        } finally {
            ostream.close();
        }

        ByteArray bytes = ostream.toByteArray();

        javaCharset = getJavaCharset(javaCharset);

        return new String(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength(), javaCharset);
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.util.io.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.