Class IO


  • public class IO
    extends java.lang.Object
    Helper class for all standard i/o methods.
    Since:
    08.04.2015 10:27:40
    Author:
    Nico Danneberg
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private IO()
      No instances wanted!
    • Method Summary

      Modifier and Type Method Description
      static void debug​(java.lang.String msg)
      Offers a simple way to print out a debug message.
      static void debugln​(java.lang.String msg)
      Uses debug(String) with an additional "\n" at the end.
      static java.lang.String i2s​(int value)
      Transforms a given primitive integer into a string.
      static void info​(java.lang.String msg)
      Offers a simple way to print out an info message.
      static void infoln​(java.lang.String msg)
      Uses info(String) with an additional "\n" at the end.
      static java.lang.String join​(int[] arr, java.lang.String glue)
      Joins all elements of the given array to a String and uses the glue as separator.
      static java.lang.String join​(long[] arr, java.lang.String glue)
      Joins all elements of the given array to a String and uses the glue as separator.
      static java.lang.String join​(java.lang.Object[] arr, java.lang.String glue)
      Joins all elements of the given array to a String and uses the glue as separator.
      static java.lang.String l2s​(long value)
      Transforms a given primitive long into a string.
      static byte[] readBytes​(java.lang.String file, java.lang.String sep)
      Tries to read one line of byte values split by the given separator
      static short[] readDigits​(java.lang.String file, int max)
      Tries to read the given number of digits from the given file.
      static LargeNumber[] readLargeNumbers​(java.lang.String file, int max)
      Reads the wanted number of large numbers from the given file.
      static java.lang.String[] readSortedStrings​(java.lang.String file)
      Reads all strings from the given file sorting them while reading directly.
      static java.lang.String[] readStrings​(java.lang.String file)
      Reads all lines from the given file and creates an array with one entry per line.
      static java.util.ArrayList<java.lang.Integer[]> readTriangle​(java.lang.String file)
      Reads integer values from the given text file in a triangle form.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IO

        private IO()
        No instances wanted!
    • Method Detail

      • debug

        public static void debug​(java.lang.String msg)
        Offers a simple way to print out a debug message. Internally the print method of System.err is used.
        Parameters:
        msg - - the message to be displayed
      • debugln

        public static void debugln​(java.lang.String msg)
        Uses debug(String) with an additional "\n" at the end.
        Parameters:
        msg - - the message to be displayed with a newline at the end
      • info

        public static void info​(java.lang.String msg)
        Offers a simple way to print out an info message. Internally the print method of System.out is used.
        Parameters:
        msg - - the message to be displayed
      • infoln

        public static void infoln​(java.lang.String msg)
        Uses info(String) with an additional "\n" at the end.
        Parameters:
        msg - - the message to be displayed with a newline at the end
      • i2s

        public static java.lang.String i2s​(int value)
        Transforms a given primitive integer into a string.
        Parameters:
        value - - the integer number to be transformed
        Returns:
        the string representation of the given integer
      • l2s

        public static java.lang.String l2s​(long value)
        Transforms a given primitive long into a string.
        Parameters:
        value - the long number to be transformed
        Returns:
        the string representation of the given long
      • join

        public static java.lang.String join​(int[] arr,
                                            java.lang.String glue)
        Joins all elements of the given array to a String and uses the glue as separator.
        Parameters:
        arr - the source integer list
        glue - the string that will be placed between the elements
        Returns:
        one string of with all elements
      • join

        public static java.lang.String join​(long[] arr,
                                            java.lang.String glue)
        Joins all elements of the given array to a String and uses the glue as separator.
        Parameters:
        arr - the source integer list
        glue - the string that will be placed between the elements
        Returns:
        one string of with all elements
      • join

        public static java.lang.String join​(java.lang.Object[] arr,
                                            java.lang.String glue)
        Joins all elements of the given array to a String and uses the glue as separator.
        Parameters:
        arr - the source object list
        glue - the string that will be placed between the elements
        Returns:
        one string of with all elements
      • readBytes

        public static byte[] readBytes​(java.lang.String file,
                                       java.lang.String sep)
        Tries to read one line of byte values split by the given separator
        Parameters:
        file - the file to read from
        sep - the separator between the values
        Returns:
        an array of byte values
      • readDigits

        public static short[] readDigits​(java.lang.String file,
                                         int max)
        Tries to read the given number of digits from the given file. Any exception is caught and results in a null return.
        Parameters:
        file - the file to read from
        max - the maximum number of digits to read
        Returns:
        an array of digits
      • readLargeNumbers

        public static LargeNumber[] readLargeNumbers​(java.lang.String file,
                                                     int max)
        Reads the wanted number of large numbers from the given file.
        Parameters:
        file - the file to read from
        max - the maximum number to read in
        Returns:
        an array of large numbers
      • readSortedStrings

        public static java.lang.String[] readSortedStrings​(java.lang.String file)
        Reads all strings from the given file sorting them while reading directly.
        Parameters:
        file - the file to read from
        Returns:
        a sorted array of strings
      • readStrings

        public static java.lang.String[] readStrings​(java.lang.String file)
        Reads all lines from the given file and creates an array with one entry per line.
        Parameters:
        file - the file to read from
        Returns:
        an array of strings
      • readTriangle

        public static java.util.ArrayList<java.lang.Integer[]> readTriangle​(java.lang.String file)
        Reads integer values from the given text file in a triangle form.
        Parameters:
        file - the file to read from
        Returns:
        an ArrayList of Integer arrays