src/java.base/share/classes/java/lang/String.java

Print this page




3029                     return;
3030                 }
3031             }
3032             this.coder = UTF16;
3033             this.value = Arrays.copyOfRange(val, 0, length << 1);
3034         }
3035     }
3036 
3037    /*
3038     * Package private constructor which shares value array for speed.
3039     */
3040     String(byte[] value, byte coder) {
3041         this.value = value;
3042         this.coder = coder;
3043     }
3044 
3045     byte coder() {
3046         return COMPACT_STRINGS ? coder : UTF16;
3047     }
3048 




3049     private boolean isLatin1() {
3050         return COMPACT_STRINGS && coder == LATIN1;
3051     }
3052 
3053     @Native static final byte LATIN1 = 0;
3054     @Native static final byte UTF16  = 1;
3055 
3056     /*
3057      * StringIndexOutOfBoundsException  if {@code index} is
3058      * negative or greater than or equal to {@code length}.
3059      */
3060     static void checkIndex(int index, int length) {
3061         if (index < 0 || index >= length) {
3062             throw new StringIndexOutOfBoundsException("index " + index +
3063                                                       ",length " + length);
3064         }
3065     }
3066 
3067     /*
3068      * StringIndexOutOfBoundsException  if {@code offset}




3029                     return;
3030                 }
3031             }
3032             this.coder = UTF16;
3033             this.value = Arrays.copyOfRange(val, 0, length << 1);
3034         }
3035     }
3036 
3037    /*
3038     * Package private constructor which shares value array for speed.
3039     */
3040     String(byte[] value, byte coder) {
3041         this.value = value;
3042         this.coder = coder;
3043     }
3044 
3045     byte coder() {
3046         return COMPACT_STRINGS ? coder : UTF16;
3047     }
3048 
3049     byte[] value() {
3050         return value;
3051     }
3052 
3053     private boolean isLatin1() {
3054         return COMPACT_STRINGS && coder == LATIN1;
3055     }
3056 
3057     @Native static final byte LATIN1 = 0;
3058     @Native static final byte UTF16  = 1;
3059 
3060     /*
3061      * StringIndexOutOfBoundsException  if {@code index} is
3062      * negative or greater than or equal to {@code length}.
3063      */
3064     static void checkIndex(int index, int length) {
3065         if (index < 0 || index >= length) {
3066             throw new StringIndexOutOfBoundsException("index " + index +
3067                                                       ",length " + length);
3068         }
3069     }
3070 
3071     /*
3072      * StringIndexOutOfBoundsException  if {@code offset}