Example usage for org.joda.time.tz ZoneInfoCompiler compile

List of usage examples for org.joda.time.tz ZoneInfoCompiler compile

Introduction

In this page you can find the example usage for org.joda.time.tz ZoneInfoCompiler compile.

Prototype

public Map<String, DateTimeZone> compile(File outputDir, File[] sources) throws IOException 

Source Link

Document

Returns a map of ids to DateTimeZones.

Usage

From source file:nodatime.jodadump.JodaDump.java

License:Open Source License

public static void main(String[] args) throws IOException {

    if (args.length < 1 || args.length > 2) {
        System.out.println("Usage: JodaDump <directory> [zone]");
        return;/*from w w  w  . ja  va 2 s.  c  o  m*/
    }
    File directory = new File(args[0]);
    if (!directory.isDirectory()) {
        System.out.println(directory + " is not a directory");
        return;
    }

    File[] files = directory.listFiles();

    ZoneInfoCompiler compiler = new ZoneInfoCompiler();
    PrintStream out = System.out;
    System.setOut(new PrintStream(new ByteArrayOutputStream()));
    Map<String, DateTimeZone> zones = compiler.compile(null, files);
    System.setOut(out);

    if (args.length == 2) {
        String id = args[1];
        DateTimeZone zone = zones.get(id);
        if (zone == null) {
            System.out.println("Zone " + id + " does not exist");
        } else {
            dumpZone(id, zone);
        }
    } else {
        // Sort IDs in ordinal fashion
        List<String> ids = new ArrayList<String>(zones.keySet());
        Collections.sort(ids); // compareTo does ordinal comparisons
        for (String id : ids) {
            dumpZone(id, zones.get(id));
        }
    }
}

From source file:org.nodatime.tzvalidate.JodaDump.java

License:Open Source License

private static Map<String, DateTimeZone> getZones(String source) throws IOException {
    if (source == null) {
        return DateTimeZone.getAvailableIDs().stream().collect(Collectors.toMap(id -> id, DateTimeZone::forID));
    }//from ww w  .j  a  v a 2 s .c o  m

    File directory = new File(source);
    if (!directory.isDirectory()) {
        throw new IOException(directory + " is not a directory");
    }
    File[] files = KNOWN_FILES.stream().map(f -> new File(directory, f)).toArray(File[]::new);
    ZoneInfoCompiler compiler = new ZoneInfoCompiler();
    PrintStream out = System.out;
    // Ignore standard output while compiling...
    System.setOut(new PrintStream(new ByteArrayOutputStream()));
    Map<String, DateTimeZone> zones = compiler.compile(null, files);
    System.setOut(out);
    return zones;
}