jdk/src/share/classes/sun/util/calendar/ZoneInfoFile.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 4194 eaf8321acdc1
child 6499 7d8804ed110b
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4194
diff changeset
     2
 * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4194
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4194
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4194
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4194
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4194
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.util.calendar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import  java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import  java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import  java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import  java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import  java.lang.ref.SoftReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import  java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import  java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import  java.security.PrivilegedActionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import  java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import  java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import  java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import  java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import  java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>ZoneInfoFile</code> reads Zone information files in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * &lt;java.home&gt;/lib/zi directory and provides time zone
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * information in the form of a {@link ZoneInfo} object. Also, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * reads the ZoneInfoMappings file to obtain time zone IDs information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * that is used by the {@link ZoneInfo} class. The directory layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * and data file formats are as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p><strong>Directory layout</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * All zone data files and ZoneInfoMappings are put under the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * &lt;java.home&gt;/lib/zi directory. A path name for a given time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * zone ID is a concatenation of &lt;java.home&gt;/lib/zi/ and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * time zone ID. (The file separator is replaced with the platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * dependent value. e.g., '\' for Win32.) An example layout will look
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * like as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * &lt;java.home&gt;/lib/zi/Africa/Addis_Ababa
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *                   /Africa/Dakar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *                   /America/Los_Angeles
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *                   /Asia/Singapore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *                   /EET
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *                   /Europe/Oslo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *                   /GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *                   /Pacific/Galapagos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *                       ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *                   /ZoneInfoMappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * A zone data file has specific information of each zone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <code>ZoneInfoMappings</code> has global information of zone IDs so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * that the information can be obtained without instantiating all time
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * zones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p><strong>File format</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * Two binary-file formats based on a simple Tag-Length-Value format are used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * to describe TimeZone information. The generic format of a data file is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *    DataFile {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *      u1              magic[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *      u1              version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *      data_item       data[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * where <code>magic</code> is a magic number identifying a file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * format, <code>version</code> is the format version number, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <code>data</code> is one or more <code>data_item</code>s. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <code>data_item</code> structure is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *    data_item {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *      u1              tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *      u2              length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *      u1              value[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * where <code>tag</code> indicates the data type of the item,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <code>length</code> is a byte count of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <code>value</code> that is the content of item data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * All data is stored in the big-endian order. There is no boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * alignment between date items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <p><strong>1. ZoneInfo data file</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * Each ZoneInfo data file consists of the following members.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *    ZoneInfoDataFile {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *      u1              magic[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *      u1              version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *      SET OF<sup>1</sup> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *        transition            transitions<sup>2</sup>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *        offset_table          offsets<sup>2</sup>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *        simpletimezone        stzparams<sup>2</sup>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *        raw_offset            rawoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *        dstsaving             dst;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 *        checksum              crc32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *        gmtoffsetwillchange   gmtflag<sup>2</sup>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *   1: an unordered collection of zero or one occurrences of each item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 *   2: optional item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <code>magic</code> is a byte-string constant identifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * ZoneInfo data file.  This field must be <code>"javazi&#92;0"</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * defined as {@link #JAVAZI_LABEL}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * <code>version</code> is the version number of the file format. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * will be used for compatibility check. This field must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <code>0x01</code> in this version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <code>transition</code>, <code>offset_table</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <code>simpletimezone</code> have information of time transition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * from the past to the future.  Therefore, these structures don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * exist if the zone didn't change zone names and haven't applied DST in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * the past, and haven't planned to apply it.  (e.g. Asia/Tokyo zone)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <code>raw_offset</code>, <code>dstsaving</code> and <code>checksum</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * exist in every zoneinfo file. They are used by TimeZone.class indirectly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <p><strong>1.1 <code>transition</code> structure</strong><p><a name="transition"></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *    transition {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *      u1      tag;              // 0x04 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *      u2      length;           // byte length of whole values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *      s8      value[length/8];  // transitions in `long'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * See {@link ZoneInfo#transitions ZoneInfo.transitions} about the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * <p><strong>1.2 <code>offset_table</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *    offset_table {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *      u1      tag;              // 0x05 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *      u2      length;           // byte length of whole values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *      s4      value[length/4];  // offset values in `int'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * <p><strong>1.3 <code>simpletimezone</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * See {@link ZoneInfo#simpleTimeZoneParams ZoneInfo.simpleTimeZoneParams}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * about the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *    simpletimezone {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *      u1      tag;              // 0x06 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 *      u2      length;           // byte length of whole values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 *      s4      value[length/4];  // SimpleTimeZone parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * See {@link ZoneInfo#offsets ZoneInfo.offsets} about the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * <p><strong>1.4 <code>raw_offset</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 *    raw_offset {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 *      u1      tag;              // 0x01 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *      u2      length;           // must be 4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *      s4      value;            // raw GMT offset [millisecond]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * See {@link ZoneInfo#rawOffset ZoneInfo.rawOffset} about the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * <p><strong>1.5 <code>dstsaving</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * Value has dstSaving in seconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 *    dstsaving {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 *      u1      tag;              // 0x02 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *      u2      length;           // must be 2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 *      s2      value;            // DST save value [second]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * See {@link ZoneInfo#dstSavings ZoneInfo.dstSavings} about value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * <p><strong>1.6 <code>checksum</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 *    checksum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 *      u1      tag;              // 0x03 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *      u2      length;           // must be 4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 *      s4      value;            // CRC32 value of transitions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * See {@link ZoneInfo#checksum ZoneInfo.checksum}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * <p><strong>1.7 <code>gmtoffsetwillchange</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * This record has a flag value for {@link ZoneInfo#rawOffsetWillChange}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * If this record is not present in a zoneinfo file, 0 is assumed for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * the value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *    gmtoffsetwillchange {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 *      u1      tag;             // 0x07 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 *      u2      length;          // must be 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 *      u1      value;           // 1: if the GMT raw offset will change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 *                               // in the future, 0, otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * <p><strong>2. ZoneInfoMappings file</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * The ZoneInfoMappings file consists of the following members.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 *    ZoneInfoMappings {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 *      u1      magic[7];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 *      u1      version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *      SET OF {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 *        versionName                   version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 *        zone_id_table                 zoneIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 *        raw_offset_table              rawoffsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 *        raw_offset_index_table        rawoffsetindices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 *        alias_table                   aliases;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 *        excluded_list                 excludedList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * <code>magic</code> is a byte-string constant which has the file type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * This field must be <code>"javazm&#92;0"</code> defined as {@link #JAVAZM_LABEL}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * <code>version</code> is the version number of this file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * format. This will be used for compatibility check. This field must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * be <code>0x01</code> in this version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * <code>versionName</code> shows which version of Olson's data has been used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * to generate this ZoneInfoMappings. (e.g. <code>tzdata2000g</code>) <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 * This field is for trouble-shooting and isn't usually used in runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * <code>zone_id_table</code>, <code>raw_offset_index_table</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * <code>alias_table</code> are general information of supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * zones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 * <p><strong>2.1 <code>zone_id_table</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 * The list of zone IDs included in the zi database. The list does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 * <em>not</em> include zone IDs, if any, listed in excludedList.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 *    zone_id_table {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 *      u1      tag;              // 0x40 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 *      u2      length;           // byte length of whole values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 *      u2      zone_id_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 *      zone_id value[zone_id_count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 *    zone_id {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 *      u1      byte_length;      // byte length of id
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 *      u1      id[byte_length];  // zone name string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * <p><strong>2.2 <code>raw_offset_table</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 *    raw_offset_table {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 *      u1      tag;              // 0x41 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 *      u2      length;           // byte length of whole values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 *      s4      value[length/4];  // raw GMT offset in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 * <p><strong>2.3 <code>raw_offset_index_table</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 *    raw_offset_index_table {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
 *      u1      tag;              // 0x42 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 *      u2      length;           // byte length of whole values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 *      u1      value[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
 * <p><strong>2.4 <code>alias_table</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
 *   alias_table {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
 *      u1      tag;              // 0x43 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
 *      u2      length;           // byte length of whole values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
 *      u2      nentries;         // number of id-pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
 *      id_pair value[nentries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 *   id_pair {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 *      zone_id aliasname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
 *      zone_id ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
 * <p><strong>2.5 <code>versionName</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 *   versionName {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 *      u1      tag;              // 0x44 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 *      u2      length;           // byte length of whole values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
 *      u1      value[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
 * <p><strong>2.6 <code>excludeList</code> structure</strong><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
 * The list of zone IDs whose zones will change their GMT offsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
 * (a.k.a. raw offsets) some time in the future. Those IDs must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
 * added to the list of zone IDs for getAvailableIDs(). Also they must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
 * be examined for getAvailableIDs(int) to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
 * <em>current</em> GMT offsets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
 * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
 *   excluded_list {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
 *      u1      tag;              // 0x45 : constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
 *      u2      length;           // byte length of whole values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
 *      u2      nentries;         // number of zone_ids
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
 *      zone_id value[nentries];  // excluded zone IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
public class ZoneInfoFile {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * The magic number for the ZoneInfo data file format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public static final byte[]  JAVAZI_LABEL = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        (byte)'j', (byte)'a', (byte)'v', (byte)'a', (byte)'z', (byte)'i', (byte)'\0'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    private static final int    JAVAZI_LABEL_LENGTH = JAVAZI_LABEL.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * The ZoneInfo data file format version number. Must increase
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * one when any incompatible change has been made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public static final byte    JAVAZI_VERSION = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Raw offset data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public static final byte    TAG_RawOffset = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Known last Daylight Saving Time save value data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public static final byte    TAG_LastDSTSaving = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Checksum data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public static final byte    TAG_CRC32 = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Transition data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public static final byte    TAG_Transition = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Offset table data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public static final byte    TAG_Offset = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * SimpleTimeZone parameters data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public static final byte    TAG_SimpleTimeZone = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Raw GMT offset will change in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public static final byte    TAG_GMTOffsetWillChange = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * The ZoneInfoMappings file name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    public static final String  JAVAZM_FILE_NAME = "ZoneInfoMappings";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * The magic number for the ZoneInfoMappings file format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public static final byte[]  JAVAZM_LABEL = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        (byte)'j', (byte)'a', (byte)'v', (byte)'a', (byte)'z', (byte)'m', (byte)'\0'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    private static final int    JAVAZM_LABEL_LENGTH = JAVAZM_LABEL.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * The ZoneInfoMappings file format version number. Must increase
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * one when any incompatible change has been made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public static final byte    JAVAZM_VERSION = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Time zone IDs data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public static final byte    TAG_ZoneIDs = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Raw GMT offsets table data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public static final byte    TAG_RawOffsets = 65;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Indices to the raw GMT offset table data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public static final byte    TAG_RawOffsetIndices = 66;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Time zone aliases table data item tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public static final byte    TAG_ZoneAliases = 67;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Olson's public zone information version tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public static final byte    TAG_TZDataVersion = 68;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * Excluded zones item tag. (Added in Mustang)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public static final byte    TAG_ExcludedZones = 69;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    private static Map<String, ZoneInfo> zoneInfoObjects = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
4194
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   475
    private static final String ziDir;
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   476
    static {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   477
        String zi = (String) AccessController.doPrivileged(
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   478
                         new sun.security.action.GetPropertyAction("java.home"))
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   479
                    + File.separator + "lib" + File.separator + "zi";
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   480
        try {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   481
            zi = new File(zi).getCanonicalPath();
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   482
        } catch (Exception e) {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   483
        }
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   484
        ziDir = zi;
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   485
    }
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   486
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Converts the given time zone ID to a platform dependent path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * name. For example, "America/Los_Angeles" is converted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * "America\Los_Angeles" on Win32.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @return a modified ID replacing '/' with {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * java.io.File#separatorChar File.separatorChar} if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public static String getFileName(String ID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        if (File.separatorChar == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            return ID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return ID.replace('/', File.separatorChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * Gets a ZoneInfo with the given GMT offset. The object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * has its ID in the format of GMT{+|-}hh:mm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @param originalId the given custom id (before normalized such as "GMT+9")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @param gmtOffset GMT offset <em>in milliseconds</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @return a ZoneInfo constructed with the given GMT offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public static ZoneInfo getCustomTimeZone(String originalId, int gmtOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        String id = toCustomID(gmtOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        ZoneInfo zi = getFromCache(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if (zi == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            zi = new ZoneInfo(id, gmtOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            zi = addToCache(id, zi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            if (!id.equals(originalId)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                zi = addToCache(originalId, zi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        return (ZoneInfo) zi.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public static String toCustomID(int gmtOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        char sign;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        int offset = gmtOffset / 60000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (offset >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            sign = '+';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            sign = '-';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            offset = -offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        int hh = offset / 60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        int mm = offset % 60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        char[] buf = new char[] { 'G', 'M', 'T', sign, '0', '0', ':', '0', '0' };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if (hh >= 10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            buf[4] += hh / 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        buf[5] += hh % 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (mm != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            buf[7] += mm / 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            buf[8] += mm % 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        return new String(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @return a ZoneInfo instance created for the specified id, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * null if there is no time zone data file found for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    public static ZoneInfo getZoneInfo(String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        ZoneInfo zi = getFromCache(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (zi == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            zi = createZoneInfo(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            if (zi == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            zi = addToCache(id, zi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return (ZoneInfo) zi.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    synchronized static ZoneInfo getFromCache(String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        if (zoneInfoObjects == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        return zoneInfoObjects.get(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    synchronized static ZoneInfo addToCache(String id, ZoneInfo zi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (zoneInfoObjects == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            zoneInfoObjects = new HashMap<String, ZoneInfo>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            ZoneInfo zone = zoneInfoObjects.get(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            if (zone != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                return zone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        zoneInfoObjects.put(id, zi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        return zi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    private static ZoneInfo createZoneInfo(String id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        byte[] buf = readZoneInfoFile(getFileName(id));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (buf == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
4194
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   591
        int index = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        int filesize = buf.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        int rawOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        int dstSavings = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        int checksum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        boolean willGMTOffsetChange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        long[] transitions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        int[] offsets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        int[] simpleTimeZoneParams = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        try {
4194
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   602
            for (index = 0; index < JAVAZI_LABEL.length; index++) {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   603
                if (buf[index] != JAVAZI_LABEL[index]) {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   604
                    System.err.println("ZoneInfo: wrong magic number: " + id);
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   605
                    return null;
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   606
                }
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   607
            }
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   608
            if (buf[index++] > JAVAZI_VERSION) {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   609
                System.err.println("ZoneInfo: incompatible version ("
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   610
                                   + buf[index - 1] + "): " + id);
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   611
                return null;
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   612
            }
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
   613
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            while (index < filesize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                byte tag = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                int  len = ((buf[index++] & 0xFF) << 8) + (buf[index++] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                if (filesize < index+len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                case TAG_CRC32:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                        int val = buf[index++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                        val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                        val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                        val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                        checksum = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                case TAG_LastDSTSaving:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                        short val = (short)(buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                        val = (short)((val << 8) + (buf[index++] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                        dstSavings = val * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                case TAG_RawOffset:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                        int val = buf[index++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                        val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                        val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                        val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                        rawOffset = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                case TAG_Transition:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                        int n = len / 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                        transitions = new long[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                        for (int i = 0; i < n; i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                            long val = buf[index++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                            transitions[i] = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                case TAG_Offset:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                        int n = len / 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                        offsets = new int[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                        for (int i = 0; i < n; i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                            int val = buf[index++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                            offsets[i] = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                case TAG_SimpleTimeZone:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                        if (len != 32 && len != 40) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                            System.err.println("ZoneInfo: wrong SimpleTimeZone parameter size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                        int n = len / 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                        simpleTimeZoneParams = new int[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                            int val = buf[index++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                            simpleTimeZoneParams[i] = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                case TAG_GMTOffsetWillChange:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                        if (len != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                            System.err.println("ZoneInfo: wrong byte length for TAG_GMTOffsetWillChange");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                        willGMTOffsetChange = buf[index++] == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    System.err.println("ZoneInfo: unknown tag < " + tag + ">. ignored.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    index += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            System.err.println("ZoneInfo: corrupted zoneinfo file: " + id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        if (index != filesize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            System.err.println("ZoneInfo: wrong file size: " + id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        return new ZoneInfo(id, rawOffset, dstSavings, checksum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                            transitions, offsets, simpleTimeZoneParams,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                            willGMTOffsetChange);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    private volatile static SoftReference<List<String>> zoneIDs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    static List<String> getZoneIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        List<String> ids = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        SoftReference<List<String>> cache = zoneIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        if (cache != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            ids = cache.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            if (ids != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                return ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        byte[] buf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        buf = getZoneInfoMappings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        int index = JAVAZM_LABEL_LENGTH + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        int filesize = buf.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            while (index < filesize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                byte tag = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                int     len = ((buf[index++] & 0xFF) << 8) + (buf[index++] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                case TAG_ZoneIDs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                        int n = (buf[index++] << 8) + (buf[index++] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                        ids = new ArrayList<String>(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                            byte m = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                            ids.add(new String(buf, index, m, "UTF-8"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                            index += m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                    index += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            System.err.println("ZoneInfo: corrupted " + JAVAZM_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        zoneIDs = new SoftReference<List<String>>(ids);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        return ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * @return an alias table in HashMap where a key is an alias ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * (e.g., "PST") and its value is a real time zone ID (e.g.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * "America/Los_Angeles").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    static Map<String, String> getZoneAliases() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        byte[] buf = getZoneInfoMappings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        int index = JAVAZM_LABEL_LENGTH + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        int filesize = buf.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        Map<String, String> aliases = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            while (index < filesize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                byte tag = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                int     len = ((buf[index++] & 0xFF) << 8) + (buf[index++] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                case TAG_ZoneAliases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                        int n = (buf[index++] << 8) + (buf[index++] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                        aliases = new HashMap<String, String>(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                            byte m = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                            String name = new String(buf, index, m, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                            index += m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                            m = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                            String realName = new String(buf, index, m, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                            index += m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                            aliases.put(name, realName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    index += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            System.err.println("ZoneInfo: corrupted " + JAVAZM_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        return aliases;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    private volatile static SoftReference<List<String>> excludedIDs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    private volatile static boolean hasNoExcludeList = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @return a List of zone IDs for zones that will change their GMT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * offsets in some future time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    static List<String> getExcludedZones() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        if (hasNoExcludeList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        List<String> excludeList = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        SoftReference<List<String>> cache = excludedIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        if (cache != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            excludeList = cache.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            if (excludeList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                return excludeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        byte[] buf = getZoneInfoMappings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        int index = JAVAZM_LABEL_LENGTH + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        int filesize = buf.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
          loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            while (index < filesize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                byte tag = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                int     len = ((buf[index++] & 0xFF) << 8) + (buf[index++] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                case TAG_ExcludedZones:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                        int n = (buf[index++] << 8) + (buf[index++] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                        excludeList = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                            byte m = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                            String name = new String(buf, index, m, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                            index += m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                            excludeList.add(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                    index += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            System.err.println("ZoneInfo: corrupted " + JAVAZM_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        if (excludeList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            excludedIDs = new SoftReference<List<String>>(excludeList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            hasNoExcludeList = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        return excludeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    private volatile static SoftReference<byte[]> rawOffsetIndices = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    static byte[] getRawOffsetIndices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        byte[] indices = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        SoftReference<byte[]> cache = rawOffsetIndices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        if (cache != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            indices = cache.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            if (indices != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                return indices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        byte[] buf = getZoneInfoMappings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        int index = JAVAZM_LABEL_LENGTH + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        int filesize = buf.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            while (index < filesize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                byte tag = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                int     len = ((buf[index++] & 0xFF) << 8) + (buf[index++] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                case TAG_RawOffsetIndices:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                        indices = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                            indices[i] = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                    break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    index += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        } catch (ArrayIndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            System.err.println("ZoneInfo: corrupted " + JAVAZM_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        rawOffsetIndices = new SoftReference<byte[]>(indices);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        return indices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    private volatile static SoftReference<int[]> rawOffsets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    static int[] getRawOffsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        int[] offsets = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        SoftReference<int[]> cache = rawOffsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        if (cache != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            offsets = cache.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            if (offsets != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                return offsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        byte[] buf = getZoneInfoMappings();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        int index = JAVAZM_LABEL_LENGTH + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        int filesize = buf.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            while (index < filesize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                byte tag = buf[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                int     len = ((buf[index++] & 0xFF) << 8) + (buf[index++] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                case TAG_RawOffsets:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                        int n = len/4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                        offsets = new int[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                            int val = buf[index++] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                            val = (val << 8) + (buf[index++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                            offsets[i] = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                    break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                    index += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        } catch (ArrayIndexOutOfBoundsException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            System.err.println("ZoneInfo: corrupted " + JAVAZM_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        rawOffsets = new SoftReference<int[]>(offsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        return offsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    private volatile static SoftReference<byte[]> zoneInfoMappings = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    private static byte[] getZoneInfoMappings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        byte[] data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        SoftReference<byte[]> cache = zoneInfoMappings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        if (cache != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            data = cache.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            if (data != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        data = readZoneInfoFile(JAVAZM_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        for (index = 0; index < JAVAZM_LABEL.length; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            if (data[index] != JAVAZM_LABEL[index]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                System.err.println("ZoneInfo: wrong magic number: " + JAVAZM_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        if (data[index++] > JAVAZM_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            System.err.println("ZoneInfo: incompatible version ("
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                               + data[index - 1] + "): " + JAVAZM_FILE_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        zoneInfoMappings = new SoftReference<byte[]>(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * Reads the specified file under &lt;java.home&gt;/lib/zi into a buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * @return the buffer, or null if any I/O error occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     */
4194
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1031
    private static byte[] readZoneInfoFile(final String fileName) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        byte[] buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            buffer = (byte[]) AccessController.doPrivileged(new PrivilegedExceptionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                public Object run() throws IOException {
4194
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1037
                    File file = new File(ziDir, fileName);
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1038
                    if (!file.exists() || !file.isFile()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                    }
4194
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1041
                    file = file.getCanonicalFile();
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1042
                    String path = file.getCanonicalPath();
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1043
                    byte[] buf = null;
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1044
                    if (path != null && path.startsWith(ziDir)) {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1045
                        int filesize = (int)file.length();
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1046
                        if (filesize > 0) {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1047
                            FileInputStream fis = new FileInputStream(file);
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1048
                            buf = new byte[filesize];
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1049
                            try {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1050
                                if (fis.read(buf) != filesize) {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1051
                                    throw new IOException("read error on " + fileName);
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1052
                                }
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1053
                            } finally {
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1054
                                fis.close();
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1055
                            }
eaf8321acdc1 6824265: (tz) TimeZone.getTimeZone allows probing local filesystem
okutsu
parents: 2
diff changeset
  1056
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                    return buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        } catch (PrivilegedActionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            Exception ex = e.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            if (!(ex instanceof FileNotFoundException) || JAVAZM_FILE_NAME.equals(fileName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                System.err.println("ZoneInfo: " + ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        return buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
}