68 import java.text.ParseException; |
68 import java.text.ParseException; |
69 import java.time.LocalDate; |
69 import java.time.LocalDate; |
70 import java.time.format.DateTimeFormatter; |
70 import java.time.format.DateTimeFormatter; |
71 import java.time.temporal.ChronoField; |
71 import java.time.temporal.ChronoField; |
72 import java.util.Arrays; |
72 import java.util.Arrays; |
73 import java.util.function.Block; |
73 import java.util.function.Consumer; |
74 |
74 |
75 /** |
75 /** |
76 * A reader for Hijrah Deviation files. |
76 * A reader for Hijrah Deviation files. |
77 * <p> |
77 * <p> |
78 * For each Hijrah calendar a deviation file is used |
78 * For each Hijrah calendar a deviation file is used |
124 * data with format defined in the class javadoc. |
124 * data with format defined in the class javadoc. |
125 * |
125 * |
126 * @param typeId the name of the calendar |
126 * @param typeId the name of the calendar |
127 * @param calendarType the calendar type |
127 * @param calendarType the calendar type |
128 * @return {@code true} if the file was read and each entry accepted by the |
128 * @return {@code true} if the file was read and each entry accepted by the |
129 * Block; else {@code false} no configuration was done |
129 * Consumer; else {@code false} no configuration was done |
130 * |
130 * |
131 * @throws IOException for zip/jar file handling exception. |
131 * @throws IOException for zip/jar file handling exception. |
132 * @throws ParseException if the format of the configuration file is wrong. |
132 * @throws ParseException if the format of the configuration file is wrong. |
133 */ |
133 */ |
134 static boolean readDeviation(String typeId, String calendarType, |
134 static boolean readDeviation(String typeId, String calendarType, |
135 Block<HijrahChronology.Deviation> block) throws IOException, ParseException { |
135 Consumer<HijrahChronology.Deviation> consumer) throws IOException, ParseException { |
136 InputStream is = getConfigFileInputStream(typeId); |
136 InputStream is = getConfigFileInputStream(typeId); |
137 if (is != null) { |
137 if (is != null) { |
138 try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { |
138 try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { |
139 String line = ""; |
139 String line = ""; |
140 int num = 0; |
140 int num = 0; |
141 while ((line = br.readLine()) != null) { |
141 while ((line = br.readLine()) != null) { |
142 num++; |
142 num++; |
143 HijrahChronology.Deviation entry = parseLine(line, num); |
143 HijrahChronology.Deviation entry = parseLine(line, num); |
144 if (entry != null) { |
144 if (entry != null) { |
145 block.accept(entry); |
145 consumer.accept(entry); |
146 } |
146 } |
147 } |
147 } |
148 } |
148 } |
149 return true; |
149 return true; |
150 } |
150 } |