12ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/* GENERATED SOURCE. DO NOT MODIFY. */
2f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// © 2016 and later: Unicode, Inc. and others.
3f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html#License
42ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/**
52ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller *******************************************************************************
62ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * Copyright (C) 2001-2015, International Business Machines Corporation and
72ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * others. All Rights Reserved.
82ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller *******************************************************************************
92ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */
102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpackage android.icu.impl.data;
122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.io.BufferedReader;
142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.io.Closeable;
152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.io.IOException;
162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.io.InputStream;
172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.io.InputStreamReader;
182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport java.io.UnsupportedEncodingException;
192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.impl.ICUData;
212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerimport android.icu.impl.PatternProps;
222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller/**
242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * A reader for text resource data in the current package or the package
252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * of a given class object.  The
262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * resource data is loaded through the class loader, so it will
272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * typically be a file in the same directory as the *.class files, or
282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * a file within a JAR file in the corresponding subdirectory.  The
292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * file must be a text file in one of the supported encodings; when the
302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * resource is opened by constructing a <code>ResourceReader</code>
312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * object the encoding is specified.
322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller *
331fba789ac68efdd9120a7373f49daef42833e674Neil Fuller * <p>2015-sep-03 TODO: Only used in android.icu.dev.test.format, move there.
342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller *
352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller * @author Alan Liu
36836e6b40a94ec3fb7545a76cb072960442b7eee9Neil Fuller * @hide Only a subset of ICU is exposed in Android
372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller */
382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fullerpublic class ResourceReader implements Closeable {
392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private BufferedReader reader = null;
402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private String resourceName;
412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private String encoding; // null for default encoding
422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private Class<?> root;
43f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert
442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * The one-based line number. Has the special value -1 before the
462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * object is initialized. Has the special value 0 after initialization
472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * but before the first line is read.
482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private int lineNo;
502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Construct a reader object for the text file of the given name
532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in this package, using the given encoding.
542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param resourceName the name of the text file located in this
552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * package's ".data" subpackage.
562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param encoding the encoding of the text file; if unsupported
572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * an exception is thrown
582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @exception UnsupportedEncodingException if
592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * <code>encoding</code> is not supported by the JDK.
602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public ResourceReader(String resourceName, String encoding)
622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        throws UnsupportedEncodingException {
632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this(ICUData.class, "data/" + resourceName, encoding);
642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Construct a reader object for the text file of the given name
682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in this package, using the default encoding.
692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param resourceName the name of the text file located in this
702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * package's ".data" subpackage.
712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public ResourceReader(String resourceName) {
732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this(ICUData.class, "data/" + resourceName);
742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Construct a reader object for the text file of the given name
782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the given class's package, using the given encoding.
792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param resourceName the name of the text file located in the
802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * given class's package.
812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param encoding the encoding of the text file; if unsupported
822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * an exception is thrown
832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @exception UnsupportedEncodingException if
842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * <code>encoding</code> is not supported by the JDK.
852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public ResourceReader(Class<?> rootClass, String resourceName, String encoding)
872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        throws UnsupportedEncodingException {
882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this.root = rootClass;
892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this.resourceName = resourceName;
902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this.encoding = encoding;
912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        lineNo = -1;
922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        _reset();
932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller         /**
962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller          * Construct a reader object for the input stream associated with
972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller          * the given resource name.
982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller          * @param is the input stream of the resource
992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller          * @param resourceName the name of the resource
1002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller          */
1012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller          public ResourceReader(InputStream is, String resourceName, String encoding) {
1022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                   this.root = null;
1032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller         this.resourceName = resourceName;
1042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller         this.encoding = encoding;
1052ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller         this.lineNo = -1;
1072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller         try {
108f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert             InputStreamReader isr = (encoding == null)
1092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                 ? new InputStreamReader(is)
1102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                 : new InputStreamReader(is, encoding);
1112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller             this.reader = new BufferedReader(isr);
1132ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller             this.lineNo= 0;
1142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller         }
1152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller         catch (UnsupportedEncodingException e) {
1162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller         }
1172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     }
1182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller          /**
1202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller           * Construct a reader object for the input stream associated with
1212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller           * the given resource name.
1222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller           * @param is the input stream of the resource
1232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller           * @param resourceName the name of the resource
1242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller           */
1252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller          public ResourceReader(InputStream is, String resourceName) {
1262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller              this(is, resourceName, null);
1272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller          }
1282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Construct a reader object for the text file of the given name
1312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * in the given class's package, using the default encoding.
1322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param resourceName the name of the text file located in the
1332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * given class's package.
1342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public ResourceReader(Class<?> rootClass, String resourceName) {
1362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this.root = rootClass;
1372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this.resourceName = resourceName;
1382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        this.encoding = null;
1392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        lineNo = -1;
1402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        try {
1412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            _reset();
1422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        } catch (UnsupportedEncodingException e) {}
1432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Read and return the next line of the file or <code>null</code>
1472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * if the end of the file has been reached.
1482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1492ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public String readLine() throws IOException {
1502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if (lineNo == 0) {
1512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            // Remove BOMs
1522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            ++lineNo;
1532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            String line = reader.readLine();
1542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            if (line != null && (line.charAt(0) == '\uFFEF' ||
1552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                                 line.charAt(0) == '\uFEFF')) {
1562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                line = line.substring(1);
1572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            }
1582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            return line;
1592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
1602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        ++lineNo;
1612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return reader.readLine();
1622ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Read a line, ignoring blank lines and lines that start with
1662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * '#'.
1672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * @param trim if true then trim leading Pattern_White_Space.
1682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public String readLineSkippingComments(boolean trim) throws IOException {
1702ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        for (;;) {
1712ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            String line = readLine();
1722ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            if (line == null) {
1732ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                return line;
1742ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            }
1752ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            // Skip over white space
1762ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            int pos = PatternProps.skipWhiteSpace(line, 0);
1772ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            // Ignore blank lines and comment lines
1782ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            if (pos == line.length() || line.charAt(pos) == '#') {
1792ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                continue;
1802ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            }
1812ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            // Process line
1822ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            if (trim) line = line.substring(pos);
1832ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            return line;
1842ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
1852ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1862ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1872ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1882ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1892ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Read a line, ignoring blank lines and lines that start with
1902ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * '#'. Do not trim leading Pattern_White_Space.
1912ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
1922ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public String readLineSkippingComments() throws IOException {
1932ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return readLineSkippingComments(false);
1942ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
1952ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
1962ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
1972ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Return the one-based line number of the last line returned by
1982ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * readLine() or readLineSkippingComments(). Should only be called
1992ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * after a call to one of these methods; otherwise the return
2002ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * value is undefined.
2012ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
2022ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public int getLineNumber() {
2032ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return lineNo;
2042ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
205f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert
2062ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
2072ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Return a string description of the position of the last line
2082ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * returned by readLine() or readLineSkippingComments().
2092ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
2102ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public String describePosition() {
2112ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        return resourceName + ':' + lineNo;
2122ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
213f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert
2142ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
2152ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Reset this reader so that the next call to
2162ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * <code>readLine()</code> returns the first line of the file
2172ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * again.  This is a somewhat expensive call, however, calling
2182ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * <code>reset()</code> after calling it the first time does
2192ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * nothing if <code>readLine()</code> has not been called in
2202ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * between.
2212ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
2222ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public void reset() {
2232ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        try {
2242ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            _reset();
2252ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        } catch (UnsupportedEncodingException e) {}
2262ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // We swallow this exception, if there is one.  If the encoding is
2272ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // invalid, the constructor will have thrown this exception already and
2282ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        // the caller shouldn't use the object afterwards.
2292ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
2302ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2312ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
2322ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Reset to the start by reconstructing the stream and readers.
2332ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * We could also use mark() and reset() on the stream or reader,
2342ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * but that would cause them to keep the stream data around in
2352ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * memory.  We don't want that because some of the resource files
2362ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * are large, e.g., 400k.
2372ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
2382ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    private void _reset() throws UnsupportedEncodingException {
2392ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        try {
2402ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            close();
2412ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        } catch (IOException e) {}
2422ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if (lineNo == 0) {
2432ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            return;
2442ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2452ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        InputStream is = ICUData.getStream(root, resourceName);
2462ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if (is == null) {
2472ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            throw new IllegalArgumentException("Can't open " + resourceName);
2482ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
249f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert
2502ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        InputStreamReader isr =
2512ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            (encoding == null) ? new InputStreamReader(is) :
2522ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller                                 new InputStreamReader(is, encoding);
2532ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        reader = new BufferedReader(isr);
2542ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        lineNo = 0;
2552ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
2562ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller
2572ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    /**
2582ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * Closes the underlying reader and releases any system resources
2592ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * associated with it. If the stream is already closed then invoking
2602ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     * this method has no effect.
2612ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller     */
262f86f25d102340da66b9c7cb6b2d5ecdc0de43ecfFredrik Roubert    @Override
2632ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    public void close() throws IOException {
2642ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        if (reader != null) {
2652ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            reader.close();
2662ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller            reader = null;
2672ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller        }
2682ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller    }
2692ae130017183d2f66d55bf0ca51f8da3294644fdNeil Fuller}
270