< prev index next >

src/java.base/share/classes/java/text/SimpleDateFormat.java

Print this page




 424  * <h3><a id="synchronization">Synchronization</a></h3>
 425  *
 426  * <p>
 427  * Date formats are not synchronized.
 428  * It is recommended to create separate format instances for each thread.
 429  * If multiple threads access a format concurrently, it must be synchronized
 430  * externally.
 431  *
 432  * @see          <a href="http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html">Java Tutorial</a>
 433  * @see          java.util.Calendar
 434  * @see          java.util.TimeZone
 435  * @see          DateFormat
 436  * @see          DateFormatSymbols
 437  * @author       Mark Davis, Chen-Lieh Huang, Alan Liu
 438  * @since 1.1
 439  */
 440 public class SimpleDateFormat extends DateFormat {
 441 
 442     // the official serial version ID which says cryptically
 443     // which version we're compatible with

 444     static final long serialVersionUID = 4774881970558875024L;
 445 
 446     // the internal serial version which says which version was written
 447     // - 0 (default) for version up to JDK 1.1.3
 448     // - 1 for version from JDK 1.1.4, which includes a new field
 449     static final int currentSerialVersion = 1;
 450 
 451     /**
 452      * The version of the serialized data on the stream.  Possible values:
 453      * <ul>
 454      * <li><b>0</b> or not present on stream: JDK 1.1.3.  This version
 455      * has no <code>defaultCenturyStart</code> on stream.
 456      * <li><b>1</b> JDK 1.1.4 or later.  This version adds
 457      * <code>defaultCenturyStart</code>.
 458      * </ul>
 459      * When streaming out this class, the most recent format
 460      * and the highest allowable <code>serialVersionOnStream</code>
 461      * is written.
 462      * @serial
 463      * @since 1.1.4


2454      * the month name pattern 'M' is context dependent.
2455      */
2456     private Map<String, Integer> getDisplayContextNamesMap(int field, Locale locale) {
2457         Map<String, Integer> map = calendar.getDisplayNames(field,
2458             forceStandaloneForm ? Calendar.SHORT_STANDALONE : Calendar.SHORT_FORMAT, locale);
2459         // Get the LONG style
2460         Map<String, Integer> m = calendar.getDisplayNames(field,
2461             forceStandaloneForm ? Calendar.LONG_STANDALONE : Calendar.LONG_FORMAT, locale);
2462         if (m != null) {
2463             map.putAll(m);
2464         }
2465         return map;
2466     }
2467 
2468     /**
2469      * After reading an object from the input stream, the format
2470      * pattern in the object is verified.
2471      *
2472      * @exception InvalidObjectException if the pattern is invalid
2473      */

2474     private void readObject(ObjectInputStream stream)
2475                          throws IOException, ClassNotFoundException {
2476         stream.defaultReadObject();
2477 
2478         try {
2479             compiledPattern = compile(pattern);
2480         } catch (Exception e) {
2481             throw new InvalidObjectException("invalid pattern");
2482         }
2483 
2484         if (serialVersionOnStream < 1) {
2485             // didn't have defaultCenturyStart field
2486             initializeDefaultCentury();
2487         }
2488         else {
2489             // fill in dependent transient field
2490             parseAmbiguousDatesAsAfter(defaultCenturyStart);
2491         }
2492         serialVersionOnStream = currentSerialVersion;
2493 




 424  * <h3><a id="synchronization">Synchronization</a></h3>
 425  *
 426  * <p>
 427  * Date formats are not synchronized.
 428  * It is recommended to create separate format instances for each thread.
 429  * If multiple threads access a format concurrently, it must be synchronized
 430  * externally.
 431  *
 432  * @see          <a href="http://docs.oracle.com/javase/tutorial/i18n/format/simpleDateFormat.html">Java Tutorial</a>
 433  * @see          java.util.Calendar
 434  * @see          java.util.TimeZone
 435  * @see          DateFormat
 436  * @see          DateFormatSymbols
 437  * @author       Mark Davis, Chen-Lieh Huang, Alan Liu
 438  * @since 1.1
 439  */
 440 public class SimpleDateFormat extends DateFormat {
 441 
 442     // the official serial version ID which says cryptically
 443     // which version we're compatible with
 444     @java.io.Serial
 445     static final long serialVersionUID = 4774881970558875024L;
 446 
 447     // the internal serial version which says which version was written
 448     // - 0 (default) for version up to JDK 1.1.3
 449     // - 1 for version from JDK 1.1.4, which includes a new field
 450     static final int currentSerialVersion = 1;
 451 
 452     /**
 453      * The version of the serialized data on the stream.  Possible values:
 454      * <ul>
 455      * <li><b>0</b> or not present on stream: JDK 1.1.3.  This version
 456      * has no <code>defaultCenturyStart</code> on stream.
 457      * <li><b>1</b> JDK 1.1.4 or later.  This version adds
 458      * <code>defaultCenturyStart</code>.
 459      * </ul>
 460      * When streaming out this class, the most recent format
 461      * and the highest allowable <code>serialVersionOnStream</code>
 462      * is written.
 463      * @serial
 464      * @since 1.1.4


2455      * the month name pattern 'M' is context dependent.
2456      */
2457     private Map<String, Integer> getDisplayContextNamesMap(int field, Locale locale) {
2458         Map<String, Integer> map = calendar.getDisplayNames(field,
2459             forceStandaloneForm ? Calendar.SHORT_STANDALONE : Calendar.SHORT_FORMAT, locale);
2460         // Get the LONG style
2461         Map<String, Integer> m = calendar.getDisplayNames(field,
2462             forceStandaloneForm ? Calendar.LONG_STANDALONE : Calendar.LONG_FORMAT, locale);
2463         if (m != null) {
2464             map.putAll(m);
2465         }
2466         return map;
2467     }
2468 
2469     /**
2470      * After reading an object from the input stream, the format
2471      * pattern in the object is verified.
2472      *
2473      * @exception InvalidObjectException if the pattern is invalid
2474      */
2475     @java.io.Serial
2476     private void readObject(ObjectInputStream stream)
2477                          throws IOException, ClassNotFoundException {
2478         stream.defaultReadObject();
2479 
2480         try {
2481             compiledPattern = compile(pattern);
2482         } catch (Exception e) {
2483             throw new InvalidObjectException("invalid pattern");
2484         }
2485 
2486         if (serialVersionOnStream < 1) {
2487             // didn't have defaultCenturyStart field
2488             initializeDefaultCentury();
2489         }
2490         else {
2491             // fill in dependent transient field
2492             parseAmbiguousDatesAsAfter(defaultCenturyStart);
2493         }
2494         serialVersionOnStream = currentSerialVersion;
2495 


< prev index next >