Allocates a new String constructed from a subarray of an array of 8-bit integer values. The offset argument is the index of the first byte of the subarray, and the count argument specifies the length of the subarray. Each byte in the subarr
(
byte ascii[], int hibyte, int offset, int count)
| 814 | * @see java.lang.String#String(byte[]) |
| 815 | */ |
| 816 | private static String stringFromSubarray( |
| 817 | byte ascii[], int hibyte, int offset, int count) { |
| 818 | if (offset < 0) { |
| 819 | throw new StringIndexOutOfBoundsException(offset); |
| 820 | } |
| 821 | if (count < 0) { |
| 822 | throw new StringIndexOutOfBoundsException(count); |
| 823 | } |
| 824 | // Note: offset or count might be near -1>>>1. |
| 825 | if (offset > ascii.length - count) { |
| 826 | throw new StringIndexOutOfBoundsException(offset + count); |
| 827 | } |
| 828 | |
| 829 | char value[] = new char[count]; |
| 830 | |
| 831 | if (hibyte == 0) { |
| 832 | for (int i = count ; i-- > 0 ;) { |
| 833 | value[i] = (char) (ascii[i + offset] & 0xff); |
| 834 | } |
| 835 | } else { |
| 836 | hibyte <<= 8; |
| 837 | for (int i = count ; i-- > 0 ;) { |
| 838 | value[i] = (char) (hibyte | (ascii[i + offset] & 0xff)); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | return new String(value); |
| 843 | } |
| 844 | } |