Package com.ibm.icu.impl.data
Class ResourceReader
- java.lang.Object
-
- com.ibm.icu.impl.data.ResourceReader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class ResourceReader extends Object implements Closeable
A reader for text resource data in the current package or the package of a given class object. The resource data is loaded through the class loader, so it will typically be a file in the same directory as the *.class files, or a file within a JAR file in the corresponding subdirectory. The file must be a text file in one of the supported encodings; when the resource is opened by constructing aResourceReaderobject the encoding is specified.2015-sep-03 TODO: Only used in com.ibm.icu.dev.test.format, move there.
-
-
Constructor Summary
Constructors Constructor Description ResourceReader(InputStream is, String resourceName)Construct a reader object for the input stream associated with the given resource name.ResourceReader(InputStream is, String resourceName, String encoding)Construct a reader object for the input stream associated with the given resource name.ResourceReader(Class<?> rootClass, String resourceName)Construct a reader object for the text file of the given name in the given class's package, using the default encoding.ResourceReader(Class<?> rootClass, String resourceName, String encoding)Construct a reader object for the text file of the given name in the given class's package, using the given encoding.ResourceReader(String resourceName)Construct a reader object for the text file of the given name in this package, using the default encoding.ResourceReader(String resourceName, String encoding)Construct a reader object for the text file of the given name in this package, using the given encoding.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlying reader and releases any system resources associated with it.StringdescribePosition()Return a string description of the position of the last line returned by readLine() or readLineSkippingComments().intgetLineNumber()Return the one-based line number of the last line returned by readLine() or readLineSkippingComments().StringreadLine()Read and return the next line of the file ornullif the end of the file has been reached.StringreadLineSkippingComments()Read a line, ignoring blank lines and lines that start with '#'.StringreadLineSkippingComments(boolean trim)Read a line, ignoring blank lines and lines that start with '#'.voidreset()Reset this reader so that the next call toreadLine()returns the first line of the file again.
-
-
-
Constructor Detail
-
ResourceReader
public ResourceReader(String resourceName, String encoding) throws UnsupportedEncodingException
Construct a reader object for the text file of the given name in this package, using the given encoding.- Parameters:
resourceName- the name of the text file located in this package's ".data" subpackage.encoding- the encoding of the text file; if unsupported an exception is thrown- Throws:
UnsupportedEncodingException- ifencodingis not supported by the JDK.
-
ResourceReader
public ResourceReader(String resourceName)
Construct a reader object for the text file of the given name in this package, using the default encoding.- Parameters:
resourceName- the name of the text file located in this package's ".data" subpackage.
-
ResourceReader
public ResourceReader(Class<?> rootClass, String resourceName, String encoding) throws UnsupportedEncodingException
Construct a reader object for the text file of the given name in the given class's package, using the given encoding.- Parameters:
resourceName- the name of the text file located in the given class's package.encoding- the encoding of the text file; if unsupported an exception is thrown- Throws:
UnsupportedEncodingException- ifencodingis not supported by the JDK.
-
ResourceReader
public ResourceReader(InputStream is, String resourceName, String encoding)
Construct a reader object for the input stream associated with the given resource name.- Parameters:
is- the input stream of the resourceresourceName- the name of the resource
-
ResourceReader
public ResourceReader(InputStream is, String resourceName)
Construct a reader object for the input stream associated with the given resource name.- Parameters:
is- the input stream of the resourceresourceName- the name of the resource
-
-
Method Detail
-
readLine
public String readLine() throws IOException
Read and return the next line of the file ornullif the end of the file has been reached.- Throws:
IOException
-
readLineSkippingComments
public String readLineSkippingComments(boolean trim) throws IOException
Read a line, ignoring blank lines and lines that start with '#'.- Parameters:
trim- if true then trim leading Pattern_White_Space.- Throws:
IOException
-
readLineSkippingComments
public String readLineSkippingComments() throws IOException
Read a line, ignoring blank lines and lines that start with '#'. Do not trim leading Pattern_White_Space.- Throws:
IOException
-
getLineNumber
public int getLineNumber()
Return the one-based line number of the last line returned by readLine() or readLineSkippingComments(). Should only be called after a call to one of these methods; otherwise the return value is undefined.
-
describePosition
public String describePosition()
Return a string description of the position of the last line returned by readLine() or readLineSkippingComments().
-
reset
public void reset()
Reset this reader so that the next call toreadLine()returns the first line of the file again. This is a somewhat expensive call, however, callingreset()after calling it the first time does nothing ifreadLine()has not been called in between.
-
close
public void close() throws IOExceptionCloses the underlying reader and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-