test/sun/text/resources/LocaleDataTest.java

Print this page




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*
  24  * @test
  25  * @bug 4052473 4052679 4055602 4066550 4067619 4068012 4068073 4070174 4070452
  26  *      4070178 4070450 4070695 4070725 4070795 4071003 4071183 4071782 4072013
  27  *      4072388 4072773 4075404 4084356 4087238 4092361 4094033 4094371 4098518
  28  *      4099810 4103218 4103220 4103861 4112136 4113638 4113654 4117054 4122468
  29  *      4122840 4139860 4156708 4175306 4215747 4209960 4290801 4900884 4942982
  30  *      4518811 4945388 4936845 4794068 4461740 4965260 4984277 4826794 5032580
  31  *      5102005 5074431 6182685 6208712 6277020 6245766 6351682 6386647 6379382
  32  *      6414459 6455680 6498742 6558863 6488119 6547501 6497154 6558856 6481177
  33  *      6379214 6485516 6486607 4225362 4494727 6533691 6531591 6531593 6570259
  34  *      6509039 6609737 6610748 6645271 6507067 6873931 6450945 6645268 6646611
  35  *      6645405 6650730 6910489 6573250 6870908 6585666 6716626 6914413 6916787
  36  *      6919624 6998391 7019267 7020960 7025837 7020583 7036905 7066203 7101495
  37  *      7003124 7085757 7028073 7171028 7189611 8000983 7195759 8004489 8006509
  38  *      7114053 7074882 7040556 8013836 8021121 6192407 6931564 8027695 8017142
  39  *      8037343 8055222 8042126 8074791 8075173
  40  * @summary Verify locale data


  41  *
  42  */
  43 
  44 /*
  45  *
  46  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  47  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  48  *
  49  * Portions copyright (c) 2007 Sun Microsystems, Inc.
  50  * All Rights Reserved.
  51  *
  52  * The original version of this source code and documentation
  53  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  54  * subsidiary of IBM. These materials are provided under terms
  55  * of a License Agreement between Taligent and Sun. This technology
  56  * is protected by multiple US and International patents.
  57  *
  58  * This notice and attribution to Taligent may not be removed.
  59  * Taligent is a registered trademark of Taligent, Inc.
  60  *


  82  *    slashes.  The file is in ISO 8859-1 encoding, with control characters and
  83  *    non-ASCII characters denoted with backslash-u escape sequences.  The program also allows
  84  *    blank lines and comment lines to be interspersed with the data.  Comment lines
  85  *    begin with '#'.
  86  *
  87  *    A data file for this test would look something like this:<pre>
  88  *        FormatData//MonthNames/0=January
  89  *        FormatData//MonthNames/1=February
  90  *        LocaleNames//US=United States
  91  *        LocaleNames//FR=France
  92  *        FormatData/fr_FR/MonthNames/0=janvier
  93  *        FormatData/fr_FR/MonthNames/1=f\u00e9vrier
  94  *        LocaleNames/fr_FR/US=\u00c9tats-Unis
  95  *        LocaleNames/fr_FR/FR=France</pre>
  96  *
  97  *    You can use language tag with '-' in locale field like this:<pre>
  98  *        LocaleNames/sr-Latn/SR=Surinam
  99  *        FormatData/sr-Latn-BA/DayNames/2=utorak</pre>
 100  *
 101  *    The command-line syntax of this test is
 102  *        <tt>java LocaleDataTest [-w] [{ -s | <filename> }]</tt>
 103  *
 104  *    This program always sends its results to standard output.   If -w is not specified,
 105  *    this program prints out only the differences between the data file and the actual
 106  *    resource data.  If -w is specified, the program prints out every entry, comment,
 107  *    and blank line from the data file.  Where there is a difference between the data
 108  *    file and the resource data, the data is the data from the resources.  This feature
 109  *    can be used to quickly generate a new data file.
 110  *
 111  *    The user can specify an optional filename or -s.  If the user specifies a filename,
 112  *    the program uses that file as the data file.  If the user specifies -s, the program
 113  *    reads its input from standard input rather than from a file.  If the user specifies
 114  *    neither, the program reads its input from a file called LocaleData in the same
 115  *    directory the program itself resides in.
 116  *
 117  *    The -nothrow option prevents the program from throwing an exception when it
 118  *    gets an error.  -w implies -nothrow.
 119  *



 120  *    Other command-line options can be specified, but are ignored.
 121  *
 122  *    It's important to note what this test will NOT test.  Certain changes to the locale
 123  *    data are meant to have certain effects on the internationalization frameworks.  For
 124  *    instance, we could ensure round-trip formatting/parsing integrity for the full
 125  *    date/time format of SimpleDateFormat by making sure that the full date and time
 126  *    patterns include sufficient data.  The test of this is not whether changes were
 127  *    made to the locale data; it's whether using this data gives round-trip integrity.
 128  *    Likewise, changing the currency patterns to use \u00a4 instead of local currency
 129  *    symbols isn't something that can be tested by this test; instead, you want to
 130  *    actually format currency values and make sure the proper currency symbol was used.
 131  *
 132  *    This test by itself doesn't do an exhaustive comparison of locale data.  It is
 133  *    possible to do this manually, however:  Use the GenerateKeyList tool to produce
 134  *    a complete list of keys for the two versions of the locales you want to compare,
 135  *    and then diff them.  This will flag additions and deletions.  Generate a data file
 136  *    for the base version of the data using the -w option and the output from
 137  *    GenerateKeyList, and then use the resultant file as the data file when you run
 138  *    this test against the new version of the data.
 139  */
 140 
 141 import java.io.*;
 142 import java.text.*;
 143 import java.util.Locale;
 144 import java.util.ResourceBundle;
 145 import java.util.ResourceBundle.Control;
 146 import java.util.MissingResourceException;
 147 
 148 public class LocaleDataTest
 149 {
 150     static final String TEXT_RESOURCES_PACKAGE ="sun.text.resources";
 151     static final String UTIL_RESOURCES_PACKAGE ="sun.util.resources";


 152 
 153     public static void main(String[] args) throws Exception {
 154 
 155         // set up our flags and our input and output streams based on the
 156         // command-line arguments (exceptions generated here will propagate out
 157         // to the environment)
 158         BufferedReader in = null;
 159         PrintWriter out = null;
 160         boolean writeNewFile = false;
 161         boolean doThrow = true;
 162 
 163         for (int i = 0; i < args.length; i++) {
 164             if (args[i].equals("-w")) {
 165                 writeNewFile = true;
 166                 doThrow = false;
 167             }
 168 
 169             else if (args[i].equals("-nothrow"))
 170                 doThrow = false;
 171 




 172             else if (args[i].equals("-s") && in == null)
 173                 in = new BufferedReader(new EscapeReader(new InputStreamReader(System.in,
 174                                 "ISO8859_1")));
 175             else if (!args[i].startsWith("-") && in == null)
 176                 in = new BufferedReader(new EscapeReader(new InputStreamReader(new
 177                                 FileInputStream(args[i]), "ISO8859_1")));
 178         }
 179         if (in == null) {
 180             File localeData = new File(System.getProperty("test.src", "."), "LocaleData");
 181             in = new BufferedReader(new EscapeReader(new InputStreamReader(new
 182                             FileInputStream(localeData), "ISO8859_1")));
 183         }
 184         out = new PrintWriter(new EscapeWriter(new OutputStreamWriter(System.out,
 185                         "ISO8859_1")), true);
 186 
 187         // perform the actual test
 188         int errorCount = doTest(in, out, writeNewFile);
 189 
 190         // write out the error count, and throw an exception out into the environment
 191         // if there were any errors
 192         if (errorCount != 0) {
 193             if (!writeNewFile)
 194                 out.println("Test failed.  " + errorCount + " errors.");
 195             if (doThrow)
 196                 throw new Exception("Test failed.  " + errorCount + " errors.");
 197         }
 198         else if (!writeNewFile)
 199             out.println("Test passed.");
 200 


 274             resTag = resTag.substring(0, resTag.length() - 1);
 275             oldIndex = index;
 276             index = key.indexOf("/", oldIndex + 1);
 277             if (index == -1) index = key.length();
 278             resTag += key.substring(oldIndex, index);
 279         }
 280 
 281         if (index < key.length() - 1)
 282             qualifier = key.substring(index + 1);
 283         else
 284             qualifier = "";
 285 
 286         String retrievedValue = null;
 287         Object resource = null;
 288         try {
 289             String fullName = null;
 290             if (rbName.equals("CalendarData")
 291                     || rbName.equals("CurrencyNames")
 292                     || rbName.equals("LocaleNames")
 293                     || rbName.equals("TimeZoneNames")) {
 294                 fullName = UTIL_RESOURCES_PACKAGE + "." + rbName;
 295             } else {
 296                 fullName = TEXT_RESOURCES_PACKAGE + "." + rbName;
 297             }
 298             Locale locale;
 299             if (use_tag) {
 300                 locale = Locale.forLanguageTag(localeName);
 301             } else {
 302                 locale = new Locale(language, country, variant);
 303             }
 304             ResourceBundle bundle = ResourceBundle.getBundle(fullName,
 305                                                              locale,
 306                                                              JRELocaleResourceBundleControl.INSTANCE);
 307             resource = bundle.getObject(resTag);
 308         }
 309         catch (MissingResourceException e) {
 310         }
 311 
 312         if (resource != null) {
 313             if (resource instanceof String) {
 314                 retrievedValue = (String)resource;
 315             }
 316             else if (resource instanceof String[]) {


 355             if (writeNewFile)
 356                 out.println(key + "=" + expectedValue);
 357         }
 358         return true;
 359     }
 360 
 361     private static class JRELocaleResourceBundleControl extends ResourceBundle.Control {
 362         static final JRELocaleResourceBundleControl INSTANCE = new JRELocaleResourceBundleControl();
 363 
 364         private JRELocaleResourceBundleControl() {
 365         }
 366 
 367         @Override
 368         public Locale getFallbackLocale(String baseName, Locale locale) {
 369             if (baseName == null || locale == null) {
 370                 throw new NullPointerException();
 371             }
 372             return null;
 373         }
 374 
 375         private static final String CLDR      = ".cldr";
 376 
 377         /**
 378          * Changes baseName to its per-language package name and
 379          * calls the super class implementation. For example,
 380          * if the baseName is "sun.text.resources.FormatData" and locale is ja_JP,
 381          * the baseName is changed to "sun.text.resources.ja.FormatData". If
 382          * baseName contains "cldr", such as "sun.text.resources.cldr.FormatData",
 383          * the name is changed to "sun.text.resources.cldr.jp.FormatData".
 384          */
 385         @Override
 386         public String toBundleName(String baseName, Locale locale) {
 387             String newBaseName = baseName;
 388             String lang = locale.getLanguage();

 389             if (lang.length() > 0) {
 390                 if (baseName.startsWith(UTIL_RESOURCES_PACKAGE)
 391                     || baseName.startsWith(TEXT_RESOURCES_PACKAGE)) {
 392                     // Assume the lengths are the same.
 393                     if (UTIL_RESOURCES_PACKAGE.length()
 394                         != TEXT_RESOURCES_PACKAGE.length()) {
 395                         throw new InternalError("The resources package names have different lengths.");
 396                     }
 397                     int index = TEXT_RESOURCES_PACKAGE.length();
 398                     if (baseName.indexOf(CLDR, index) > 0) {
 399                         index += CLDR.length();
 400                     }
 401                     newBaseName = baseName.substring(0, index + 1) + lang
 402                                       + baseName.substring(index);
 403                 }
 404             }
 405             return super.toBundleName(newBaseName, locale);
 406         }
 407     }
 408 }
 409 
 410 class EscapeReader extends FilterReader {
 411     public EscapeReader(Reader in) {
 412         super(in);
 413     }
 414 
 415     public int read() throws IOException {
 416         if (buffer != null) {
 417             String b = buffer.toString();
 418             int result = b.charAt(0);
 419             if (b.length() > 1)
 420                 buffer = new StringBuffer(b.substring(1));
 421             else




  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*
  24  * @test
  25  * @bug 4052473 4052679 4055602 4066550 4067619 4068012 4068073 4070174 4070452
  26  *      4070178 4070450 4070695 4070725 4070795 4071003 4071183 4071782 4072013
  27  *      4072388 4072773 4075404 4084356 4087238 4092361 4094033 4094371 4098518
  28  *      4099810 4103218 4103220 4103861 4112136 4113638 4113654 4117054 4122468
  29  *      4122840 4139860 4156708 4175306 4215747 4209960 4290801 4900884 4942982
  30  *      4518811 4945388 4936845 4794068 4461740 4965260 4984277 4826794 5032580
  31  *      5102005 5074431 6182685 6208712 6277020 6245766 6351682 6386647 6379382
  32  *      6414459 6455680 6498742 6558863 6488119 6547501 6497154 6558856 6481177
  33  *      6379214 6485516 6486607 4225362 4494727 6533691 6531591 6531593 6570259
  34  *      6509039 6609737 6610748 6645271 6507067 6873931 6450945 6645268 6646611
  35  *      6645405 6650730 6910489 6573250 6870908 6585666 6716626 6914413 6916787
  36  *      6919624 6998391 7019267 7020960 7025837 7020583 7036905 7066203 7101495
  37  *      7003124 7085757 7028073 7171028 7189611 8000983 7195759 8004489 8006509
  38  *      7114053 7074882 7040556 8008577 8013836 8021121 6192407 6931564 8027695
  39  *      8017142 8037343 8055222 8042126 8074791 8075173
  40  * @summary Verify locale data
  41  * @run main LocaleDataTest
  42  * @run main LocaleDataTest -cldr
  43  *
  44  */
  45 
  46 /*
  47  *
  48  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  49  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  50  *
  51  * Portions copyright (c) 2007 Sun Microsystems, Inc.
  52  * All Rights Reserved.
  53  *
  54  * The original version of this source code and documentation
  55  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  56  * subsidiary of IBM. These materials are provided under terms
  57  * of a License Agreement between Taligent and Sun. This technology
  58  * is protected by multiple US and International patents.
  59  *
  60  * This notice and attribution to Taligent may not be removed.
  61  * Taligent is a registered trademark of Taligent, Inc.
  62  *


  84  *    slashes.  The file is in ISO 8859-1 encoding, with control characters and
  85  *    non-ASCII characters denoted with backslash-u escape sequences.  The program also allows
  86  *    blank lines and comment lines to be interspersed with the data.  Comment lines
  87  *    begin with '#'.
  88  *
  89  *    A data file for this test would look something like this:<pre>
  90  *        FormatData//MonthNames/0=January
  91  *        FormatData//MonthNames/1=February
  92  *        LocaleNames//US=United States
  93  *        LocaleNames//FR=France
  94  *        FormatData/fr_FR/MonthNames/0=janvier
  95  *        FormatData/fr_FR/MonthNames/1=f\u00e9vrier
  96  *        LocaleNames/fr_FR/US=\u00c9tats-Unis
  97  *        LocaleNames/fr_FR/FR=France</pre>
  98  *
  99  *    You can use language tag with '-' in locale field like this:<pre>
 100  *        LocaleNames/sr-Latn/SR=Surinam
 101  *        FormatData/sr-Latn-BA/DayNames/2=utorak</pre>
 102  *
 103  *    The command-line syntax of this test is
 104  *        <tt>java LocaleDataTest [-w] [{ -s | <filename> }] [-cldr]</tt>
 105  *
 106  *    This program always sends its results to standard output.   If -w is not specified,
 107  *    this program prints out only the differences between the data file and the actual
 108  *    resource data.  If -w is specified, the program prints out every entry, comment,
 109  *    and blank line from the data file.  Where there is a difference between the data
 110  *    file and the resource data, the data is the data from the resources.  This feature
 111  *    can be used to quickly generate a new data file.
 112  *
 113  *    The user can specify an optional filename or -s.  If the user specifies a filename,
 114  *    the program uses that file as the data file.  If the user specifies -s, the program
 115  *    reads its input from standard input rather than from a file.  If the user specifies
 116  *    neither, the program reads its input from a file called LocaleData in the same
 117  *    directory the program itself resides in.
 118  *
 119  *    The -nothrow option prevents the program from throwing an exception when it
 120  *    gets an error.  -w implies -nothrow.
 121  *
 122  *    -cldr option specifies to test CLDR locale data. The default data file name for this
 123  *    option is "CLDRLocaleData".
 124  *
 125  *    Other command-line options can be specified, but are ignored.
 126  *
 127  *    It's important to note what this test will NOT test.  Certain changes to the locale
 128  *    data are meant to have certain effects on the internationalization frameworks.  For
 129  *    instance, we could ensure round-trip formatting/parsing integrity for the full
 130  *    date/time format of SimpleDateFormat by making sure that the full date and time
 131  *    patterns include sufficient data.  The test of this is not whether changes were
 132  *    made to the locale data; it's whether using this data gives round-trip integrity.
 133  *    Likewise, changing the currency patterns to use \u00a4 instead of local currency
 134  *    symbols isn't something that can be tested by this test; instead, you want to
 135  *    actually format currency values and make sure the proper currency symbol was used.
 136  *
 137  *    This test by itself doesn't do an exhaustive comparison of locale data.  It is
 138  *    possible to do this manually, however:  Use the GenerateKeyList tool to produce
 139  *    a complete list of keys for the two versions of the locales you want to compare,
 140  *    and then diff them.  This will flag additions and deletions.  Generate a data file
 141  *    for the base version of the data using the -w option and the output from
 142  *    GenerateKeyList, and then use the resultant file as the data file when you run
 143  *    this test against the new version of the data.
 144  */
 145 
 146 import java.io.*;
 147 import java.text.*;
 148 import java.util.Locale;
 149 import java.util.ResourceBundle;
 150 import java.util.ResourceBundle.Control;
 151 import java.util.MissingResourceException;
 152 
 153 public class LocaleDataTest
 154 {
 155     static final String TEXT_RESOURCES_PACKAGE ="sun.text.resources";
 156     static final String UTIL_RESOURCES_PACKAGE ="sun.util.resources";
 157     static final String DEFAULT_DATAFILE ="LocaleData";
 158     static String cldrSuffix = "";
 159 
 160     public static void main(String[] args) throws Exception {
 161 
 162         // set up our flags and our input and output streams based on the
 163         // command-line arguments (exceptions generated here will propagate out
 164         // to the environment)
 165         BufferedReader in = null;
 166         PrintWriter out = null;
 167         boolean writeNewFile = false;
 168         boolean doThrow = true;
 169 
 170         for (int i = 0; i < args.length; i++) {
 171             if (args[i].equals("-w")) {
 172                 writeNewFile = true;
 173                 doThrow = false;
 174             }
 175 
 176             else if (args[i].equals("-nothrow"))
 177                 doThrow = false;
 178 
 179             else if (args[i].equals("-cldr")) {
 180                 cldrSuffix = ".cldr";
 181             }
 182 
 183             else if (args[i].equals("-s") && in == null)
 184                 in = new BufferedReader(new EscapeReader(new InputStreamReader(System.in,
 185                                 "ISO8859_1")));
 186             else if (!args[i].startsWith("-") && in == null)
 187                 in = new BufferedReader(new EscapeReader(new InputStreamReader(new
 188                                 FileInputStream(args[i]), "ISO8859_1")));
 189         }
 190         if (in == null) {
 191             File localeData = new File(System.getProperty("test.src", "."), DEFAULT_DATAFILE + cldrSuffix);
 192             in = new BufferedReader(new EscapeReader(new InputStreamReader(new
 193                             FileInputStream(localeData), "ISO8859_1")));
 194         }
 195         out = new PrintWriter(new EscapeWriter(new OutputStreamWriter(System.out,
 196                         "ISO8859_1")), true);
 197 
 198         // perform the actual test
 199         int errorCount = doTest(in, out, writeNewFile);
 200 
 201         // write out the error count, and throw an exception out into the environment
 202         // if there were any errors
 203         if (errorCount != 0) {
 204             if (!writeNewFile)
 205                 out.println("Test failed.  " + errorCount + " errors.");
 206             if (doThrow)
 207                 throw new Exception("Test failed.  " + errorCount + " errors.");
 208         }
 209         else if (!writeNewFile)
 210             out.println("Test passed.");
 211 


 285             resTag = resTag.substring(0, resTag.length() - 1);
 286             oldIndex = index;
 287             index = key.indexOf("/", oldIndex + 1);
 288             if (index == -1) index = key.length();
 289             resTag += key.substring(oldIndex, index);
 290         }
 291 
 292         if (index < key.length() - 1)
 293             qualifier = key.substring(index + 1);
 294         else
 295             qualifier = "";
 296 
 297         String retrievedValue = null;
 298         Object resource = null;
 299         try {
 300             String fullName = null;
 301             if (rbName.equals("CalendarData")
 302                     || rbName.equals("CurrencyNames")
 303                     || rbName.equals("LocaleNames")
 304                     || rbName.equals("TimeZoneNames")) {
 305                 fullName = UTIL_RESOURCES_PACKAGE + cldrSuffix + "." + rbName;
 306             } else {
 307                 fullName = TEXT_RESOURCES_PACKAGE + cldrSuffix + "." + rbName;
 308             }
 309             Locale locale;
 310             if (use_tag) {
 311                 locale = Locale.forLanguageTag(localeName);
 312             } else {
 313                 locale = new Locale(language, country, variant);
 314             }
 315             ResourceBundle bundle = ResourceBundle.getBundle(fullName,
 316                                                              locale,
 317                                                              JRELocaleResourceBundleControl.INSTANCE);
 318             resource = bundle.getObject(resTag);
 319         }
 320         catch (MissingResourceException e) {
 321         }
 322 
 323         if (resource != null) {
 324             if (resource instanceof String) {
 325                 retrievedValue = (String)resource;
 326             }
 327             else if (resource instanceof String[]) {


 366             if (writeNewFile)
 367                 out.println(key + "=" + expectedValue);
 368         }
 369         return true;
 370     }
 371 
 372     private static class JRELocaleResourceBundleControl extends ResourceBundle.Control {
 373         static final JRELocaleResourceBundleControl INSTANCE = new JRELocaleResourceBundleControl();
 374 
 375         private JRELocaleResourceBundleControl() {
 376         }
 377 
 378         @Override
 379         public Locale getFallbackLocale(String baseName, Locale locale) {
 380             if (baseName == null || locale == null) {
 381                 throw new NullPointerException();
 382             }
 383             return null;
 384         }
 385 


 386         /**
 387          * Changes baseName to its per-language/country package name and
 388          * calls the super class implementation. For example,
 389          * if the baseName is "sun.text.resources.FormatData" and locale is ja_JP,
 390          * the baseName is changed to "sun.text.resources.ja.JP.FormatData". If
 391          * baseName contains "cldr", such as "sun.text.resources.cldr.FormatData",
 392          * the name is changed to "sun.text.resources.cldr.ja.JP.FormatData".
 393          */
 394         @Override
 395         public String toBundleName(String baseName, Locale locale) {
 396             String newBaseName = baseName;
 397             String lang = locale.getLanguage();
 398             String ctry = locale.getCountry();
 399             if (lang.length() > 0) {
 400                 if (baseName.startsWith(UTIL_RESOURCES_PACKAGE + cldrSuffix)
 401                     || baseName.startsWith(TEXT_RESOURCES_PACKAGE + cldrSuffix)) {
 402                     // Assume the lengths are the same.
 403                     if (UTIL_RESOURCES_PACKAGE.length()
 404                         != TEXT_RESOURCES_PACKAGE.length()) {
 405                         throw new InternalError("The resources package names have different lengths.");
 406                     }
 407                     int index = (TEXT_RESOURCES_PACKAGE + cldrSuffix).length();
 408                     ctry = (ctry.length() == 2) ? ("." + ctry) : "";
 409                     newBaseName = baseName.substring(0, index + 1) + lang + ctry


 410                                       + baseName.substring(index);
 411                 }
 412             }
 413             return super.toBundleName(newBaseName, locale);
 414         }
 415     }
 416 }
 417 
 418 class EscapeReader extends FilterReader {
 419     public EscapeReader(Reader in) {
 420         super(in);
 421     }
 422 
 423     public int read() throws IOException {
 424         if (buffer != null) {
 425             String b = buffer.toString();
 426             int result = b.charAt(0);
 427             if (b.length() > 1)
 428                 buffer = new StringBuffer(b.substring(1));
 429             else