Package com.polytechnik.utils
Class ReadWriteUtils
java.lang.Object
com.polytechnik.utils.ReadWriteUtils
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final int
elementIndex
(int[] array, int element) Checkes for a given element in an array.static final int
elementIndex
(long[] array, long element) Checkes for a given element in an array.static final int
elementIndex
(String[] array, String element) Checkes for a given element in an array.static final String[]
extractnames
(String str, String delim) Extract names.static final int[]
extractNumbers
(String[] array) This method extracts integer numbers from a string array.static final int
getArrayAsBits
(int[] data, int[] bits) Encodes an array of integers as bits.static final int[]
getBitsAsArray
(int data, int[] bits) Decodes an integer to array.static final double
Extracts double from a string.static final byte[]
getFileBytes
(String filename) static final String
getFileContent
(File file) This method reads all the data from a file.static final String
getFileContent
(String filename) This method reads all the data from a file.static final int
getInteger
(String s, int defaultvalue) Extracts integer from a string.static final long
Extracts long from a string.static final String
getparameter
(String name, ResourceBundle resources, boolean mustbeset) Reads a parameter from a configurartion file.static final ResourceBundle
getProperties
(String fname) Reads properties.static final byte[]
getStreamBytes
(InputStream stream) static final String[]
getStreamContent
(InputStream[] streams) static final StreamTokenizer
getTokenizer
(String separators, Reader br) Create stream tokenizer with the settings we need.static final boolean
hasElement
(int[] array, int element) Checkes for a given element in an array.static int
processStreamByLines
(String stream_id, StreamTokenizer tk, Predicate<String[]> header_processor, Predicate<String[]> processor) static final ReadWriteUtils.ReadNameValue[]
readAllParameters
(String allparameters, String[] namestoread, ResourceBundle resources) Reads given parameters from a properties.static final String[]
This method reads one line from a stream.static final int
readOneLine
(StreamTokenizer tk, String[] arraytosave) This method reads one line from a stream.static final String[]
readParameters
(String prefix, String[] parameters, ResourceBundle resources) Reads parameters from config using a given prefix.
-
Field Details
-
PROPERTYPREFIX
-
PARAMSEPARATOR
- See Also:
-
-
Constructor Details
-
ReadWriteUtils
public ReadWriteUtils()
-
-
Method Details
-
getTokenizer
Create stream tokenizer with the settings we need. -
readOneLine
This method reads one line from a stream.- Parameters:
tk
- The StreamTokenizer to read data from.arraytosave
- An array to store read data.- Returns:
- The number of words in line.
- Throws:
IOException
-
readOneLine
This method reads one line from a stream.- Parameters:
tk
- The StreamTokenizer to read data from.- Returns:
- Read line.
- Throws:
IOException
-
processStreamByLines
public static int processStreamByLines(String stream_id, StreamTokenizer tk, Predicate<String[]> header_processor, Predicate<String[]> processor) throws IOException - Throws:
IOException
-
extractnames
-
getProperties
public static final ResourceBundle getProperties(String fname) throws MissingResourceException, IOException Reads properties. A prefix may be added to property name if a special system property is set.- Throws:
MissingResourceException
IOException
-
readParameters
public static final String[] readParameters(String prefix, String[] parameters, ResourceBundle resources) throws MissingResourceException Reads parameters from config using a given prefix.- Throws:
MissingResourceException
-
readAllParameters
public static final ReadWriteUtils.ReadNameValue[] readAllParameters(String allparameters, String[] namestoread, ResourceBundle resources) throws MissingResourceException Reads given parameters from a properties.- Throws:
MissingResourceException
-
getparameter
public static final String getparameter(String name, ResourceBundle resources, boolean mustbeset) throws MissingResourceException Reads a parameter from a configurartion file.- Throws:
MissingResourceException
-
hasElement
public static final boolean hasElement(int[] array, int element) Checkes for a given element in an array. -
elementIndex
public static final int elementIndex(int[] array, int element) Checkes for a given element in an array. -
elementIndex
-
extractNumbers
This method extracts integer numbers from a string array.- Throws:
NumberFormatException
-
elementIndex
public static final int elementIndex(long[] array, long element) Checkes for a given element in an array. -
getArrayAsBits
public static final int getArrayAsBits(int[] data, int[] bits) Encodes an array of integers as bits. -
getBitsAsArray
public static final int[] getBitsAsArray(int data, int[] bits) Decodes an integer to array. -
getStreamContent
- Throws:
IOException
-
getFileContent
This method reads all the data from a file.- Throws:
IOException
-
getFileContent
This method reads all the data from a file.- Throws:
IOException
-
getStreamBytes
- Throws:
IOException
-
getFileBytes
- Throws:
IOException
-
getLong
Extracts long from a string. This method extracts long value from a string. it uses defaultvalue if the string is not a number. -
getDouble
Extracts double from a string. -
getInteger
Extracts integer from a string.
-