src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/util/ContiguousCharArrayArray.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/util/ContiguousCharArrayArray.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,244 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + *
    1.28 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
    1.29 + */
    1.30 +
    1.31 +package com.sun.xml.internal.fastinfoset.util;
    1.32 +import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
    1.33 +
    1.34 +public class ContiguousCharArrayArray extends ValueArray {
    1.35 +    public static final int INITIAL_CHARACTER_SIZE = 512;
    1.36 +    public static final int MAXIMUM_CHARACTER_SIZE = Integer.MAX_VALUE;
    1.37 +
    1.38 +    protected int _maximumCharacterSize;
    1.39 +
    1.40 +    public int[] _offset;
    1.41 +    public int[] _length;
    1.42 +
    1.43 +    public char[] _array;
    1.44 +    public int _arrayIndex;
    1.45 +    public int _readOnlyArrayIndex;
    1.46 +
    1.47 +    private String[] _cachedStrings;
    1.48 +
    1.49 +    public int _cachedIndex;
    1.50 +
    1.51 +    private ContiguousCharArrayArray _readOnlyArray;
    1.52 +
    1.53 +    public ContiguousCharArrayArray(int initialCapacity, int maximumCapacity,
    1.54 +            int initialCharacterSize, int maximumCharacterSize) {
    1.55 +        _offset = new int[initialCapacity];
    1.56 +        _length = new int[initialCapacity];
    1.57 +        _array = new char[initialCharacterSize];
    1.58 +        _maximumCapacity = maximumCapacity;
    1.59 +        _maximumCharacterSize = maximumCharacterSize;
    1.60 +    }
    1.61 +
    1.62 +    public ContiguousCharArrayArray() {
    1.63 +        this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY,
    1.64 +                INITIAL_CHARACTER_SIZE, MAXIMUM_CHARACTER_SIZE);
    1.65 +    }
    1.66 +
    1.67 +    public final void clear() {
    1.68 +        _arrayIndex = _readOnlyArrayIndex;
    1.69 +        _size = _readOnlyArraySize;
    1.70 +
    1.71 +        if (_cachedStrings != null) {
    1.72 +            for (int i = _readOnlyArraySize; i < _cachedStrings.length; i++) {
    1.73 +                _cachedStrings[i] = null;
    1.74 +            }
    1.75 +        }
    1.76 +    }
    1.77 +
    1.78 +    public final int getArrayIndex() {
    1.79 +        return _arrayIndex;
    1.80 +    }
    1.81 +
    1.82 +    public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
    1.83 +        if (!(readOnlyArray instanceof ContiguousCharArrayArray)) {
    1.84 +            throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.illegalClass", new Object[]{readOnlyArray}));
    1.85 +        }
    1.86 +
    1.87 +        setReadOnlyArray((ContiguousCharArrayArray)readOnlyArray, clear);
    1.88 +    }
    1.89 +
    1.90 +    public final void setReadOnlyArray(ContiguousCharArrayArray readOnlyArray, boolean clear) {
    1.91 +        if (readOnlyArray != null) {
    1.92 +            _readOnlyArray = readOnlyArray;
    1.93 +            _readOnlyArraySize = readOnlyArray.getSize();
    1.94 +            _readOnlyArrayIndex = readOnlyArray.getArrayIndex();
    1.95 +
    1.96 +            if (clear) {
    1.97 +                clear();
    1.98 +            }
    1.99 +
   1.100 +            _array = getCompleteCharArray();
   1.101 +            _offset = getCompleteOffsetArray();
   1.102 +            _length = getCompleteLengthArray();
   1.103 +            _size = _readOnlyArraySize;
   1.104 +            _arrayIndex = _readOnlyArrayIndex;
   1.105 +        }
   1.106 +    }
   1.107 +
   1.108 +    public final char[] getCompleteCharArray() {
   1.109 +        if (_readOnlyArray == null) {
   1.110 +            if (_array == null) return null;
   1.111 +
   1.112 +            // Return cloned version of internal _array
   1.113 +            final char[] clonedArray = new char[_array.length];
   1.114 +            System.arraycopy(_array, 0, clonedArray, 0, _array.length);
   1.115 +            return clonedArray;
   1.116 +//            return _array;
   1.117 +        } else {
   1.118 +            final char[] ra = _readOnlyArray.getCompleteCharArray();
   1.119 +            final char[] a = new char[_readOnlyArrayIndex + _array.length];
   1.120 +            System.arraycopy(ra, 0, a, 0, _readOnlyArrayIndex);
   1.121 +            return a;
   1.122 +        }
   1.123 +    }
   1.124 +
   1.125 +    public final int[] getCompleteOffsetArray() {
   1.126 +        if (_readOnlyArray == null) {
   1.127 +            if (_offset == null) return null;
   1.128 +
   1.129 +            // Return cloned version of internal _offset
   1.130 +            final int[] clonedArray = new int[_offset.length];
   1.131 +            System.arraycopy(_offset, 0, clonedArray, 0, _offset.length);
   1.132 +            return clonedArray;
   1.133 +//            return _offset;
   1.134 +        } else {
   1.135 +            final int[] ra = _readOnlyArray.getCompleteOffsetArray();
   1.136 +            final int[] a = new int[_readOnlyArraySize + _offset.length];
   1.137 +            System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
   1.138 +            return a;
   1.139 +        }
   1.140 +    }
   1.141 +
   1.142 +    public final int[] getCompleteLengthArray() {
   1.143 +        if (_readOnlyArray == null) {
   1.144 +            if (_length == null) return null;
   1.145 +
   1.146 +            // Return cloned version of internal _length
   1.147 +            final int[] clonedArray = new int[_length.length];
   1.148 +            System.arraycopy(_length, 0, clonedArray, 0, _length.length);
   1.149 +            return clonedArray;
   1.150 +//            return _length;
   1.151 +        } else {
   1.152 +            final int[] ra = _readOnlyArray.getCompleteLengthArray();
   1.153 +            final int[] a = new int[_readOnlyArraySize + _length.length];
   1.154 +            System.arraycopy(ra, 0, a, 0, _readOnlyArraySize);
   1.155 +            return a;
   1.156 +        }
   1.157 +    }
   1.158 +
   1.159 +    public final String getString(int i) {
   1.160 +        if (_cachedStrings != null && i < _cachedStrings.length) {
   1.161 +            final String s = _cachedStrings[i];
   1.162 +            return (s != null) ? s : (_cachedStrings[i] = new String(_array, _offset[i], _length[i]));
   1.163 +        }
   1.164 +
   1.165 +        final String[] newCachedStrings = new String[_offset.length];
   1.166 +        if (_cachedStrings != null && i >= _cachedStrings.length) {
   1.167 +            System.arraycopy(_cachedStrings, 0, newCachedStrings, 0, _cachedStrings.length);
   1.168 +        }
   1.169 +        _cachedStrings = newCachedStrings;
   1.170 +
   1.171 +        return _cachedStrings[i] = new String(_array, _offset[i], _length[i]);
   1.172 +    }
   1.173 +
   1.174 +    public final void ensureSize(int l) {
   1.175 +        if (_arrayIndex + l >= _array.length) {
   1.176 +            resizeArray(_arrayIndex + l);
   1.177 +        }
   1.178 +    }
   1.179 +
   1.180 +    public final void add(int l) {
   1.181 +        if (_size == _offset.length) {
   1.182 +            resize();
   1.183 +        }
   1.184 +
   1.185 +        _cachedIndex = _size;
   1.186 +        _offset[_size] = _arrayIndex;
   1.187 +        _length[_size++] = l;
   1.188 +
   1.189 +        _arrayIndex += l;
   1.190 +    }
   1.191 +
   1.192 +    public final int add(char[] c, int l) {
   1.193 +        if (_size == _offset.length) {
   1.194 +            resize();
   1.195 +        }
   1.196 +
   1.197 +        final int oldArrayIndex = _arrayIndex;
   1.198 +        final int arrayIndex = oldArrayIndex + l;
   1.199 +
   1.200 +        _cachedIndex = _size;
   1.201 +        _offset[_size] = oldArrayIndex;
   1.202 +        _length[_size++] = l;
   1.203 +
   1.204 +        if (arrayIndex >= _array.length) {
   1.205 +            resizeArray(arrayIndex);
   1.206 +        }
   1.207 +
   1.208 +        System.arraycopy(c, 0, _array, oldArrayIndex, l);
   1.209 +
   1.210 +        _arrayIndex = arrayIndex;
   1.211 +        return oldArrayIndex;
   1.212 +    }
   1.213 +
   1.214 +    protected final void resize() {
   1.215 +        if (_size == _maximumCapacity) {
   1.216 +            throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
   1.217 +        }
   1.218 +
   1.219 +        int newSize = _size * 3 / 2 + 1;
   1.220 +        if (newSize > _maximumCapacity) {
   1.221 +            newSize = _maximumCapacity;
   1.222 +        }
   1.223 +
   1.224 +        final int[] offset = new int[newSize];
   1.225 +        System.arraycopy(_offset, 0, offset, 0, _size);
   1.226 +        _offset = offset;
   1.227 +
   1.228 +        final int[] length = new int[newSize];
   1.229 +        System.arraycopy(_length, 0, length, 0, _size);
   1.230 +        _length = length;
   1.231 +    }
   1.232 +
   1.233 +    protected final void resizeArray(int requestedSize) {
   1.234 +        if (_arrayIndex == _maximumCharacterSize) {
   1.235 +            throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.maxNumberOfCharacters"));
   1.236 +        }
   1.237 +
   1.238 +        int newSize = requestedSize * 3 / 2 + 1;
   1.239 +        if (newSize > _maximumCharacterSize) {
   1.240 +            newSize = _maximumCharacterSize;
   1.241 +        }
   1.242 +
   1.243 +        final char[] array = new char[newSize];
   1.244 +        System.arraycopy(_array, 0, array, 0, _arrayIndex);
   1.245 +        _array = array;
   1.246 +    }
   1.247 +}

mercurial