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