< prev index next >

src/java.base/share/classes/java/time/zone/ZoneOffsetTransitionRule.java

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


 239     //-----------------------------------------------------------------------
 240     /**
 241      * Defend against malicious streams.
 242      *
 243      * @param s the stream to read
 244      * @throws InvalidObjectException always
 245      */
 246     private void readObject(ObjectInputStream s) throws InvalidObjectException {
 247         throw new InvalidObjectException("Deserialization via serialization delegate");
 248     }
 249 
 250     /**
 251      * Writes the object using a
 252      * <a href="{@docRoot}/serialized-form.html#java.time.zone.Ser">dedicated serialized form</a>.
 253      * @serialData
 254      * Refer to the serialized form of
 255      * <a href="{@docRoot}/serialized-form.html#java.time.zone.ZoneRules">ZoneRules.writeReplace</a>
 256      * for the encoding of epoch seconds and offsets.
 257      * <pre style="font-size:1.0em">{@code
 258      *
 259      *      out.writeByte(3);                // identifies a ZoneOffsetTransition
 260      *      final int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
 261      *      final int stdOffset = standardOffset.getTotalSeconds();
 262      *      final int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
 263      *      final int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
 264      *      final int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
 265      *      final int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
 266      *      final int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
 267      *      final int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
 268      *      final int dowByte = (dow == null ? 0 : dow.getValue());
 269      *      int b = (month.getValue() << 28) +          // 4 bits
 270      *              ((dom + 32) << 22) +                // 6 bits
 271      *              (dowByte << 19) +                   // 3 bits
 272      *              (timeByte << 14) +                  // 5 bits
 273      *              (timeDefinition.ordinal() << 12) +  // 2 bits
 274      *              (stdOffsetByte << 4) +              // 8 bits
 275      *              (beforeByte << 2) +                 // 2 bits
 276      *              afterByte;                          // 2 bits
 277      *      out.writeInt(b);
 278      *      if (timeByte == 31) {
 279      *          out.writeInt(timeSecs);


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


 239     //-----------------------------------------------------------------------
 240     /**
 241      * Defend against malicious streams.
 242      *
 243      * @param s the stream to read
 244      * @throws InvalidObjectException always
 245      */
 246     private void readObject(ObjectInputStream s) throws InvalidObjectException {
 247         throw new InvalidObjectException("Deserialization via serialization delegate");
 248     }
 249 
 250     /**
 251      * Writes the object using a
 252      * <a href="{@docRoot}/serialized-form.html#java.time.zone.Ser">dedicated serialized form</a>.
 253      * @serialData
 254      * Refer to the serialized form of
 255      * <a href="{@docRoot}/serialized-form.html#java.time.zone.ZoneRules">ZoneRules.writeReplace</a>
 256      * for the encoding of epoch seconds and offsets.
 257      * <pre style="font-size:1.0em">{@code
 258      *
 259      *      out.writeByte(3);                // identifies a ZoneOffsetTransitionRule
 260      *      final int timeSecs = (timeEndOfDay ? 86400 : time.toSecondOfDay());
 261      *      final int stdOffset = standardOffset.getTotalSeconds();
 262      *      final int beforeDiff = offsetBefore.getTotalSeconds() - stdOffset;
 263      *      final int afterDiff = offsetAfter.getTotalSeconds() - stdOffset;
 264      *      final int timeByte = (timeSecs % 3600 == 0 ? (timeEndOfDay ? 24 : time.getHour()) : 31);
 265      *      final int stdOffsetByte = (stdOffset % 900 == 0 ? stdOffset / 900 + 128 : 255);
 266      *      final int beforeByte = (beforeDiff == 0 || beforeDiff == 1800 || beforeDiff == 3600 ? beforeDiff / 1800 : 3);
 267      *      final int afterByte = (afterDiff == 0 || afterDiff == 1800 || afterDiff == 3600 ? afterDiff / 1800 : 3);
 268      *      final int dowByte = (dow == null ? 0 : dow.getValue());
 269      *      int b = (month.getValue() << 28) +          // 4 bits
 270      *              ((dom + 32) << 22) +                // 6 bits
 271      *              (dowByte << 19) +                   // 3 bits
 272      *              (timeByte << 14) +                  // 5 bits
 273      *              (timeDefinition.ordinal() << 12) +  // 2 bits
 274      *              (stdOffsetByte << 4) +              // 8 bits
 275      *              (beforeByte << 2) +                 // 2 bits
 276      *              afterByte;                          // 2 bits
 277      *      out.writeInt(b);
 278      *      if (timeByte == 31) {
 279      *          out.writeInt(timeSecs);


< prev index next >