Class TextReader


  • public class TextReader
    extends Object
    Read content from local or remote text files into a String.
    Author:
    Stefan Frings, http://stefanfrings.de/javautils
    • Constructor Detail

      • TextReader

        public TextReader()
    • Method Detail

      • readText

        public static String readText​(URLConnection con,
                                      String defaultEncoding)
                               throws IOException
        Read text from an URLConnection into a String and then close the connection.
        Parameters:
        con - An open URLConnection
        defaultEncoding - Expected encoding, used if the protocol if the connection does not provide this information.
        Returns:
        The text document
        Throws:
        IOException - In case of an I/O error.
      • readText

        public static String readText​(CombinedURL url,
                                      int connTimeout,
                                      int readTimeout,
                                      String defaultEncoding)
                               throws IOException
        Read text from an URL into a String.
        Parameters:
        url - Source URL
        connTimeout - Timeout connectng to the server
        readTimeout - Timeout reading the from the server
        defaultEncoding - Expected encoding, used if the connection does not provide this information.
        Returns:
        The text document
        Throws:
        IOException - In case of an I/O error.
      • readText

        public static String readText​(File file,
                                      String encoding)
                               throws IOException
        Read text from a File into a String and then close the connection.
        Parameters:
        file - The source file
        encoding - Encoding of the file, null is allowed to use the default
        Returns:
        The text document
        Throws:
        IOException - In case of an I/O error.
      • readText

        public static String readText​(InputStream is,
                                      String encoding)
                               throws IOException
        Read text from an InputStream into a String and then close the connection.
        Parameters:
        is - The source input stream
        encoding - Encoding of the file, null is allowed to use the default
        Returns:
        The text document
        Throws:
        IOException - In case of an I/O error.