988 * <dt><b>0</b> or not present on stream</dt>
989 * <dd>
990 * JDK 1.1.5 or earlier.
991 * </dd>
992 * <dt><b>1</b></dt>
993 * <dd>
994 * JDK 1.1.6 or later. Writes a correct 'time' value
995 * as well as compatible values for other fields. This is a
996 * transitional format.
997 * </dd>
998 * </dl>
999 * When streaming out this class, the most recent format
1000 * and the highest allowable <code>serialVersionOnStream</code>
1001 * is written.
1002 * @serial
1003 * @since 1.1.6
1004 */
1005 private int serialVersionOnStream = currentSerialVersion;
1006
1007 // Proclaim serialization compatibility with JDK 1.1
1008 static final long serialVersionUID = -1807547505821590642L;
1009
1010 // Mask values for calendar fields
1011 @SuppressWarnings("PointlessBitwiseExpression")
1012 static final int ERA_MASK = (1 << ERA);
1013 static final int YEAR_MASK = (1 << YEAR);
1014 static final int MONTH_MASK = (1 << MONTH);
1015 static final int WEEK_OF_YEAR_MASK = (1 << WEEK_OF_YEAR);
1016 static final int WEEK_OF_MONTH_MASK = (1 << WEEK_OF_MONTH);
1017 static final int DAY_OF_MONTH_MASK = (1 << DAY_OF_MONTH);
1018 static final int DATE_MASK = DAY_OF_MONTH_MASK;
1019 static final int DAY_OF_YEAR_MASK = (1 << DAY_OF_YEAR);
1020 static final int DAY_OF_WEEK_MASK = (1 << DAY_OF_WEEK);
1021 static final int DAY_OF_WEEK_IN_MONTH_MASK = (1 << DAY_OF_WEEK_IN_MONTH);
1022 static final int AM_PM_MASK = (1 << AM_PM);
1023 static final int HOUR_MASK = (1 << HOUR);
1024 static final int HOUR_OF_DAY_MASK = (1 << HOUR_OF_DAY);
1025 static final int MINUTE_MASK = (1 << MINUTE);
1026 static final int SECOND_MASK = (1 << SECOND);
1027 static final int MILLISECOND_MASK = (1 << MILLISECOND);
3509 int weekOfYear = cal.get(WEEK_OF_YEAR);
3510 if (fields[WEEK_OF_YEAR] != weekOfYear) {
3511 fields[WEEK_OF_YEAR] = weekOfYear;
3512 }
3513 }
3514 }
3515
3516 /**
3517 * Save the state of this object to a stream (i.e., serialize it).
3518 *
3519 * Ideally, <code>Calendar</code> would only write out its state data and
3520 * the current time, and not write any field data out, such as
3521 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
3522 * and <code>isSet[]</code>. <code>nextStamp</code> also should not be part
3523 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
3524 * shipped. To be compatible with JDK 1.1, we will always have to write out
3525 * the field values and state flags. However, <code>nextStamp</code> can be
3526 * removed from the serialization stream; this will probably happen in the
3527 * near future.
3528 */
3529 private synchronized void writeObject(ObjectOutputStream stream)
3530 throws IOException
3531 {
3532 // Try to compute the time correctly, for the future (stream
3533 // version 2) in which we don't write out fields[] or isSet[].
3534 if (!isTimeSet) {
3535 try {
3536 updateTime();
3537 }
3538 catch (IllegalArgumentException e) {}
3539 }
3540
3541 // If this Calendar has a ZoneInfo, save it and set a
3542 // SimpleTimeZone equivalent (as a single DST schedule) for
3543 // backward compatibility.
3544 TimeZone savedZone = null;
3545 if (zone instanceof ZoneInfo) {
3546 SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
3547 if (stz == null) {
3548 stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
3563 }
3564 }
3565
3566 private static class CalendarAccessControlContext {
3567 private static final AccessControlContext INSTANCE;
3568 static {
3569 RuntimePermission perm = new RuntimePermission("accessClassInPackage.sun.util.calendar");
3570 PermissionCollection perms = perm.newPermissionCollection();
3571 perms.add(perm);
3572 INSTANCE = new AccessControlContext(new ProtectionDomain[] {
3573 new ProtectionDomain(null, perms)
3574 });
3575 }
3576 private CalendarAccessControlContext() {
3577 }
3578 }
3579
3580 /**
3581 * Reconstitutes this object from a stream (i.e., deserialize it).
3582 */
3583 private void readObject(ObjectInputStream stream)
3584 throws IOException, ClassNotFoundException
3585 {
3586 final ObjectInputStream input = stream;
3587 input.defaultReadObject();
3588
3589 stamp = new int[FIELD_COUNT];
3590
3591 // Starting with version 2 (not implemented yet), we expect that
3592 // fields[], isSet[], isTimeSet, and areFieldsSet may not be
3593 // streamed out anymore. We expect 'time' to be correct.
3594 if (serialVersionOnStream >= 2)
3595 {
3596 isTimeSet = true;
3597 if (fields == null) {
3598 fields = new int[FIELD_COUNT];
3599 }
3600 if (isSet == null) {
3601 isSet = new boolean[FIELD_COUNT];
3602 }
|
988 * <dt><b>0</b> or not present on stream</dt>
989 * <dd>
990 * JDK 1.1.5 or earlier.
991 * </dd>
992 * <dt><b>1</b></dt>
993 * <dd>
994 * JDK 1.1.6 or later. Writes a correct 'time' value
995 * as well as compatible values for other fields. This is a
996 * transitional format.
997 * </dd>
998 * </dl>
999 * When streaming out this class, the most recent format
1000 * and the highest allowable <code>serialVersionOnStream</code>
1001 * is written.
1002 * @serial
1003 * @since 1.1.6
1004 */
1005 private int serialVersionOnStream = currentSerialVersion;
1006
1007 // Proclaim serialization compatibility with JDK 1.1
1008 @java.io.Serial
1009 static final long serialVersionUID = -1807547505821590642L;
1010
1011 // Mask values for calendar fields
1012 @SuppressWarnings("PointlessBitwiseExpression")
1013 static final int ERA_MASK = (1 << ERA);
1014 static final int YEAR_MASK = (1 << YEAR);
1015 static final int MONTH_MASK = (1 << MONTH);
1016 static final int WEEK_OF_YEAR_MASK = (1 << WEEK_OF_YEAR);
1017 static final int WEEK_OF_MONTH_MASK = (1 << WEEK_OF_MONTH);
1018 static final int DAY_OF_MONTH_MASK = (1 << DAY_OF_MONTH);
1019 static final int DATE_MASK = DAY_OF_MONTH_MASK;
1020 static final int DAY_OF_YEAR_MASK = (1 << DAY_OF_YEAR);
1021 static final int DAY_OF_WEEK_MASK = (1 << DAY_OF_WEEK);
1022 static final int DAY_OF_WEEK_IN_MONTH_MASK = (1 << DAY_OF_WEEK_IN_MONTH);
1023 static final int AM_PM_MASK = (1 << AM_PM);
1024 static final int HOUR_MASK = (1 << HOUR);
1025 static final int HOUR_OF_DAY_MASK = (1 << HOUR_OF_DAY);
1026 static final int MINUTE_MASK = (1 << MINUTE);
1027 static final int SECOND_MASK = (1 << SECOND);
1028 static final int MILLISECOND_MASK = (1 << MILLISECOND);
3510 int weekOfYear = cal.get(WEEK_OF_YEAR);
3511 if (fields[WEEK_OF_YEAR] != weekOfYear) {
3512 fields[WEEK_OF_YEAR] = weekOfYear;
3513 }
3514 }
3515 }
3516
3517 /**
3518 * Save the state of this object to a stream (i.e., serialize it).
3519 *
3520 * Ideally, <code>Calendar</code> would only write out its state data and
3521 * the current time, and not write any field data out, such as
3522 * <code>fields[]</code>, <code>isTimeSet</code>, <code>areFieldsSet</code>,
3523 * and <code>isSet[]</code>. <code>nextStamp</code> also should not be part
3524 * of the persistent state. Unfortunately, this didn't happen before JDK 1.1
3525 * shipped. To be compatible with JDK 1.1, we will always have to write out
3526 * the field values and state flags. However, <code>nextStamp</code> can be
3527 * removed from the serialization stream; this will probably happen in the
3528 * near future.
3529 */
3530 @java.io.Serial
3531 private synchronized void writeObject(ObjectOutputStream stream)
3532 throws IOException
3533 {
3534 // Try to compute the time correctly, for the future (stream
3535 // version 2) in which we don't write out fields[] or isSet[].
3536 if (!isTimeSet) {
3537 try {
3538 updateTime();
3539 }
3540 catch (IllegalArgumentException e) {}
3541 }
3542
3543 // If this Calendar has a ZoneInfo, save it and set a
3544 // SimpleTimeZone equivalent (as a single DST schedule) for
3545 // backward compatibility.
3546 TimeZone savedZone = null;
3547 if (zone instanceof ZoneInfo) {
3548 SimpleTimeZone stz = ((ZoneInfo)zone).getLastRuleInstance();
3549 if (stz == null) {
3550 stz = new SimpleTimeZone(zone.getRawOffset(), zone.getID());
3565 }
3566 }
3567
3568 private static class CalendarAccessControlContext {
3569 private static final AccessControlContext INSTANCE;
3570 static {
3571 RuntimePermission perm = new RuntimePermission("accessClassInPackage.sun.util.calendar");
3572 PermissionCollection perms = perm.newPermissionCollection();
3573 perms.add(perm);
3574 INSTANCE = new AccessControlContext(new ProtectionDomain[] {
3575 new ProtectionDomain(null, perms)
3576 });
3577 }
3578 private CalendarAccessControlContext() {
3579 }
3580 }
3581
3582 /**
3583 * Reconstitutes this object from a stream (i.e., deserialize it).
3584 */
3585 @java.io.Serial
3586 private void readObject(ObjectInputStream stream)
3587 throws IOException, ClassNotFoundException
3588 {
3589 final ObjectInputStream input = stream;
3590 input.defaultReadObject();
3591
3592 stamp = new int[FIELD_COUNT];
3593
3594 // Starting with version 2 (not implemented yet), we expect that
3595 // fields[], isSet[], isTimeSet, and areFieldsSet may not be
3596 // streamed out anymore. We expect 'time' to be correct.
3597 if (serialVersionOnStream >= 2)
3598 {
3599 isTimeSet = true;
3600 if (fields == null) {
3601 fields = new int[FIELD_COUNT];
3602 }
3603 if (isSet == null) {
3604 isSet = new boolean[FIELD_COUNT];
3605 }
|