Print this page
rev 5696 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o packaging changes. by Naoto Sato and Masayoshi Okutsu)

Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/text/BreakDictionary.java
          +++ new/src/share/classes/sun/util/locale/provider/BreakDictionary.java
   1    1  /*
   2      - * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
        2 + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
   3    3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4    4   *
   5    5   * This code is free software; you can redistribute it and/or modify it
   6    6   * under the terms of the GNU General Public License version 2 only, as
   7    7   * published by the Free Software Foundation.  Oracle designates this
   8    8   * particular file as subject to the "Classpath" exception as provided
   9    9   * by Oracle in the LICENSE file that accompanied this code.
  10   10   *
  11   11   * This code is distributed in the hope that it will be useful, but WITHOUT
  12   12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
↓ open down ↓ 17 lines elided ↑ open up ↑
  30   30   *
  31   31   * The original version of this source code and documentation
  32   32   * is copyrighted and owned by Taligent, Inc., a wholly-owned
  33   33   * subsidiary of IBM. These materials are provided under terms
  34   34   * of a License Agreement between Taligent and Sun. This technology
  35   35   * is protected by multiple US and International patents.
  36   36   *
  37   37   * This notice and attribution to Taligent may not be removed.
  38   38   * Taligent is a registered trademark of Taligent, Inc.
  39   39   */
  40      -package java.text;
       40 +package sun.util.locale.provider;
  41   41  
  42      -import java.io.*;
       42 +import java.io.BufferedInputStream;
       43 +import java.io.IOException;
  43   44  import java.security.AccessController;
  44   45  import java.security.PrivilegedActionException;
  45   46  import java.security.PrivilegedExceptionAction;
  46   47  import java.util.MissingResourceException;
  47   48  import sun.text.CompactByteArray;
  48   49  import sun.text.SupplementaryCharacterData;
  49   50  
  50   51  /**
  51   52   * This is the class that represents the list of known words used by
  52   53   * DictionaryBasedBreakIterator.  The conceptual data structure used
↓ open down ↓ 74 lines elided ↑ open up ↑
 127  128      /**
 128  129       * For each logical row, this index contains a constant that is added to
 129  130       * the logical column number to get the physical column number
 130  131       */
 131  132      private byte[] rowIndexShifts = null;
 132  133  
 133  134      //=========================================================================
 134  135      // deserialization
 135  136      //=========================================================================
 136  137  
 137      -    public BreakDictionary(String dictionaryName)
      138 +    BreakDictionary(String dictionaryName)
 138  139          throws IOException, MissingResourceException {
 139  140  
 140  141          readDictionaryFile(dictionaryName);
 141  142      }
 142  143  
 143  144      private void readDictionaryFile(final String dictionaryName)
 144  145          throws IOException, MissingResourceException {
 145  146  
 146  147          BufferedInputStream in;
 147  148          try {
 148  149              in = AccessController.doPrivileged(
 149  150                  new PrivilegedExceptionAction<BufferedInputStream>() {
      151 +                    @Override
 150  152                      public BufferedInputStream run() throws Exception {
 151  153                          return new BufferedInputStream(getClass().getResourceAsStream("/sun/text/resources/" + dictionaryName));
 152  154                      }
 153  155                  }
 154  156              );
 155  157          }
 156  158          catch (PrivilegedActionException e) {
 157  159              throw new InternalError(e.toString(), e);
 158  160          }
 159  161  
 160  162          byte[] buf = new byte[8];
 161  163          if (in.read(buf) != 8) {
 162  164              throw new MissingResourceException("Wrong data length",
 163  165                                                 dictionaryName, "");
 164  166          }
 165  167  
 166      -        // check vesion
 167      -        int version = BreakIterator.getInt(buf, 0);
      168 +        // check version
      169 +        int version = RuleBasedBreakIterator.getInt(buf, 0);
 168  170          if (version != supportedVersion) {
 169  171              throw new MissingResourceException("Dictionary version(" + version + ") is unsupported",
 170  172                                                             dictionaryName, "");
 171  173          }
 172  174  
 173  175          // get data size
 174      -        int len = BreakIterator.getInt(buf, 4);
      176 +        int len = RuleBasedBreakIterator.getInt(buf, 4);
 175  177          buf = new byte[len];
 176  178          if (in.read(buf) != len) {
 177  179              throw new MissingResourceException("Wrong data length",
 178  180                                                 dictionaryName, "");
 179  181          }
 180  182  
 181  183          // close the stream
 182  184          in.close();
 183  185  
 184  186          int l;
 185  187          int offset = 0;
 186  188  
 187  189          // read in the column map for BMP characteres (this is serialized in
 188  190          // its internal form: an index array followed by a data array)
 189      -        l = BreakIterator.getInt(buf, offset);
      191 +        l = RuleBasedBreakIterator.getInt(buf, offset);
 190  192          offset += 4;
 191  193          short[] temp = new short[l];
 192  194          for (int i = 0; i < l; i++, offset+=2) {
 193      -            temp[i] = BreakIterator.getShort(buf, offset);
      195 +            temp[i] = RuleBasedBreakIterator.getShort(buf, offset);
 194  196          }
 195      -        l = BreakIterator.getInt(buf, offset);
      197 +        l = RuleBasedBreakIterator.getInt(buf, offset);
 196  198          offset += 4;
 197  199          byte[] temp2 = new byte[l];
 198  200          for (int i = 0; i < l; i++, offset++) {
 199  201              temp2[i] = buf[offset];
 200  202          }
 201  203          columnMap = new CompactByteArray(temp, temp2);
 202  204  
 203  205          // read in numCols and numColGroups
 204      -        numCols = BreakIterator.getInt(buf, offset);
      206 +        numCols = RuleBasedBreakIterator.getInt(buf, offset);
 205  207          offset += 4;
 206      -        numColGroups = BreakIterator.getInt(buf, offset);
      208 +        numColGroups = RuleBasedBreakIterator.getInt(buf, offset);
 207  209          offset += 4;
 208  210  
 209  211          // read in the row-number index
 210      -        l = BreakIterator.getInt(buf, offset);
      212 +        l = RuleBasedBreakIterator.getInt(buf, offset);
 211  213          offset += 4;
 212  214          rowIndex = new short[l];
 213  215          for (int i = 0; i < l; i++, offset+=2) {
 214      -            rowIndex[i] = BreakIterator.getShort(buf, offset);
      216 +            rowIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
 215  217          }
 216  218  
 217  219          // load in the populated-cells bitmap: index first, then bitmap list
 218      -        l = BreakIterator.getInt(buf, offset);
      220 +        l = RuleBasedBreakIterator.getInt(buf, offset);
 219  221          offset += 4;
 220  222          rowIndexFlagsIndex = new short[l];
 221  223          for (int i = 0; i < l; i++, offset+=2) {
 222      -            rowIndexFlagsIndex[i] = BreakIterator.getShort(buf, offset);
      224 +            rowIndexFlagsIndex[i] = RuleBasedBreakIterator.getShort(buf, offset);
 223  225          }
 224      -        l = BreakIterator.getInt(buf, offset);
      226 +        l = RuleBasedBreakIterator.getInt(buf, offset);
 225  227          offset += 4;
 226  228          rowIndexFlags = new int[l];
 227  229          for (int i = 0; i < l; i++, offset+=4) {
 228      -            rowIndexFlags[i] = BreakIterator.getInt(buf, offset);
      230 +            rowIndexFlags[i] = RuleBasedBreakIterator.getInt(buf, offset);
 229  231          }
 230  232  
 231  233          // load in the row-shift index
 232      -        l = BreakIterator.getInt(buf, offset);
      234 +        l = RuleBasedBreakIterator.getInt(buf, offset);
 233  235          offset += 4;
 234  236          rowIndexShifts = new byte[l];
 235  237          for (int i = 0; i < l; i++, offset++) {
 236  238              rowIndexShifts[i] = buf[offset];
 237  239          }
 238  240  
 239  241          // load in the actual state table
 240      -        l = BreakIterator.getInt(buf, offset);
      242 +        l = RuleBasedBreakIterator.getInt(buf, offset);
 241  243          offset += 4;
 242  244          table = new short[l];
 243  245          for (int i = 0; i < l; i++, offset+=2) {
 244      -            table[i] = BreakIterator.getShort(buf, offset);
      246 +            table[i] = RuleBasedBreakIterator.getShort(buf, offset);
 245  247          }
 246  248  
 247  249          // finally, prepare the column map for supplementary characters
 248      -        l = BreakIterator.getInt(buf, offset);
      250 +        l = RuleBasedBreakIterator.getInt(buf, offset);
 249  251          offset += 4;
 250  252          int[] temp3 = new int[l];
 251  253          for (int i = 0; i < l; i++, offset+=4) {
 252      -            temp3[i] = BreakIterator.getInt(buf, offset);
      254 +            temp3[i] = RuleBasedBreakIterator.getInt(buf, offset);
 253  255          }
 254  256          supplementaryCharColumnMap = new SupplementaryCharacterData(temp3);
 255  257      }
 256  258  
 257  259      //=========================================================================
 258  260      // access to the words
 259  261      //=========================================================================
 260  262  
 261  263      /**
 262  264       * Uses the column map to map the character to a column number, then
↓ open down ↓ 35 lines elided ↑ open up ↑
 298  300          }
 299  301          else {
 300  302              return 0;
 301  303          }
 302  304      }
 303  305  
 304  306      /**
 305  307       * Given (logical) row and column numbers, returns true if the
 306  308       * cell in that position is populated
 307  309       */
 308      -    private final boolean cellIsPopulated(int row, int col) {
      310 +    private boolean cellIsPopulated(int row, int col) {
 309  311          // look up the entry in the bitmap index for the specified row.
 310  312          // If it's a negative number, it's the column number of the only
 311  313          // populated cell in the row
 312  314          if (rowIndexFlagsIndex[row] < 0) {
 313  315              return col == -rowIndexFlagsIndex[row];
 314  316          }
 315  317  
 316  318          // if it's a positive number, it's the offset of an entry in the bitmap
 317  319          // list.  If the table is more than 32 columns wide, the bitmap is stored
 318  320          // successive entries in the bitmap list, so we have to divide the column
↓ open down ↓ 6 lines elided ↑ open up ↑
 325  327          }
 326  328      }
 327  329  
 328  330      /**
 329  331       * Implementation of getNextState() when we know the specified cell is
 330  332       * populated.
 331  333       * @param row The PHYSICAL row number of the cell
 332  334       * @param col The PHYSICAL column number of the cell
 333  335       * @return The value stored in the cell
 334  336       */
 335      -    private final short internalAt(int row, int col) {
      337 +    private short internalAt(int row, int col) {
 336  338          // the table is a one-dimensional array, so this just does the math necessary
 337  339          // to treat it as a two-dimensional array (we don't just use a two-dimensional
 338  340          // array because two-dimensional arrays are inefficient in Java)
 339  341          return table[row * numCols + col];
 340  342      }
 341  343  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX