Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of JSR-310 nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* 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 org.threeten.bp.zone;
import static org.threeten.bp.temporal.ChronoField.HOUR_OF_DAY;
import static org.threeten.bp.temporal.ChronoField.MINUTE_OF_HOUR;
import static org.threeten.bp.temporal.ChronoField.SECOND_OF_MINUTE;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParsePosition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import org.threeten.bp.DayOfWeek;
import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.LocalTime;
import org.threeten.bp.Month;
import org.threeten.bp.Year;
import org.threeten.bp.ZoneOffset;
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalAdjusters;
import org.threeten.bp.zone.ZoneOffsetTransitionRule.TimeDefinition;
/**
* A builder that can read the TZDB time-zone files and build {@code ZoneRules} instances.
*
*
Specification for implementors
* This class is a mutable builder. A new instance must be created for each compile.
*/
final class TzdbZoneRulesCompiler {
/**
* Time parser.
*/
private static final DateTimeFormatter TIME_PARSER;
static {
TIME_PARSER = new DateTimeFormatterBuilder()
.appendValue(HOUR_OF_DAY)
.optionalStart().appendLiteral(':').appendValue(MINUTE_OF_HOUR, 2)
.optionalStart().appendLiteral(':').appendValue(SECOND_OF_MINUTE, 2)
.toFormatter();
}
private static final Set RULE_LOOKUP = expand("rule", "r");
private static final Set ZONE_LOOKUP = expand("zone", "z");
private static final Set LINK_LOOKUP = expand("link", "l");
private static final Set MIN_YEAR_LOOKUP = expand("minimum", "mi");
private static final Set MAX_YEAR_LOOKUP = expand("maximum", "ma");
private static final Set ONLY_YEAR_LOOKUP = expand("only", "o");
private static final Map MONTH_LOOKUP = new HashMap();
static {
put(expand("january", "ja"), 1, MONTH_LOOKUP);
put(expand("february", "f"), 2, MONTH_LOOKUP);
put(expand("march", "mar"), 3, MONTH_LOOKUP);
put(expand("april", "ap"), 4, MONTH_LOOKUP);
put(expand("may", "may"), 5, MONTH_LOOKUP);
put(expand("june", "jun"), 6, MONTH_LOOKUP);
put(expand("july", "jul"), 7, MONTH_LOOKUP);
put(expand("august", "au"), 8, MONTH_LOOKUP);
put(expand("september", "s"), 9, MONTH_LOOKUP);
put(expand("october", "o"), 10, MONTH_LOOKUP);
put(expand("november", "n"), 11, MONTH_LOOKUP);
put(expand("december", "d"), 12, MONTH_LOOKUP);
}
private static final Map DOW_LOOKUP = new HashMap();
static {
put(expand("monday", "m"), 1, DOW_LOOKUP);
put(expand("tuesday", "tu"), 2, DOW_LOOKUP);
put(expand("wednesday", "w"), 3, DOW_LOOKUP);
put(expand("thursday", "th"), 4, DOW_LOOKUP);
put(expand("friday", "f"), 5, DOW_LOOKUP);
put(expand("saturday", "sa"), 6, DOW_LOOKUP);
put(expand("sunday", "su"), 7, DOW_LOOKUP);
}
private static void put(Set strs, int value, Map map) {
for (Iterator it = strs.iterator(); it.hasNext();) {
map.put(it.next(), value);
}
}
private static Set expand(String whole, String shortest) {
Set set = new HashSet();
String code = whole;
while (!code.equals(shortest)) {
set.add(code);
code = code.substring(0, code.length() - 1);
}
set.add(code);
return set;
}
/**
* Reads a set of TZDB files and builds a single combined data file.
*
* @param args the arguments
*/
public static void main(String[] args) {
if (args.length < 2) {
outputHelp();
return;
}
// parse args
String version = null;
File baseSrcDir = null;
File dstDir = null;
boolean unpacked = false;
boolean verbose = false;
// parse options
int i;
for (i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.startsWith("-") == false) {
break;
}
if ("-srcdir".equals(arg)) {
if (baseSrcDir == null && ++i < args.length) {
baseSrcDir = new File(args[i]);
continue;
}
} else if ("-dstdir".equals(arg)) {
if (dstDir == null && ++i < args.length) {
dstDir = new File(args[i]);
continue;
}
} else if ("-version".equals(arg)) {
if (version == null && ++i < args.length) {
version = args[i];
continue;
}
} else if ("-unpacked".equals(arg)) {
if (unpacked == false) {
unpacked = true;
continue;
}
} else if ("-verbose".equals(arg)) {
if (verbose == false) {
verbose = true;
continue;
}
} else if ("-help".equals(arg) == false) {
System.out.println("Unrecognised option: " + arg);
}
outputHelp();
return;
}
// check source directory
if (baseSrcDir == null) {
System.out.println("Source directory must be specified using -srcdir: " + baseSrcDir);
return;
}
if (baseSrcDir.isDirectory() == false) {
System.out.println("Source does not exist or is not a directory: " + baseSrcDir);
return;
}
dstDir = (dstDir != null ? dstDir : baseSrcDir);
// parse source file names
List srcFileNames = Arrays.asList(Arrays.copyOfRange(args, i, args.length));
if (srcFileNames.isEmpty()) {
System.out.println("Source filenames not specified, using default set");
System.out.println("(africa antarctica asia australasia backward etcetera europe northamerica southamerica)");
srcFileNames = Arrays.asList("africa", "antarctica", "asia", "australasia", "backward",
"etcetera", "europe", "northamerica", "southamerica");
}
// find source directories to process
List srcDirs = new ArrayList();
if (version != null) {
File srcDir = new File(baseSrcDir, version);
if (srcDir.isDirectory() == false) {
System.out.println("Version does not represent a valid source directory : " + srcDir);
return;
}
srcDirs.add(srcDir);
} else {
File[] dirs = baseSrcDir.listFiles();
for (File dir : dirs) {
if (dir.isDirectory() && dir.getName().matches("[12][0-9][0-9][0-9][A-Za-z0-9._-]+")) {
srcDirs.add(dir);
}
}
}
if (srcDirs.isEmpty()) {
System.out.println("Source directory contains no valid source folders: " + baseSrcDir);
return;
}
// check destination directory
if (dstDir.exists() == false && dstDir.mkdirs() == false) {
System.out.println("Destination directory could not be created: " + dstDir);
return;
}
if (dstDir.isDirectory() == false) {
System.out.println("Destination is not a directory: " + dstDir);
return;
}
process(srcDirs, srcFileNames, dstDir, unpacked, verbose);
}
/**
* Output usage text for the command line.
*/
private static void outputHelp() {
System.out.println("Usage: TzdbZoneRulesCompiler ");
System.out.println("where options include:");
System.out.println(" -srcdir Where to find source directories (required)");
System.out.println(" -dstdir Where to output generated files (default srcdir)");
System.out.println(" -version Specify the version, such as 2009a (optional)");
System.out.println(" -unpacked Generate dat files without jar files");
System.out.println(" -help Print this usage message");
System.out.println(" -verbose Output verbose information during compilation");
System.out.println(" There must be one directory for each version in srcdir");
System.out.println(" Each directory must have the name of the version, such as 2009a");
System.out.println(" Each directory must contain the unpacked tzdb files, such as asia or europe");
System.out.println(" Directories must match the regex [12][0-9][0-9][0-9][A-Za-z0-9._-]+");
System.out.println(" There will be one jar file for each version and one combined jar in dstdir");
System.out.println(" If the version is specified, only that version is processed");
}
/**
* Process to create the jar files.
*/
private static void process(List srcDirs, List srcFileNames, File dstDir, boolean unpacked, boolean verbose) {
// build actual jar files
Map