< prev index next >

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

Print this page




1102                 int start = index;
1103                 index = mid;
1104                 return new LinesSpliterator(value, start, mid - start);
1105             }
1106             return null;
1107         }
1108 
1109         @Override
1110         public long estimateSize() {
1111             return fence - index + 1;
1112         }
1113 
1114         @Override
1115         public int characteristics() {
1116             return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
1117         }
1118 
1119         static LinesSpliterator spliterator(byte[] value) {
1120             return new LinesSpliterator(value, 0, value.length >>> 1);
1121         }






























































1122     }
1123 
1124     static Stream<String> lines(byte[] value) {
1125         return StreamSupport.stream(LinesSpliterator.spliterator(value), false);




1126     }
1127 
1128     private static void putChars(byte[] val, int index, char[] str, int off, int end) {
1129         while (off < end) {
1130             putChar(val, index++, str[off++]);
1131         }
1132     }
1133 
1134     public static String newString(byte[] val, int index, int len) {
1135         if (String.COMPACT_STRINGS) {
1136             byte[] buf = compress(val, index, len);
1137             if (buf != null) {
1138                 return new String(buf, LATIN1);
1139             }
1140         }
1141         int last = index + len;
1142         return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
1143     }
1144 
1145     public static void fillNull(byte[] val, int index, int end) {




1102                 int start = index;
1103                 index = mid;
1104                 return new LinesSpliterator(value, start, mid - start);
1105             }
1106             return null;
1107         }
1108 
1109         @Override
1110         public long estimateSize() {
1111             return fence - index + 1;
1112         }
1113 
1114         @Override
1115         public int characteristics() {
1116             return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
1117         }
1118 
1119         static LinesSpliterator spliterator(byte[] value) {
1120             return new LinesSpliterator(value, 0, value.length >>> 1);
1121         }
1122 
1123         static LinesSpliterator spliterator(byte[] value, int leading, int trailing) {
1124             int length = value.length >>> 1;
1125             int left = 0;
1126             int index;
1127             for (int l = 0; l < leading; l++) {
1128                 index = skipBlankForward(value, left, length);
1129                 if (index == left) {
1130                     break;
1131                 }
1132                 left = index;
1133             }
1134             int right = length;
1135             for (int t = 0; t < trailing; t++) {
1136                 index = skipBlankBackward(value, left, right);
1137                 if (index == right) {
1138                     break;
1139                 }
1140                 right = index;
1141             }
1142             return new LinesSpliterator(value, left, right - left);
1143         }
1144 
1145         private static int skipBlankForward(byte[] value, int start, int length) {
1146             int index = start;
1147             while (index < length) {
1148                 char ch = getChar(value, index++);
1149                 if (ch == '\n') {
1150                     return index;
1151                 }
1152                 if (ch == '\r') {
1153                     if (index < length && getChar(value, index) == '\n') {
1154                         return index + 1;
1155                     }
1156                     return index;
1157                 }
1158                 if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
1159                     return start;
1160                 }
1161             }
1162             return length;
1163         }
1164 
1165         private static int skipBlankBackward(byte[] value, int start, int fence) {
1166             int index = fence;
1167             if (start < index && getChar(value, index - 1) == '\n') {
1168                 index--;
1169             }
1170             if (start < index && getChar(value, index - 1) == '\r') {
1171                 index--;
1172             }
1173             while (start < index) {
1174                 char ch = getChar(value, --index);
1175                 if (ch == '\r' || ch == '\n') {
1176                     return index + 1;
1177                 }
1178                 if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
1179                     return fence;
1180                 }
1181             }
1182             return start;
1183         }
1184     }
1185 
1186     static Stream<String> lines(byte[] value, int leading, int trailing) {
1187         if (leading == 0 && trailing == 0) {
1188             return StreamSupport.stream(LinesSpliterator.spliterator(value), false);
1189         } else {
1190             return StreamSupport.stream(LinesSpliterator.spliterator(value, leading, trailing), false);
1191         }
1192     }
1193 
1194     private static void putChars(byte[] val, int index, char[] str, int off, int end) {
1195         while (off < end) {
1196             putChar(val, index++, str[off++]);
1197         }
1198     }
1199 
1200     public static String newString(byte[] val, int index, int len) {
1201         if (String.COMPACT_STRINGS) {
1202             byte[] buf = compress(val, index, len);
1203             if (buf != null) {
1204                 return new String(buf, LATIN1);
1205             }
1206         }
1207         int last = index + len;
1208         return new String(Arrays.copyOfRange(val, index << 1, last << 1), UTF16);
1209     }
1210 
1211     public static void fillNull(byte[] val, int index, int end) {


< prev index next >