Package org.codehaus.stax2

Examples of org.codehaus.stax2.XMLStreamReader2


    }

    private String buildDoc(Base64Variant b64variant, Random r, byte[] data, boolean addNoise)
    {
        // Let's use base64 codec from RI here:
        AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, 0, data.length);

        StringBuffer sb = new StringBuffer(data.length * 2);
        sb.append("<root>");

        // Without noise it's quite easy, just need enough space:
        if (!addNoise) {
            // Base64 adds 33% overhead, but let's be generous
            char[] buffer = new char[4 + (data.length * 3 / 2)];
            int len = enc.encodeMore(buffer, 0, buffer.length);
            sb.append(buffer, 0, len);
        } else {
            // but with noise, need bit different approach
            char[] buffer = new char[300];

            while (!enc.isCompleted()) {
                int offset = r.nextInt() & 0xF;
                int len;
                int rn = r.nextInt() & 15;

                switch (rn) {
                case 1:
                case 2:
                case 3:
                case 4:
                    len = rn;
                    break;
                case 5:
                case 6:
                case 7:
                    len = 3 + (r.nextInt() & 15);
                    break;
                default:
                    len = 20 + (r.nextInt() & 127);
                    break;
                }
                int end = enc.encodeMore(buffer, offset, offset+len);

                // regular or CDATA?
                boolean cdata = r.nextBoolean() && r.nextBoolean();

                if (cdata) {
View Full Code Here


        StringBuffer sb = new StringBuffer(16 + dataTable.length * dataTable[0].length);
        sb.append("<root>");
        for (int i = 0; i < dataTable.length; ++i) {
            byte[] data = dataTable[i];
            char[] buffer = new char[4 + (data.length * 3 / 2)];
            AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, 0, data.length);
            int len = enc.encodeMore(buffer, 0, buffer.length);
            sb.append("<a>");
            sb.append(buffer, 0, len);
            sb.append("</a>");
        }
        sb.append("</root>");
View Full Code Here

                return 0;
            }
            throw new IllegalArgumentException("Illegal maxLength ("+maxLength+"), has to be positive number, and offset+maxLength can not exceed"+resultBuffer.length);
        }

        final CharArrayBase64Decoder dec = _base64Decoder();
        int type = mCurrToken;
        // First things first: must be acceptable start state:
        if (((1 << type) & MASK_TYPED_ACCESS_BINARY) == 0) {
            if (type == END_ELEMENT) {
                // Minor complication: may have unflushed stuff (non-padded versions)
                if (!dec.hasData()) {
                    return -1;
                }
            } else {
                throwNotTextualOrElem(type);
            }
        } else if (type == START_ELEMENT) { // just starting (START_ELEMENT)?
            if (mStEmptyElem) { // empty element? simple...
                mStEmptyElem = false;
                mCurrToken = END_ELEMENT;
                return -1;
            }
            // Otherwise let's just find the first text segment
            while (true) {
                type = next();
                if (type == END_ELEMENT) {
                    // Simple... no textual content
                    return -1;
                }
                if (type == COMMENT || type == PROCESSING_INSTRUCTION) {
                    continue;
                }
                /* 12-Dec-2009, tatu: Important: in coalescing mode we may
                 *   have incomplete segment that needs to be completed
                 */
                if (mTokenState < mStTextThreshold) {
                    finishToken(false);
                }
                _initBinaryChunks(v, dec, type, true);
                break;
            }
        }

        int totalCount = 0;

        main_loop:
        while (true) {
            // Ok, decode:
            int count;
            try {
                count = dec.decode(resultBuffer, offset, maxLength);
            } catch (IllegalArgumentException iae) {
                // !!! 26-Sep-2008, tatus: should try to figure out which char (etc) triggered problem to pass with typed exception
                throw _constructTypeException(iae.getMessage(), "");
            }
            offset += count;
            totalCount += count;
            maxLength -= count;

            /* And if we filled the buffer we are done. Or, an edge
             * case: reached END_ELEMENT (for non-padded variant)
             */
            if (maxLength < 1 || mCurrToken == END_ELEMENT) {
                break;
            }
            // Otherwise need to advance to the next event
            while (true) {
                type = next();
                if (type == COMMENT || type == PROCESSING_INSTRUCTION
                    || type == SPACE) { // space is ignorable too
                    continue;
                }
                if (type == END_ELEMENT) {
                    /* Just need to verify we don't have partial stuff
                     * (missing one to three characters of a full quartet
                     * that encodes 1 - 3 bytes). Also: non-padding
                     * variants can be in incomplete state, from which
                     * data may need to be flushed...
                     */
                    int left = dec.endOfContent();
                    if (left < 0) { // incomplete, error
                        throw _constructTypeException("Incomplete base64 triplet at the end of decoded content", "");
                    } else if (left > 0) { // 1 or 2 more bytes of data, loop some more
                        continue main_loop;
                    }
View Full Code Here

    }

    protected CharArrayBase64Decoder _base64Decoder()
    {
        if (_base64Decoder == null) {
            _base64Decoder = new CharArrayBase64Decoder();
        }
        return _base64Decoder;
    }
View Full Code Here

    }

    protected ValueDecoderFactory _decoderFactory()
    {
        if (_decoderFactory == null) {
            _decoderFactory = new ValueDecoderFactory();
        }
        return _decoderFactory;
    }
View Full Code Here

             * data:
             */
            int ptr = 0;
            do {
                int chunkLen = 1 + (r.nextInt() & 0x7);
                AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, ptr, chunkLen);
                ptr += chunkLen;
                int len = enc.encodeMore(buffer, 0, buffer.length);
                b64.append(buffer, 0, len);
            } while (b64.length() < SIZE);
            // And then create document, with split content
View Full Code Here

        // So first we'll encode 1 to 6 bytes as base64
        for (int bv = 0; bv < sPaddingVariants.length; ++bv) {
            Base64Variant b64variant = sPaddingVariants[bv];
            for (int i = 1; i <= data.length; ++i) {
                AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, 0, i);
                char[] cbuf = new char[20];
                int clen = enc.encodeMore(cbuf, 0, cbuf.length);
               
                // and use all byte last 1, 2 or 3 chars
                for (int j = 1; j <= 3; ++j) {
View Full Code Here

                Base64Variant b64variant = sBase64Variants[bv];
                for (int i = 0; i < LEN_ATTR.length; ++i) {
                    int size = LEN_ATTR[i];
                    byte[] data = generateData(new Random(size), size);
                    char[] buffer = new char[4 + (data.length * 3 / 2)];
                    AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, 0, data.length);
                    int len = enc.encodeMore(buffer, 0, buffer.length);
                    StringBuilder sb = new StringBuilder(buffer.length + 32);
                    sb.append("<root attr='");
                    sb.append(buffer, 0, len);
                    sb.append("' />");
View Full Code Here

        for (int bv = 0; bv < sPaddingVariants.length; ++bv) {
            Base64Variant b64variant = sPaddingVariants[bv];

            // So first we'll encode 1 to 6 bytes as base64
            for (int i = 1; i <= data.length; ++i) {
                AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, 0, i);
                char[] cbuf = new char[20];
                int clen = enc.encodeMore(cbuf, 0, cbuf.length);
               
                // and use all byte last 1, 2 or 3 chars
                for (int j = 1; j <= 3; ++j) {
View Full Code Here

    }

    private String buildDoc(Base64Variant b64variant, Random r, byte[] data, boolean addNoise)
    {
        // Let's use base64 codec from RI here:
        AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, 0, data.length);

        StringBuffer sb = new StringBuffer(data.length * 2);
        sb.append("<root>");

        // Without noise it's quite easy, just need enough space:
View Full Code Here

TOP

Related Classes of org.codehaus.stax2.XMLStreamReader2

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.