Package com.persistit.exception

Examples of com.persistit.exception.ConversionException


        abstract void fromValue(Object object, Value value) throws Exception;

        abstract void toValue(Object object, Value value) throws Exception;

        protected void cantModifyFinalField() {
            throw new ConversionException("Can not modify final field " + _field.getName());
        }
View Full Code Here


        boolean zeroByteFree = false;
        try {
            final int handle = decodeHandle();
            clazz = _persistit.classForHandle(handle);
            if (clazz == null) {
                throw new ConversionException("No class information for handle " + handle);
            }
            final KeyCoder coder = _persistit.lookupKeyCoder(clazz);
            if (coder == null) {
                throw new ConversionException("No KeyCoder for class " + clazz.getName());
            }
            zeroByteFree = coder.isZeroByteFree();
            segmentSize = unquoteNulls(index, zeroByteFree);
            size = _size;
            _size = index + segmentSize;
            unquoted = true;
            if (target == null) {
                return coder.decodeKeySegment(this, clazz, context);
            } else {
                if (coder instanceof KeyRenderer) {
                    ((KeyRenderer) coder).renderKeySegment(this, target, clazz, context);
                    return target;
                } else {
                    throw new ConversionException("No KeyRenderer for class " + clazz.getName());
                }
            }
        } finally {
            _size = size;
            if (unquoted) {
View Full Code Here

     */
    private Appendable decodeString(final boolean quoted, final Appendable sb) {
        int index = _index;
        int c1 = _bytes[index++] & 0xFF;
        if (c1 != TYPE_STRING) {
            throw new ConversionException("Invalid String lead-in byte (" + c1 + ") at position " + (index - 1)
                    + " in key");
        }

        while ((c1 = _bytes[index++] & 0xFF) != 0 && index <= _size) {
            char c = 0;
            // Handle encoded NUL and SOH bytes
            if (c1 == 0x01) {
                final int c2 = _bytes[index++] & 0xFF;
                if (c2 >= 0x0020 && c2 <= 0x0021) {
                    c = (char) (c2 - 0x0020);
                } else {
                    throw new ConversionException("String decoding exception at position " + (index - 1));
                }
            }

            // 7-bit ASCII
            else if (c1 <= 0x7F) {
                c = (char) c1;
            }

            else if (c1 > 0xC0 && c1 <= 0xDF) {
                final int c2 = _bytes[index++] & 0xFF;
                if (c2 >= 0x80 && c2 <= 0xBF) {
                    c = (char) (((c1 & 0x1F) << 6) | ((c2 & 0x3F) << 0));
                } else {
                    throw new ConversionException("String decoding exception at position " + (index - 1));
                }
            } else if (c1 >= 0xE0 && c1 <= 0xEF) {
                final int c2 = _bytes[index++] & 0xFF;
                final int c3 = _bytes[index++] & 0xFF;
                if (c2 >= 0x80 && c2 <= 0xBF && c3 >= 0x80 && c3 <= 0xBF) {
                    c = (char) (((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | ((c3 & 0x3F) << 0));
                }
            } else {
                throw new ConversionException("String decoding exception at position " + (index - 1));
            }
            if (quoted) {
                Util.appendQuotedChar(sb, c);
            } else {
                Util.append(sb, c);
View Full Code Here

            _index = index;
            return result + ClassIndex.HANDLE_BASE;

        default:
        }
        throw new ConversionException("Invalid KeyCoder handle at " + _index);
    }
View Full Code Here

        throw new ConversionException("Invalid KeyCoder handle at " + _index);
    }

    private int decodeEnd(final int index) {
        if (_bytes[index] != 0) {
            throw new ConversionException("Invalid end byte at " + (index + 1));
        }
        return index + 1;
    }
View Full Code Here

    }

    private Object decodeNull() {
        final int type = _bytes[_index] & 0xFF;
        if (type != TYPE_NULL)
            throw new ConversionException("Expected null type");
        _index = decodeEnd(_index + 1);
        return null;
    }
View Full Code Here

        if (type == TYPE_BEFORE) {
            v = BEFORE;
        } else if (type == TYPE_AFTER) {
            v = AFTER;
        } else {
            throw new ConversionException("Invalid BEFORE type " + type);
        }
        _index = decodeEnd(_index + 1);
        return v;
    }
View Full Code Here

    private int quoteNulls(final int index, int size, final boolean zeroByteFree) {
        for (int i = index; i < index + size; i++) {
            final int c = _bytes[i] & 0xFF;
            if (zeroByteFree) {
                if (c == 0) {
                    throw new ConversionException("NUL found in encoded Key");
                }
            } else {
                if (c == 0 || c == 1) {
                    System.arraycopy(_bytes, i + 1, _bytes, i + 2, _size - i - 1);
                    _bytes[i] = 1;
View Full Code Here

    private void decodeBigInteger(final BigIntegerStruct bis) {
        final int start = _index;
        final int signum = (_bytes[_index++] & 0xFF) - 0x40;
        if (signum < -1 || signum > 1) {
            throw new ConversionException("Invalid BigInteger signum at offset " + (start));
        }
        if (signum == 0) {
            bis._bigInteger = BigInteger.ZERO;
            bis._scale = 0;
            return;
        }
        final boolean neg = signum < 0;
        //
        // Decode the exponent
        //
        int exp = decodeIntInternal();
        if (neg)
            exp = -exp;
        //
        // Reset the fields of the BigIntegerStruct
        //
        bis._bigInteger = null;
        bis._scale = 0;
        bis._zeroCount = 0;

        boolean done = false;
        int lastDigit = 0;
        boolean leftOverDigit = false;
        boolean lastDigitZero = false;
        int zeroCount = 0;
        while (!done) {
            long lowBits = leftOverDigit ? lastDigit : 0;
            //
            // Number of digits that will be accumulated in lowBits before
            // adding to the accumulator.
            //
            int chunk = 0;
            if (exp > 0) {
                chunk = exp % 16;
                if (chunk == 0)
                    chunk = 16;
            } else {
                chunk = 16;
            }
            exp -= chunk;
            if (leftOverDigit)
                chunk--;
            boolean dontAccumulate = false;
            while (chunk > 0 && !done) {
                int b = _bytes[_index++] & 0xFF;
                if (b == 0) {
                    done = true;
                    _index--;
                    if (chunk >= 15 && exp == -16 && lowBits == 0) {
                        exp += 16;
                        dontAccumulate = true;
                    } else {
                        if (leftOverDigit)
                            lastDigitZero = (lastDigit == 0);
                        if (lastDigitZero)
                            zeroCount++;
                        for (; --chunk >= 0;) {
                            zeroCount++;
                            lowBits *= 10;
                        }
                    }
                } else if (b != 0xFF) {
                    if (neg)
                        b = 0xAA - b;
                    else
                        b = b - 0x11;
                    if (((b >>> 4) & 0x0F) > 9 || (b & 0x0F) > 9) {
                        throw new ConversionException("Invalid BigInteger encoding at index " + (_index - 1));
                    }
                    if (chunk == 1) {
                        final int digit = (b >>> 4) & 0x0F;
                        lowBits = lowBits * 10 + digit;
                        lastDigit = b & 0x0F;
View Full Code Here

    public boolean ensureFit(final int length) {
        if (_size + length <= _bytes.length) {
            return false;
        }
        if (_size + length > _maximumSize) {
            throw new ConversionException("Requested size=" + (_size + length) + " exceeds maximum size="
                    + _maximumSize);
        }
        int newArraySize = (((_size + length) * 2 + SIZE_GRANULARITY - 1) / SIZE_GRANULARITY) * SIZE_GRANULARITY;
        if (newArraySize > _maximumSize) {
            newArraySize = _maximumSize;
View Full Code Here

TOP

Related Classes of com.persistit.exception.ConversionException

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.