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

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

Introduction

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

Prototype

public ZoneInfoCompiler() 

Source Link

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   ww  w. java  2  s . c  om
    }
    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));
    }/*  ww w. j  ava  2  s  .  c  om*/

    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;
}