Top Description Fields Constructors Methods
com.ibm.icu.impl.data

public Class ResourceReader

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.BufferedReader, .Closeable, .IOException, .InputStream, .InputStreamReader, .UnsupportedEncodingException, com.ibm.icu.impl.ICUData, .PatternProps

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 a ResourceReader object the encoding is specified.

2015-sep-03 TODO: Only used in com.ibm.icu.dev.test.format, move there.

Author
Alan Liu

Field Summary

Modifier and TypeField and Description
private String
private int
lineNo

The one-based line number.

private BufferedReader
private String
private Class<?>

Constructor Summary

AccessConstructor and Description
public
ResourceReader(String
the name of the text file located in this package's ".data" subpackage.
resourceName
,
String
the encoding of the text file; if unsupported an exception is thrown
encoding
)

Construct a reader object for the text file of the given name in this package, using the given encoding.

public
ResourceReader(String
the name of the text file located in this package's ".data" subpackage.
resourceName
)

Construct a reader object for the text file of the given name in this package, using the default encoding.

public
ResourceReader(Class<?> rootClass, String
the name of the text file located in the given class's package.
resourceName
,
String
the encoding of the text file; if unsupported an exception is thrown
encoding
)

Construct a reader object for the text file of the given name in the given class's package, using the given encoding.

public
ResourceReader(InputStream
the input stream of the resource
is
,
String
the name of the resource
resourceName
,
String encoding)

Construct a reader object for the input stream associated with the given resource name.

public
ResourceReader(InputStream
the input stream of the resource
is
,
String
the name of the resource
resourceName
)

Construct a reader object for the input stream associated with the given resource name.

public
ResourceReader(Class<?> rootClass, String
the name of the text file located in the given class's package.
resourceName
)

Construct a reader object for the text file of the given name in the given class's package, using the default encoding.

Method Summary

Modifier and TypeMethod and Description
private void
_reset()

Reset to the start by reconstructing the stream and readers.

public void
close()

Implements java.io.Closeable.close.

Closes the underlying reader and releases any system resources associated with it.
public String
describePosition()

Return a string description of the position of the last line returned by readLine() or readLineSkippingComments().

public int
getLineNumber()

Return the one-based line number of the last line returned by readLine() or readLineSkippingComments().

public String
readLine()

Read and return the next line of the file or null if the end of the file has been reached.

public String
readLineSkippingComments(boolean
if true then trim leading Pattern_White_Space.
trim
)

Read a line, ignoring blank lines and lines that start with '#'.

public String
readLineSkippingComments()

Read a line, ignoring blank lines and lines that start with '#'.

public void
reset()

Reset this reader so that the next call to readLine() returns the first line of the file again.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

encodingback to summary
private String encoding
lineNoback to summary
private int lineNo

The one-based line number. Has the special value -1 before the object is initialized. Has the special value 0 after initialization but before the first line is read.

readerback to summary
private BufferedReader reader
resourceNameback to summary
private String resourceName
rootback to summary
private Class<?> root

Constructor Detail

ResourceReaderback to summary
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:String

the name of the text file located in this package's ".data" subpackage.

encoding:String

the encoding of the text file; if unsupported an exception is thrown

Exceptions
UnsupportedEncodingException:
if encoding is not supported by the JDK.
ResourceReaderback to summary
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:String

the name of the text file located in this package's ".data" subpackage.

ResourceReaderback to summary
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:String

the name of the text file located in the given class's package.

encoding:String

the encoding of the text file; if unsupported an exception is thrown

Exceptions
UnsupportedEncodingException:
if encoding is not supported by the JDK.
ResourceReaderback to summary
public ResourceReader(InputStream is, String resourceName, String encoding)

Construct a reader object for the input stream associated with the given resource name.

Parameters
is:InputStream

the input stream of the resource

resourceName:String

the name of the resource

ResourceReaderback to summary
public ResourceReader(InputStream is, String resourceName)

Construct a reader object for the input stream associated with the given resource name.

Parameters
is:InputStream

the input stream of the resource

resourceName:String

the name of the resource

ResourceReaderback to summary
public 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.

Parameters
resourceName:String

the name of the text file located in the given class's package.

Method Detail

_resetback to summary
private void _reset() throws UnsupportedEncodingException

Reset to the start by reconstructing the stream and readers. We could also use mark() and reset() on the stream or reader, but that would cause them to keep the stream data around in memory. We don't want that because some of the resource files are large, e.g., 400k.

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Closes the underlying reader and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

describePositionback to summary
public String describePosition()

Return a string description of the position of the last line returned by readLine() or readLineSkippingComments().

getLineNumberback to summary
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.

readLineback to summary
public String readLine() throws IOException

Read and return the next line of the file or null if the end of the file has been reached.

readLineSkippingCommentsback to summary
public String readLineSkippingComments(boolean trim) throws IOException

Read a line, ignoring blank lines and lines that start with '#'.

Parameters
trim:boolean

if true then trim leading Pattern_White_Space.

readLineSkippingCommentsback to summary
public String readLineSkippingComments() throws IOException

Read a line, ignoring blank lines and lines that start with '#'. Do not trim leading Pattern_White_Space.

resetback to summary
public void reset()

Reset this reader so that the next call to readLine() returns the first line of the file again. This is a somewhat expensive call, however, calling reset() after calling it the first time does nothing if readLine() has not been called in between.