< prev index next >

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

Print this page




 715                 int start = index;
 716                 index = mid;
 717                 return new LinesSpliterator(value, start, mid - start);
 718             }
 719             return null;
 720         }
 721 
 722         @Override
 723         public long estimateSize() {
 724             return fence - index + 1;
 725         }
 726 
 727         @Override
 728         public int characteristics() {
 729             return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
 730         }
 731 
 732         static LinesSpliterator spliterator(byte[] value) {
 733             return new LinesSpliterator(value, 0, value.length);
 734         }






























































 735     }
 736 
 737     static Stream<String> lines(byte[] value) {
 738         return StreamSupport.stream(LinesSpliterator.spliterator(value), false);




 739     }
 740 
 741     public static void putChar(byte[] val, int index, int c) {
 742         //assert (canEncode(c));
 743         val[index] = (byte)(c);
 744     }
 745 
 746     public static char getChar(byte[] val, int index) {
 747         return (char)(val[index] & 0xff);
 748     }
 749 
 750     public static byte[] toBytes(int[] val, int off, int len) {
 751         byte[] ret = new byte[len];
 752         for (int i = 0; i < len; i++) {
 753             int cp = val[off++];
 754             if (!canEncode(cp)) {
 755                 return null;
 756             }
 757             ret[i] = (byte)cp;
 758         }




 715                 int start = index;
 716                 index = mid;
 717                 return new LinesSpliterator(value, start, mid - start);
 718             }
 719             return null;
 720         }
 721 
 722         @Override
 723         public long estimateSize() {
 724             return fence - index + 1;
 725         }
 726 
 727         @Override
 728         public int characteristics() {
 729             return Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL;
 730         }
 731 
 732         static LinesSpliterator spliterator(byte[] value) {
 733             return new LinesSpliterator(value, 0, value.length);
 734         }
 735 
 736         static LinesSpliterator spliterator(byte[] value, int leading, int trailing) {
 737             int length = value.length;
 738             int left = 0;
 739             int index;
 740             for (int l = 0; l < leading; l++) {
 741                 index = skipBlankForward(value, left, length);
 742                 if (index == left) {
 743                     break;
 744                 }
 745                 left = index;
 746             }
 747             int right = length;
 748             for (int t = 0; t < trailing; t++) {
 749                 index = skipBlankBackward(value, left, right);
 750                 if (index == right) {
 751                     break;
 752                 }
 753                 right = index;
 754             }
 755             return new LinesSpliterator(value, left, right - left);
 756         }
 757 
 758         private static int skipBlankForward(byte[] value, int start, int length) {
 759             int index = start;
 760             while (index < length) {
 761                 char ch = getChar(value, index++);
 762                 if (ch == '\n') {
 763                     return index;
 764                 }
 765                 if (ch == '\r') {
 766                     if (index < length && getChar(value, index) == '\n') {
 767                         return index + 1;
 768                     }
 769                     return index;
 770                 }
 771                 if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
 772                     return start;
 773                 }
 774             }
 775             return length;
 776         }
 777 
 778         private static int skipBlankBackward(byte[] value, int start, int fence) {
 779             int index = fence;
 780             if (start < index && getChar(value, index - 1) == '\n') {
 781                 index--;
 782             }
 783             if (start < index && getChar(value, index - 1) == '\r') {
 784                 index--;
 785             }
 786             while (start < index) {
 787                 char ch = getChar(value, --index);
 788                 if (ch == '\r' || ch == '\n') {
 789                     return index + 1;
 790                 }
 791                 if (ch != ' ' && ch != '\t' && !Character.isWhitespace(ch)) {
 792                     return fence;
 793                 }
 794             }
 795             return start;
 796         }
 797     }
 798 
 799     static Stream<String> lines(byte[] value, int leading, int trailing) {
 800         if (leading == 0 && trailing == 0) {
 801             return StreamSupport.stream(LinesSpliterator.spliterator(value), false);
 802         } else {
 803             return StreamSupport.stream(LinesSpliterator.spliterator(value, leading, trailing), false);
 804         }
 805     }
 806 
 807     public static void putChar(byte[] val, int index, int c) {
 808         //assert (canEncode(c));
 809         val[index] = (byte)(c);
 810     }
 811 
 812     public static char getChar(byte[] val, int index) {
 813         return (char)(val[index] & 0xff);
 814     }
 815 
 816     public static byte[] toBytes(int[] val, int off, int len) {
 817         byte[] ret = new byte[len];
 818         for (int i = 0; i < len; i++) {
 819             int cp = val[off++];
 820             if (!canEncode(cp)) {
 821                 return null;
 822             }
 823             ret[i] = (byte)cp;
 824         }


< prev index next >