Loads options from a reader into this instance. Will read from the stream until it hits a section header, ie a '[' character, and resets the reader to point to this character. @param reader where to read from @throws IOException at an I/O problem
(BufferedReader reader)
| 852 | * @throws IOException at an I/O problem |
| 853 | */ |
| 854 | public void load(BufferedReader reader) throws IOException { |
| 855 | while (reader.ready()) { |
| 856 | reader.mark(NAME_MAXLENGTH); |
| 857 | String line = reader.readLine().trim(); |
| 858 | |
| 859 | // Check for section header |
| 860 | if (line.length() > 0 && line.charAt(0) == HEADER_START) { |
| 861 | reader.reset(); |
| 862 | return; |
| 863 | } |
| 864 | |
| 865 | int delimIndex = -1; |
| 866 | // blank line |
| 867 | if (line.equals("")) { |
| 868 | this.addBlankLine(); |
| 869 | } |
| 870 | // comment line |
| 871 | else if ((delimIndex = Arrays.binarySearch(this.commentDelimsSorted, line.charAt(0))) >= 0) { |
| 872 | addComment(line.substring(1), this.commentDelimsSorted[delimIndex]); |
| 873 | } |
| 874 | // option line |
| 875 | else { |
| 876 | delimIndex = -1; |
| 877 | int delimNum = -1; |
| 878 | int lastSpaceIndex = -1; |
| 879 | for (int i = 0, l = line.length(); i < l && delimIndex < 0; i++) { |
| 880 | delimNum = Arrays.binarySearch(this.optionDelimsSorted, line.charAt(i)); |
| 881 | if (delimNum >= 0) { |
| 882 | delimIndex = i; |
| 883 | } else { |
| 884 | boolean isSpace = Arrays.binarySearch( |
| 885 | this.OPTION_DELIMS_WHITESPACE, line.charAt(i)) >= 0; |
| 886 | if (!isSpace && lastSpaceIndex >= 0) { |
| 887 | break; |
| 888 | } else if (isSpace) { |
| 889 | lastSpaceIndex = i; |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | // delimiter at start of line |
| 894 | if (delimIndex == 0) { |
| 895 | // XXX what's a man got to do? |
| 896 | } |
| 897 | // no delimiter found |
| 898 | else if (delimIndex < 0) { |
| 899 | if (lastSpaceIndex < 0) { |
| 900 | this.set(line, ""); |
| 901 | } else { |
| 902 | this.set(line.substring(0, lastSpaceIndex) |
| 903 | , line.substring(lastSpaceIndex + 1)); |
| 904 | } |
| 905 | } |
| 906 | // delimiter found |
| 907 | else { |
| 908 | this.set(line.substring(0, delimIndex) |
| 909 | , line.substring(delimIndex + 1), line.charAt(delimIndex)); |
| 910 | } |
| 911 | } |
no test coverage detected