src/share/classes/java/time/chrono/HijrahDeviationReader.java

Print this page

        

*** 52,62 **** * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package java.time.calendar; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; --- 52,62 ---- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ ! package java.time.chrono; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream;
*** 65,77 **** import java.io.InputStreamReader; import java.nio.file.FileSystems; import java.security.AccessController; import java.text.ParseException; import java.time.LocalDate; ! import java.time.format.DateTimeFormatters; import java.time.temporal.ChronoField; - import java.time.temporal.ChronoLocalDate; import java.util.Arrays; import java.util.function.Block; /** * A reader for Hijrah Deviation files. --- 65,76 ---- import java.io.InputStreamReader; import java.nio.file.FileSystems; import java.security.AccessController; import java.text.ParseException; import java.time.LocalDate; ! import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoField; import java.util.Arrays; import java.util.function.Block; /** * A reader for Hijrah Deviation files.
*** 83,93 **** * The default location of the deviation files is * {@code <java.home> + FILE_SEP + "lib"}. * The deviation files are named {@code "hijrah_" + ID}. * <p> * The deviation file for a calendar can be overridden by defining the ! * property {@code java.time.calendar.HijrahChrono.File.hijrah_<ID>} * with the full pathname of the deviation file. * <p> * The deviation file is read line by line: * <ul> * <li>The "#" character begins a comment - --- 82,92 ---- * The default location of the deviation files is * {@code <java.home> + FILE_SEP + "lib"}. * The deviation files are named {@code "hijrah_" + ID}. * <p> * The deviation file for a calendar can be overridden by defining the ! * property {@code java.time.chrono.HijrahChronology.File.hijrah_<ID>} * with the full pathname of the deviation file. * <p> * The deviation file is read line by line: * <ul> * <li>The "#" character begins a comment -
*** 131,149 **** * * @throws IOException for zip/jar file handling exception. * @throws ParseException if the format of the configuration file is wrong. */ static boolean readDeviation(String typeId, String calendarType, ! Block<HijrahChrono.Deviation> block) throws IOException, ParseException { InputStream is = getConfigFileInputStream(typeId); if (is != null) { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String line = ""; int num = 0; while ((line = br.readLine()) != null) { num++; ! HijrahChrono.Deviation entry = parseLine(line, num); if (entry != null) { block.accept(entry); } } } --- 130,148 ---- * * @throws IOException for zip/jar file handling exception. * @throws ParseException if the format of the configuration file is wrong. */ static boolean readDeviation(String typeId, String calendarType, ! Block<HijrahChronology.Deviation> block) throws IOException, ParseException { InputStream is = getConfigFileInputStream(typeId); if (is != null) { try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) { String line = ""; int num = 0; while ((line = br.readLine()) != null) { num++; ! HijrahChronology.Deviation entry = parseLine(line, num); if (entry != null) { block.accept(entry); } } }
*** 158,168 **** * @param line a line to parse * @param num line number * @return an Entry or null if the line is empty. * @throws ParseException if line has incorrect format. */ ! private static HijrahChrono.Deviation parseLine(final String line, final int num) throws ParseException { int hash = line.indexOf("#"); String nocomment = (hash < 0) ? line : line.substring(0, hash); String[] split = nocomment.split("\\s"); if (split.length == 0 || split[0].isEmpty()) { return null; // Nothing to parse --- 157,167 ---- * @param line a line to parse * @param num line number * @return an Entry or null if the line is empty. * @throws ParseException if line has incorrect format. */ ! private static HijrahChronology.Deviation parseLine(final String line, final int num) throws ParseException { int hash = line.indexOf("#"); String nocomment = (hash < 0) ? line : line.substring(0, hash); String[] split = nocomment.split("\\s"); if (split.length == 0 || split[0].isEmpty()) { return null; // Nothing to parse
*** 172,191 **** } //element [0] is a date //element [1] is the offset ! LocalDate isoDate = DateTimeFormatters.pattern("MMM-dd-yyyy").parse(split[0], LocalDate::from); int offset = Integer.valueOf(split[1]); // Convert date to HijrahDate using the default Islamic Calendar ! ChronoLocalDate<HijrahChrono> hijrahDate = HijrahChrono.INSTANCE.date(isoDate); int year = hijrahDate.get(ChronoField.YEAR); int month = hijrahDate.get(ChronoField.MONTH_OF_YEAR); ! return new HijrahChrono.Deviation(year, month, year, month, offset); } /** * Return InputStream for deviation configuration file. The default location --- 171,190 ---- } //element [0] is a date //element [1] is the offset ! LocalDate isoDate = DateTimeFormatter.ofPattern("MMM-dd-yyyy").parse(split[0], LocalDate::from); int offset = Integer.valueOf(split[1]); // Convert date to HijrahDate using the default Islamic Calendar ! HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(isoDate); int year = hijrahDate.get(ChronoField.YEAR); int month = hijrahDate.get(ChronoField.MONTH_OF_YEAR); ! return new HijrahChronology.Deviation(year, month, year, month, offset); } /** * Return InputStream for deviation configuration file. The default location
*** 196,220 **** * <pre> * hijrah_ + typeId + .cfg * </pre> The default location and file name can be overridden by setting * following two Java system properties. * <pre> ! * Location: java.time.calendar.HijrahDate.deviationConfigDir ! * File name: java.time.calendar.HijrahDate.File. + typeid * </pre> Regarding the file format, see readDeviationConfig() method for * details. * * @param typeId the name of the calendar deviation data * @return InputStream for file reading. * @throws IOException for zip/jar file handling exception. */ private static InputStream getConfigFileInputStream(final String typeId) throws IOException { try { ! InputStream stream = ! (InputStream)AccessController ! .doPrivileged((java.security.PrivilegedExceptionAction) () -> { ! String propFilename = "java.time.calendar.HijrahChrono.File." + typeId; String filename = System.getProperty(propFilename); File file = null; if (filename != null) { file = new File(filename); } else { --- 195,218 ---- * <pre> * hijrah_ + typeId + .cfg * </pre> The default location and file name can be overridden by setting * following two Java system properties. * <pre> ! * Location: java.time.chrono.HijrahDate.deviationConfigDir ! * File name: java.time.chrono.HijrahDate.File. + typeid * </pre> Regarding the file format, see readDeviationConfig() method for * details. * * @param typeId the name of the calendar deviation data * @return InputStream for file reading. * @throws IOException for zip/jar file handling exception. */ private static InputStream getConfigFileInputStream(final String typeId) throws IOException { try { ! InputStream stream = AccessController ! .doPrivileged((java.security.PrivilegedExceptionAction<InputStream>) () -> { ! String propFilename = "java.time.chrono.HijrahChronology.File." + typeId; String filename = System.getProperty(propFilename); File file = null; if (filename != null) { file = new File(filename); } else {