Package com.alibaba.citrus.util.io

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

@author Michael Zhou

        assertProductItem(newcart, 0, "item1", 10);
        assertProductItem(newcart, 1, "item2", 100);
    }

    private Cart deepClone() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);

        oos.writeObject(cart);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(baos.toInputStream());

        try {
            return (Cart) ois.readObject();
        } finally {
            ois.close();
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

                "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

    /**
     * ���롣
     */
    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

            // 如果需要改变,只需要改变其下面的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

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.