3131import net .time4j .tz .ZoneProvider ;
3232import net .time4j .tz .spi .ZoneNameProviderSPI ;
3333
34+ import java .io .ByteArrayInputStream ;
35+ import java .io .DataInputStream ;
3436import java .io .File ;
3537import java .io .FileNotFoundException ;
3638import java .io .IOException ;
@@ -79,7 +81,7 @@ public class TimezoneRepositoryProviderSPI
7981
8082 private final String version ;
8183 private final String location ;
82- private final Map <String , TransitionHistory > data ;
84+ private final Map <String , byte [] > data ;
8385 private final Map <String , String > aliases ;
8486 private final PlainDate expires ;
8587 private final Map <GregorianDate , Integer > leapsecs ;
@@ -91,16 +93,14 @@ public TimezoneRepositoryProviderSPI() {
9193
9294 URL url = null ;
9395 InputStream is = null ;
94- ObjectInputStream ois = null ;
96+ DataInputStream dis = null ;
9597
9698 String tmpVersion = "" ;
9799 String tmpLocation = "" ;
98100 PlainDate tmpExpires = PlainDate .axis ().getMinimum ();
99101
100- Map <String , TransitionHistory > tmpData =
101- new HashMap <String , TransitionHistory >();
102- Map <String , String > tmpAliases =
103- new HashMap <String , String >();
102+ Map <String , byte []> tmpData = new HashMap <String , byte []>();
103+ Map <String , String > tmpAliases = new HashMap <String , String >();
104104
105105 boolean noLeaps =
106106 (System .getProperty ("net.time4j.scale.leapseconds.path" ) != null );
@@ -144,52 +144,59 @@ public TimezoneRepositoryProviderSPI() {
144144
145145 if (url != null ) {
146146 is = url .openStream ();
147- ois = new ObjectInputStream (is );
147+ dis = new DataInputStream (is );
148148 tmpLocation = url .toString ();
149- checkMagicLabel (ois , tmpLocation );
150- String v = ois .readUTF ();
151- int sizeOfZones = ois .readInt ();
149+ checkMagicLabel (dis , tmpLocation );
150+ String v = dis .readUTF ();
151+ int sizeOfZones = dis .readInt ();
152152
153153 List <String > zones = new ArrayList <String >();
154154
155155 for (int i = 0 ; i < sizeOfZones ; i ++) {
156- String zoneID = ois .readUTF ();
157- TransitionHistory th = (TransitionHistory ) ois .readObject ();
156+ String zoneID = dis .readUTF ();
157+ int dataLen = dis .readInt ();
158+ byte [] dataBuf = new byte [dataLen ];
159+ int dataRead = dis .read (dataBuf , 0 , dataLen );
160+ if (dataLen > dataRead ) {
161+ byte [] tmpBuf = new byte [dataRead ];
162+ System .arraycopy (dataBuf , 0 , tmpBuf , 0 , dataRead );
163+ dataBuf = tmpBuf ;
164+ }
158165 zones .add (zoneID );
159- tmpData .put (zoneID , th );
166+ tmpData .put (zoneID , dataBuf );
160167 }
161168
162- int sizeOfLinks = ois .readShort ();
169+ int sizeOfLinks = dis .readShort ();
163170
164171 for (int i = 0 ; i < sizeOfLinks ; i ++) {
165- String alias = ois .readUTF ();
166- String id = zones .get (ois .readShort ());
172+ String alias = dis .readUTF ();
173+ String id = zones .get (dis .readShort ());
167174 tmpAliases .put (alias , id );
168175 }
169176
170177 if (!noLeaps ) {
171- int sizeOfLeaps = ois .readShort ();
178+ int sizeOfLeaps = dis .readShort ();
172179
173180 for (int i = 0 ; i < sizeOfLeaps ; i ++) {
174- int year = ois .readShort ();
175- int month = ois .readByte ();
176- int dom = ois .readByte ();
177- int shift = ois .readByte ();
181+ int year = dis .readShort ();
182+ int month = dis .readByte ();
183+ int dom = dis .readByte ();
184+ int shift = dis .readByte ();
178185
179186 this .leapsecs .put (
180187 PlainDate .of (year , month , dom ),
181188 Integer .valueOf (shift ));
182189 }
183190
184- tmpExpires = (PlainDate ) ois .readObject ();
191+ int year = dis .readShort ();
192+ int month = dis .readByte ();
193+ int dom = dis .readByte ();
194+ tmpExpires = PlainDate .of (year , month , dom );
185195 }
186196
187197 tmpVersion = v ; // here all is okay, so let us set the version
188198 }
189199
190- } catch (ClassNotFoundException cnfe ) {
191- System .out .println (
192- "Note: TZ-repository corrupt. => " + cnfe .getMessage ());
193200 } catch (IOException ioe ) {
194201 System .out .println (
195202 "Note: TZ-repository not available. => " + ioe .getMessage ());
@@ -257,7 +264,17 @@ public Map<String, String> getAliases() {
257264 @ Override
258265 public TransitionHistory load (String zoneID ) {
259266
260- return this .data .get (zoneID );
267+ try {
268+ byte [] bytes = this .data .get (zoneID );
269+ ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream (bytes ));
270+ return (TransitionHistory ) ois .readObject ();
271+ } catch (IOException e ) {
272+ e .printStackTrace ();
273+ } catch (ClassNotFoundException e ) {
274+ e .printStackTrace ();
275+ }
276+
277+ return null ;
261278
262279 }
263280
@@ -329,16 +346,16 @@ public String toString() {
329346 }
330347
331348 private static void checkMagicLabel (
332- ObjectInputStream ois ,
349+ DataInputStream dis ,
333350 String location
334351 ) throws IOException {
335352
336- int b1 = ois .readByte ();
337- int b2 = ois .readByte ();
338- int b3 = ois .readByte ();
339- int b4 = ois .readByte ();
340- int b5 = ois .readByte ();
341- int b6 = ois .readByte ();
353+ int b1 = dis .readByte ();
354+ int b2 = dis .readByte ();
355+ int b3 = dis .readByte ();
356+ int b4 = dis .readByte ();
357+ int b5 = dis .readByte ();
358+ int b6 = dis .readByte ();
342359
343360 if (
344361 (b1 != 't' )
0 commit comments