Does never read more than needed
(int pos)
| 859 | /** Does never read more than needed */ |
| 860 | |
| 861 | private final int peek(int pos) throws IOException { |
| 862 | |
| 863 | while (pos >= peekCount) { |
| 864 | |
| 865 | int nw; |
| 866 | |
| 867 | if (srcBuf.length <= 1) |
| 868 | nw = reader.read(); |
| 869 | else if (srcPos < srcCount) |
| 870 | nw = srcBuf[srcPos++]; |
| 871 | else { |
| 872 | srcCount = reader.read(srcBuf, 0, srcBuf.length); |
| 873 | if (srcCount <= 0) |
| 874 | nw = -1; |
| 875 | else |
| 876 | nw = srcBuf[0]; |
| 877 | |
| 878 | srcPos = 1; |
| 879 | } |
| 880 | |
| 881 | if (nw == '\r') { |
| 882 | wasCR = true; |
| 883 | peek[peekCount++] = '\n'; |
| 884 | } |
| 885 | else { |
| 886 | if (nw == '\n') { |
| 887 | if (!wasCR) |
| 888 | peek[peekCount++] = '\n'; |
| 889 | } |
| 890 | else |
| 891 | peek[peekCount++] = nw; |
| 892 | |
| 893 | wasCR = false; |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | return peek[pos]; |
| 898 | } |
| 899 | |
| 900 | private final String readName() |
| 901 | throws IOException, XmlPullParserException { |
no test coverage detected