Class ReadWriteUtils

java.lang.Object
com.polytechnik.utils.ReadWriteUtils

public abstract class ReadWriteUtils extends Object
A class with a variety of helper functions.
  • Field Details

  • Constructor Details

    • ReadWriteUtils

      public ReadWriteUtils()
  • Method Details

    • getTokenizer

      public static final StreamTokenizer getTokenizer(String separators, Reader br)
      Create stream tokenizer with the settings we need.
    • readOneLine

      public static final int readOneLine(StreamTokenizer tk, String[] arraytosave) throws IOException
      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

      public static final String[] readOneLine(StreamTokenizer tk) throws IOException
      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

      public static final String[] extractnames(String str, String delim)
      Extract names.
    • 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

      public static final int elementIndex(String[] array, String element)
      Checkes for a given element in an array.
    • extractNumbers

      public static final int[] extractNumbers(String[] array) throws NumberFormatException
      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

      public static final String[] getStreamContent(InputStream[] streams) throws IOException
      Throws:
      IOException
    • getFileContent

      public static final String getFileContent(String filename) throws IOException
      This method reads all the data from a file.
      Throws:
      IOException
    • getFileContent

      public static final String getFileContent(File file) throws IOException
      This method reads all the data from a file.
      Throws:
      IOException
    • getStreamBytes

      public static final byte[] getStreamBytes(InputStream stream) throws IOException
      Throws:
      IOException
    • getFileBytes

      public static final byte[] getFileBytes(String filename) throws IOException
      Throws:
      IOException
    • getLong

      public static final long getLong(String s, long defaultvalue)
      Extracts long from a string. This method extracts long value from a string. it uses defaultvalue if the string is not a number.
    • getDouble

      public static final double getDouble(String s, double defaultvalue)
      Extracts double from a string.
    • getInteger

      public static final int getInteger(String s, int defaultvalue)
      Extracts integer from a string.