Package org.svetovid.io
Interface SvetovidReader
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
AbstractSvetovidReader
,DefaultSvetovidReader
,StandardSvetovidReader
This interface provides methods that simplify reading the program input data
for beginner programmers. Exception handling is not necessary as when it is
turned off by
setThrowingExceptions(boolean)
many operations are
returning default values on any errors. If necessary, the last raised
exception can be retrieved using getLastException()
method.-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this reader and releases any resources associated with the underlying source.Returns the exception raised in the last operation; if the operation was successful and no exception was raised, returnsnull
.Returns the currently used pattern for recognizing whitespace.boolean
hasMore()
Checks whether this reader has data to be read.boolean
isEmpty()
Checks whether this reader has no more data to be read.boolean
Returns the indicator whether this reader will throw exceptions on I/O operation errors or just return default values.readAll()
Reads all remaining content and returns it as a string.String[]
Read all remaining lines and returns them as an array of strings.boolean
readBool()
Reads one token and converts it to a boolean value.boolean[]
Reads one line, separates it into tokens and converts them to boolean values.Boolean[]
Reads one line, separates it into tokens and converts them to boolean values.Reads one token and converts it to a boolean value.boolean[][]
Reads multiple lines and converts the data to a boolean matrix.Boolean[][]
Reads multiple lines and converts the data to a boolean matrix.byte
readByte()
Reads one token and converts it to a byte value.byte[]
Reads one line, separates it into tokens and converts them to byte values.Byte[]
Reads one line, separates it into tokens and converts them to byte values.Reads one token and converts it to a byte value.byte[][]
Reads multiple lines and converts the data to a byte matrix.Byte[][]
Reads multiple lines and converts the data to a byte matrix.char
readChar()
Reads one token and converts it to a character value.char[]
Reads one line, separates it into tokens and converts them to character values.Reads one line, separates it into tokens and converts them to character values.Reads one token and converts it to a character value.char[][]
Reads multiple lines and converts the data to a character matrix.Character[][]
Reads multiple lines and converts the data to a character matrix.double
Reads one token and converts it to a double-precision floating-point value.double[]
Reads one line, separates it into tokens and converts them to double-precision floating-point values.Double[]
Reads one line, separates it into tokens and converts them to double-precision floating-point values.Reads one token and converts it to a double-precision floating-point value.double[][]
Reads multiple lines and converts the data to a double-precision floating-point matrix.Double[][]
Reads multiple lines and converts the data to a double-precision floating-point matrix.float
Reads one token and converts it to a floating-point value.float[]
Reads one line, separates it into tokens and converts them to floating-point values.Float[]
Reads one line, separates it into tokens and converts them to floating-point values.Reads one token and converts it to a floating-point value.float[][]
Reads multiple lines and converts the data to a floating-point matrix.Float[][]
Reads multiple lines and converts the data to a floating-point matrix.int
readInt()
Reads one token and converts it to an integer value.int[]
Reads one line, separates it into tokens and converts them to integer values.Integer[]
Reads one line, separates it into tokens and converts them to integer values.Reads one token and converts it to an integer value.int[][]
Reads multiple lines and converts the data to an integer matrix.Integer[][]
Reads multiple lines and converts the data to an integer matrix.readLine()
Reads a line of text and returns it as a string.long
readLong()
Reads one token and converts it to a long integer value.long[]
Reads one line, separates it into tokens and converts them to long integer values.Long[]
Reads one line, separates it into tokens and converts them to long integer values.Reads one token and converts it to a long integer value.long[][]
Reads multiple lines and converts the data to a long integer matrix.Long[][]
Reads multiple lines and converts the data to a long integer matrix.Reads a JSON (JavaScript Object Notation) formatted object.short
Reads one token and converts it to a short integer value.short[]
Reads one line, separates it into tokens and converts them to short integer values.Short[]
Reads one line, separates it into tokens and converts them to short integer values.Reads one token and converts it to a short integer value.short[][]
Reads multiple lines and converts the data to a shot integer matrix.Short[][]
Reads multiple lines and converts the data to a shot integer matrix.Reads one token and returns it as a string value.String[]
Reads one line, separates it into tokens and returns them as string values.String[][]
Reads multiple lines and converts the data to a string matrix.void
setThrowingExceptions
(boolean shouldThrow) Configures whether this reader should throw exceptions on I/O operation errors or just return default values.void
setWhitespace
(Pattern whitespace) Sets the pattern used to recognize whitespace.
-
Method Details
-
getWhitespace
Pattern getWhitespace()Returns the currently used pattern for recognizing whitespace. This pattern is used to separate tokens when reading form the underlying source. For more on patterns seePattern
.- Returns:
- the pattern currently used to recognize whitespace.
- See Also:
-
setWhitespace
Sets the pattern used to recognize whitespace. This pattern is used to separate tokens when reading form the underlying source. For more on patterns seePattern
.- Parameters:
whitespace
- the pattern to use recognize whitespace- See Also:
-
isThrowingExceptions
boolean isThrowingExceptions()Returns the indicator whether this reader will throw exceptions on I/O operation errors or just return default values.- Returns:
true
if this reader throws exceptions on failed I/O operations;false
otherwise.
-
setThrowingExceptions
void setThrowingExceptions(boolean shouldThrow) Configures whether this reader should throw exceptions on I/O operation errors or just return default values.- Parameters:
shouldThrow
-true
if this reader should throw exceptions on failed I/O operations in the future;false
if it should return default values.
-
getLastException
Throwable getLastException()Returns the exception raised in the last operation; if the operation was successful and no exception was raised, returnsnull
.- Returns:
- the exception raised in the last operation or
null
it the operation was successful.
-
isEmpty
boolean isEmpty()Checks whether this reader has no more data to be read.- Returns:
true
if this reader has no more data to be read;false
otherwise.
-
hasMore
boolean hasMore()Checks whether this reader has data to be read.- Returns:
true
if this reader has data to be read;false
otherwise.
-
close
Closes this reader and releases any resources associated with the underlying source. The general contract ofclose
is that it closes the input source. A closed source cannot perform input operations and cannot be reopened.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
SvetovidIOException
- if an error occurred during the operation.
-
readBool
Reads one token and converts it to a boolean value.- Returns:
- the
boolean
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable boolean.SvetovidIOException
- if an error occurred during the operation.
-
readByte
Reads one token and converts it to a byte value.- Returns:
- the
byte
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable byte.SvetovidIOException
- if an error occurred during the operation.
-
readShort
Reads one token and converts it to a short integer value.- Returns:
- the
short
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable short.SvetovidIOException
- if an error occurred during the operation.
-
readInt
Reads one token and converts it to an integer value.- Returns:
- the
int
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable int.SvetovidIOException
- if an error occurred during the operation.
-
readLong
Reads one token and converts it to a long integer value.- Returns:
- the
long
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable long.SvetovidIOException
- if an error occurred during the operation.
-
readFloat
Reads one token and converts it to a floating-point value.- Returns:
- the
float
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable float.SvetovidIOException
- if an error occurred during the operation.
-
readDouble
Reads one token and converts it to a double-precision floating-point value.- Returns:
- the
double
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable double.SvetovidIOException
- if an error occurred during the operation.
-
readChar
Reads one token and converts it to a character value.- Returns:
- the
char
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable char.SvetovidIOException
- if an error occurred during the operation.
-
readToken
Reads one token and returns it as a string value.- Returns:
- the
String
value read. - Throws:
SvetovidFormatException
- if the token isnull
.SvetovidIOException
- if an error occurred during the operation.
-
readBoolBoxed
Reads one token and converts it to a boolean value.- Returns:
- the
Boolean
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable boolean.SvetovidIOException
- if an error occurred during the operation.
-
readByteBoxed
Reads one token and converts it to a byte value.- Returns:
- the
Byte
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable byte.SvetovidIOException
- if an error occurred during the operation.
-
readShortBoxed
Reads one token and converts it to a short integer value.- Returns:
- the
Short
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable short.SvetovidIOException
- if an error occurred during the operation.
-
readIntBoxed
Reads one token and converts it to an integer value.- Returns:
- the
Integer
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable int.SvetovidIOException
- if an error occurred during the operation.
-
readLongBoxed
Reads one token and converts it to a long integer value.- Returns:
- the
Long
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable long.SvetovidIOException
- if an error occurred during the operation.
-
readFloatBoxed
Reads one token and converts it to a floating-point value.- Returns:
- the
Float
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable float.SvetovidIOException
- if an error occurred during the operation.
-
readDoubleBoxed
Reads one token and converts it to a double-precision floating-point value.- Returns:
- the
Double
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable double.SvetovidIOException
- if an error occurred during the operation.
-
readCharBoxed
Reads one token and converts it to a character value.- Returns:
- the
Character
value read. - Throws:
SvetovidFormatException
- if the token is not a parsable character.SvetovidIOException
- if an error occurred during the operation.
-
readBoolArray
Reads one line, separates it into tokens and converts them to boolean values.- Returns:
- an array of
boolean
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable boolean.SvetovidIOException
- if an error occurred during the operation.
-
readByteArray
Reads one line, separates it into tokens and converts them to byte values.- Returns:
- an array of
byte
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable byte.SvetovidIOException
- if an error occurred during the operation.
-
readShortArray
Reads one line, separates it into tokens and converts them to short integer values.- Returns:
- an array of
short
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable short.SvetovidIOException
- if an error occurred during the operation.
-
readIntArray
Reads one line, separates it into tokens and converts them to integer values.- Returns:
- an array of
int
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable integer.SvetovidIOException
- if an error occurred during the operation.
-
readLongArray
Reads one line, separates it into tokens and converts them to long integer values.- Returns:
- an array of
long
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable long.SvetovidIOException
- if an error occurred during the operation.
-
readFloatArray
Reads one line, separates it into tokens and converts them to floating-point values.- Returns:
- an array of
float
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable float.SvetovidIOException
- if an error occurred during the operation.
-
readDoubleArray
Reads one line, separates it into tokens and converts them to double-precision floating-point values.- Returns:
- an array of
double
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable double.SvetovidIOException
- if an error occurred during the operation.
-
readCharArray
Reads one line, separates it into tokens and converts them to character values.- Returns:
- an array of
char
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable character.SvetovidIOException
- if an error occurred during the operation.
-
readTokenArray
Reads one line, separates it into tokens and returns them as string values.- Returns:
- an array of
String
values read. - Throws:
SvetovidIOException
- if an error occurred during the operation.
-
readBoolArrayBoxed
Reads one line, separates it into tokens and converts them to boolean values.- Returns:
- an array of
Boolean
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable boolean.SvetovidIOException
- if an error occurred during the operation.
-
readByteArrayBoxed
Reads one line, separates it into tokens and converts them to byte values.- Returns:
- an array of
Byte
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable byte.SvetovidIOException
- if an error occurred during the operation.
-
readShortArrayBoxed
Reads one line, separates it into tokens and converts them to short integer values.- Returns:
- an array of
Short
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable short.SvetovidIOException
- if an error occurred during the operation.
-
readIntArrayBoxed
Reads one line, separates it into tokens and converts them to integer values.- Returns:
- an array of
Integer
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable integer.SvetovidIOException
- if an error occurred during the operation.
-
readLongArrayBoxed
Reads one line, separates it into tokens and converts them to long integer values.- Returns:
- an array of
Long
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable long.SvetovidIOException
- if an error occurred during the operation.
-
readFloatArrayBoxed
Reads one line, separates it into tokens and converts them to floating-point values.- Returns:
- an array of
Float
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable float.SvetovidIOException
- if an error occurred during the operation.
-
readDoubleArrayBoxed
Reads one line, separates it into tokens and converts them to double-precision floating-point values.- Returns:
- an array of
Double
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable double.SvetovidIOException
- if an error occurred during the operation.
-
readCharArrayBoxed
Reads one line, separates it into tokens and converts them to character values.- Returns:
- an array of
Character
values read. - Throws:
SvetovidFormatException
- if one of the tokens is not a parsable character.SvetovidIOException
- if an error occurred during the operation.
-
readLine
Reads a line of text and returns it as a string. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a line feed.- Returns:
- A
String
containing the contents of the line, not including any line-termination characters, or null if the end of the source has been reached. - Throws:
SvetovidIOException
- if an error occurred during the operation.
-
readAllLines
Read all remaining lines and returns them as an array of strings. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a line feed.- Returns:
- A
String
array containing the contents of the remaining lines, not including any line-termination characters, or an empty array if the end of the source has been reached. - Throws:
SvetovidIOException
- if an error occurred during the operation.
-
readAll
Reads all remaining content and returns it as a string.- Returns:
- A
String
containing all the remaining contents of the source, or null if the end of the source has been reached. - Throws:
SvetovidIOException
- if an error occurred during the operation.
-
readBoolMatrix
Reads multiple lines and converts the data to a boolean matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
boolean
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable boolean.SvetovidIOException
- if an error occurred during the operation.
-
readByteMatrix
Reads multiple lines and converts the data to a byte matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
byte
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable byte.SvetovidIOException
- if an error occurred during the operation.
-
readShortMatrix
Reads multiple lines and converts the data to a shot integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
short
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable short.SvetovidIOException
- if an error occurred during the operation.
-
readIntMatrix
Reads multiple lines and converts the data to an integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
int
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable integer.SvetovidIOException
- if an error occurred during the operation.
-
readLongMatrix
Reads multiple lines and converts the data to a long integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
long
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable long.SvetovidIOException
- if an error occurred during the operation.
-
readFloatMatrix
Reads multiple lines and converts the data to a floating-point matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
float
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable float.SvetovidIOException
- if an error occurred during the operation.
-
readDoubleMatrix
Reads multiple lines and converts the data to a double-precision floating-point matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
double
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable double.SvetovidIOException
- if an error occurred during the operation.
-
readCharMatrix
Reads multiple lines and converts the data to a character matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
char
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable character.SvetovidIOException
- if an error occurred during the operation.
-
readTokenMatrix
Reads multiple lines and converts the data to a string matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
String
values read. - Throws:
SvetovidIOException
- if an error occurred during the operation.
-
readBoolMatrixBoxed
Reads multiple lines and converts the data to a boolean matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
Boolean
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable boolean.SvetovidIOException
- if an error occurred during the operation.
-
readByteMatrixBoxed
Reads multiple lines and converts the data to a byte matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
Byte
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable byte.SvetovidIOException
- if an error occurred during the operation.
-
readShortMatrixBoxed
Reads multiple lines and converts the data to a shot integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
Short
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable short.SvetovidIOException
- if an error occurred during the operation.
-
readIntMatrixBoxed
Reads multiple lines and converts the data to an integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
Integer
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable integer.SvetovidIOException
- if an error occurred during the operation.
-
readLongMatrixBoxed
Reads multiple lines and converts the data to a long integer matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
Long
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable long.SvetovidIOException
- if an error occurred during the operation.
-
readFloatMatrixBoxed
Reads multiple lines and converts the data to a floating-point matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
Float
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable float.SvetovidIOException
- if an error occurred during the operation.
-
readDoubleMatrixBoxed
Reads multiple lines and converts the data to a double-precision floating-point matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
Double
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable double.SvetovidIOException
- if an error occurred during the operation.
-
readCharMatrixBoxed
Reads multiple lines and converts the data to a character matrix. The matrix is read row by row until an empty row is found or the end of input is reached.- Returns:
- a matrix of
Character
values read. - Throws:
SvetovidFormatException
- if one of the read values is not a parsable character.SvetovidIOException
- if an error occurred during the operation.
-
readObject
Reads a JSON (JavaScript Object Notation) formatted object.The object is converted to Java types using the following rules:
- literal
null
is converted to Javanull
, - literals
true
andfalse
are converted toBoolean.TRUE
andBoolean.FALSE
respectively, - numbers are converted to an instance of the first numeric type from
the following list that can hold the value read:
Byte
,Short
,Integer
,Long
,Float
,Double
,BigInteger
,BigDecimal
, - strings are converted to
String
values, - arrays are converted to
List
s containing the held values in the same order - and objects are converted to
Map
s that can be iterated in the order in which its members were defined. Each member's value is registered in the map under its name.
- Returns:
- a Java Object parsed form the JSON format according to the above rules.
- Throws:
SvetovidFormatException
- if the object to be read is not in the JSON format.SvetovidIOException
- if an error occurred during the operation.
- literal
-