|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectIIOServiceProvider
ImageReaderWriterSpi
ImageReaderSpi
SpatialImageReader.Spi
StreamImageReader.Spi
TextImageReader.Spi
protected abstract static class TextImageReader.Spi
Service provider interface (SPI) for TextImageReaders. This SPI provides additional
fields controlling the character encoding (charset), the local to use for parsing
numbers, dates or other objects (locale) and the value used in place of missing
pixel values (padValue).
By default the charset and locale fields are initialized to null,
which stands for the platform-dependent character encoding and locale. In addition the
padValue is set to Double.NaN, which means that there is no pad value. If
a subclass wants to fix the encoding, locale and pad value to some format-specific values,
it shall specify those values at construction time as in the example below:
public Spi() {
charset = Charset.forName("ISO-8859-1"); // ISO Latin Alphabet No. 1
locale = Locale.US;
padValue = -9999;
}
The table below summarizes the initial values.
Those values can be modified by subclass constructors.
| Field | Value |
|---|---|
ImageReaderSpi.inputTypes |
String, File, URI, URL, URLConnection,
Reader, InputStream, ImageInputStream,
ReadableByteChannel |
ImageReaderWriterSpi.suffixes |
"txt", "TXT",
"asc", "ASC",
"dat", "DAT" |
charset |
null (stands for the
platform default) |
locale |
null (stands for the
platform default) |
padValue |
Double.NaN (stands for no pad-value) |
| See super-class javadoc for remaining fields | |
TextImageWriter.Spi
| coverage/geotk-coverageio (download) | View source code for this class |
| Field Summary | |
|---|---|
protected Charset |
charset
Character encoding, or null for the default. |
protected Locale |
locale
The locale for numbers or dates parsing. |
protected double |
padValue
The pad value, or Double.NaN if none. |
| Fields inherited from class ImageReaderSpi |
|---|
inputTypes, STANDARD_INPUT_TYPE, writerSpiNames |
| Fields inherited from class IIOServiceProvider |
|---|
vendorName, version |
| Constructor Summary | |
|---|---|
protected |
TextImageReader.Spi()
Constructs a quasi-blank TextImageReader.Spi. |
| Method Summary | |
|---|---|
boolean |
canDecodeInput(Object source)
Returns true if the supplied source object appears to be of the format
supported by this reader. |
protected boolean |
canDecodeInput(Object source,
int readAheadLimit)
Returns true if the supplied source object appears to be of the format
supported by this reader. |
protected boolean |
isValidColumnCount(int count)
Invoked by isValidContent(double[][]) for determining if the given number
of columns is likely to be valid. |
protected boolean |
isValidContent(double[][] rows)
Invoked by canDecodeInput(Object, int) for determining if the given rows are
likely to be valid. |
protected boolean |
isValidHeader(Set<String> keywords)
Invoked by canDecodeInput(Object, int) for determining if the given header is
likely to be valid. |
| Methods inherited from class SpatialImageReader.Spi |
|---|
addExtraMetadataFormat, getImageMetadataFormat, getStreamMetadataFormat |
| Methods inherited from class ImageReaderSpi |
|---|
createReaderInstance, createReaderInstance, getImageWriterSpiNames, getInputTypes, isOwnReader |
| Methods inherited from class IIOServiceProvider |
|---|
getDescription, getVendorName, getVersion, onDeregistration, onRegistration |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Charset charset
null for the default. This field is initially
null, which means to use the platform-dependent encoding. Subclasses
shall set a non-null value if the files to be decoded use some specific character
encoding.
TextImageReader.getCharset(InputStream)protected Locale locale
Locale.US means that
numbers are expected to use a dot for the decimal separator. This field is initially
null, which means that the default locale
will be used.
TextImageReader.getLineFormat(int)protected double padValue
Double.NaN if none. Every occurrences of pixel value equals
to this pad value will be replaced by Double.NaN during the read operation.
Note that this replacement doesn't apply to non-pixel values (for example x,
y coordinates in the format read by
TextRecordImageReader).
TextImageReader.getPadValue(int)| Constructor Detail |
|---|
protected TextImageReader.Spi()
TextImageReader.Spi. This constructor initializes
the fields as documented in the class javadoc. It is
up to the subclass to initialize all other instance variables in order to provide
working versions of all methods.
For efficiency reasons, the above fields are initialized to shared arrays. Subclasses can assign new arrays, but should not modify the default array content.
| Method Detail |
|---|
public boolean canDecodeInput(Object source)
throws IOException
true if the supplied source object appears to be of the format
supported by this reader. The default implementation tries to parse the first
few lines up to 2048 characters, as below:
return canDecodeInput(source, 2048);
canDecodeInput in class ImageReaderSpisource - The object (typically an ImageInputStream) to be decoded.
true if the source seems readable.
IOException - If an error occurred during reading.
protected boolean canDecodeInput(Object source,
int readAheadLimit)
throws IOException
true if the supplied source object appears to be of the format
supported by this reader. The default implementation tries to parse the first
few lines up to the specified number of characters, then gives those lines to
the isValidHeader(Set) and isValidContent(double[][]) methods.
The default implementation is suitable for
TextMatrixImageReader, i.e.
it expects only rows for pixel values (no header) and all rows shall have the
same length. If this behavior needs to be changed, consider overriding the
isValidHeader and isValidContent methods.
source - The object (typically an ImageInputStream) to be decoded.readAheadLimit - Maximum number of characters to read. If this amount is reached
but this method still unable to make a choice, then it conservatively returns
false.
true if the source seems readable.
IOException - If an error occurred during reading.protected boolean isValidHeader(Set<String> keywords)
canDecodeInput(Object, int) for determining if the given header is
likely to be valid. This method receives in argument a keywords set containing
the first word of every header lines (defined below), converted to upper
cases using the locale defined in this provider.
A header line is defined as a line which is not a comment line, appears before the first row of pixel values and where the first non-blank character is a Java identifier start.
The default implementation returns true if the given set is empty.
In other words, by default no header is allowed in the data file.
keywords - The first word found in every header lines,
converted to upper-case.
true if the set of keywords is known to this format.protected boolean isValidContent(double[][] rows)
canDecodeInput(Object, int) for determining if the given rows are
likely to be valid. This method receives in argument a rows array containing
the first few lines of data. The number of rows depends on the average row length and
the readAheadLimit argument given to canDecodeInput.
The default implementation returns true if there is at least one row
and every row have the same number of columns.
rows - The first few rows.
true if the given rows seem to have a valid content.protected boolean isValidColumnCount(int count)
isValidContent(double[][]) for determining if the given number
of columns is likely to be valid. This method receives in argument the length of
every rows that were given to isValidContent, when that length is constant.
The default implementation returns true if the number of columns is greater
than zero. Subclasses can override this method if they know the expected number of
columns.
count - The number of columns in the first few line of rows.
true if the given number of columns seems to be valid.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||