< prev index next >

make/jdk/src/classes/build/tools/tzdb/TzdbZoneRulesCompiler.java

Print this page
rev 55794 : [mq]: 8212970
   1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 247             // group
 248             out.writeUTF("TZDB");
 249             // versions
 250             out.writeShort(1);
 251             out.writeUTF(version);
 252             // regions
 253             String[] regionArray = builtZones.keySet().toArray(new String[builtZones.size()]);
 254             out.writeShort(regionArray.length);
 255             for (String regionId : regionArray) {
 256                 out.writeUTF(regionId);
 257             }
 258             // rules  -- remove the dup
 259             List<ZoneRules> rulesList = builtZones.values().stream()
 260                 .distinct()
 261                 .collect(Collectors.toList());
 262             out.writeShort(rulesList.size());
 263             ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
 264             for (ZoneRules rules : rulesList) {
 265                 baos.reset();
 266                 DataOutputStream dataos = new DataOutputStream(baos);
 267                 rules.writeExternal(dataos);
 268                 dataos.close();
 269                 byte[] bytes = baos.toByteArray();
 270                 out.writeShort(bytes.length);
 271                 out.write(bytes);
 272             }
 273             // link version-region-rules
 274             out.writeShort(builtZones.size());
 275             for (Map.Entry<String, ZoneRules> entry : builtZones.entrySet()) {
 276                  int regionIndex = Arrays.binarySearch(regionArray, entry.getKey());
 277                  int rulesIndex = rulesList.indexOf(entry.getValue());
 278                  out.writeShort(regionIndex);
 279                  out.writeShort(rulesIndex);
 280             }
 281             // alias-region
 282             out.writeShort(links.size());
 283             for (Map.Entry<String, String> entry : links.entrySet()) {
 284                  int aliasIndex = Arrays.binarySearch(regionArray, entry.getKey());
 285                  int regionIndex = Arrays.binarySearch(regionArray, entry.getValue());
 286                  out.writeShort(aliasIndex);
 287                  out.writeShort(regionIndex);


   1 /*
   2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 247             // group
 248             out.writeUTF("TZDB");
 249             // versions
 250             out.writeShort(1);
 251             out.writeUTF(version);
 252             // regions
 253             String[] regionArray = builtZones.keySet().toArray(new String[builtZones.size()]);
 254             out.writeShort(regionArray.length);
 255             for (String regionId : regionArray) {
 256                 out.writeUTF(regionId);
 257             }
 258             // rules  -- remove the dup
 259             List<ZoneRules> rulesList = builtZones.values().stream()
 260                 .distinct()
 261                 .collect(Collectors.toList());
 262             out.writeShort(rulesList.size());
 263             ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
 264             for (ZoneRules rules : rulesList) {
 265                 baos.reset();
 266                 DataOutputStream dataos = new DataOutputStream(baos);
 267                 Ser.write(rules, dataos);
 268                 dataos.close();
 269                 byte[] bytes = baos.toByteArray();
 270                 out.writeShort(bytes.length);
 271                 out.write(bytes);
 272             }
 273             // link version-region-rules
 274             out.writeShort(builtZones.size());
 275             for (Map.Entry<String, ZoneRules> entry : builtZones.entrySet()) {
 276                  int regionIndex = Arrays.binarySearch(regionArray, entry.getKey());
 277                  int rulesIndex = rulesList.indexOf(entry.getValue());
 278                  out.writeShort(regionIndex);
 279                  out.writeShort(rulesIndex);
 280             }
 281             // alias-region
 282             out.writeShort(links.size());
 283             for (Map.Entry<String, String> entry : links.entrySet()) {
 284                  int aliasIndex = Arrays.binarySearch(regionArray, entry.getKey());
 285                  int regionIndex = Arrays.binarySearch(regionArray, entry.getValue());
 286                  out.writeShort(aliasIndex);
 287                  out.writeShort(regionIndex);


< prev index next >