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 TypeMethodDescriptionvoidclose()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.booleanhasMore()Checks whether this reader has data to be read.booleanisEmpty()Checks whether this reader has no more data to be read.booleanReturns 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.booleanreadBool()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.bytereadByte()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.charreadChar()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.doubleReads 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.floatReads 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.intreadInt()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.longreadLong()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.shortReads 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.voidsetThrowingExceptions(boolean shouldThrow) Configures whether this reader should throw exceptions on I/O operation errors or just return default values.voidsetWhitespace(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:
trueif this reader throws exceptions on failed I/O operations;falseotherwise.
-
setThrowingExceptions
void setThrowingExceptions(boolean shouldThrow) Configures whether this reader should throw exceptions on I/O operation errors or just return default values.- Parameters:
shouldThrow-trueif this reader should throw exceptions on failed I/O operations in the future;falseif 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
nullit the operation was successful.
-
isEmpty
boolean isEmpty()Checks whether this reader has no more data to be read.- Returns:
trueif this reader has no more data to be read;falseotherwise.
-
hasMore
boolean hasMore()Checks whether this reader has data to be read.- Returns:
trueif this reader has data to be read;falseotherwise.
-
close
Closes this reader and releases any resources associated with the underlying source. The general contract ofcloseis that it closes the input source. A closed source cannot perform input operations and cannot be reopened.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
SvetovidIOException- if an error occurred during the operation.
-
readBool
Reads one token and converts it to a boolean value.- Returns:
- the
booleanvalue 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
bytevalue 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
shortvalue 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
intvalue 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
longvalue 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
floatvalue 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
doublevalue 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
charvalue 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
Stringvalue 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
Booleanvalue 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
Bytevalue 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
Shortvalue 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
Integervalue 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
Longvalue 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
Floatvalue 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
Doublevalue 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
Charactervalue 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
booleanvalues 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
bytevalues 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
shortvalues 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
intvalues 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
longvalues 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
floatvalues 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
doublevalues 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
charvalues 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
Stringvalues 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
Booleanvalues 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
Bytevalues 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
Shortvalues 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
Integervalues 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
Longvalues 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
Floatvalues 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
Doublevalues 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
Charactervalues 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
Stringcontaining 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
Stringarray 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
Stringcontaining 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
booleanvalues 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
bytevalues 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
shortvalues 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
intvalues 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
longvalues 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
floatvalues 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
doublevalues 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
charvalues 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
Stringvalues 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
Booleanvalues 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
Bytevalues 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
Shortvalues 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
Integervalues 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
Longvalues 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
Floatvalues 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
Doublevalues 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
Charactervalues 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
nullis converted to Javanull, - literals
trueandfalseare converted toBoolean.TRUEandBoolean.FALSErespectively, - 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
Stringvalues, - arrays are converted to
Lists containing the held values in the same order - and objects are converted to
Maps 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
-