Package de.stefanfrings.utils
Class TextReader
java.lang.Object
de.stefanfrings.utils.TextReader
Read content from local or remote text files into a String.
- Author:
- Stefan Frings, http://stefanfrings.de/javautils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringreadText(CombinedURL url, int connTimeout, int readTimeout, String defaultEncoding) Read text from an URL into a String.static StringRead text from a File into a String and then close the connection.static StringreadText(InputStream is, String encoding) Read text from an InputStream into a String and then close the connection.static StringreadText(URLConnection con, String defaultEncoding) Read text from an URLConnection into a String and then close the connection.static StringRead text from a local URL into a String.
-
Constructor Details
-
TextReader
public TextReader()
-
-
Method Details
-
readText
Read text from an URLConnection into a String and then close the connection.- Parameters:
con- An open URLConnectiondefaultEncoding- 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
Read text from a local URL into a String. To read from a remote URL, usereadText(CombinedURL url, int connTimeout, int readTimeout, String encoding)instead.- Parameters:
url- Source URLdefaultEncoding- 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(CombinedURL url, int connTimeout, int readTimeout, String defaultEncoding) throws IOException Read text from an URL into a String.- Parameters:
url- Source URLconnTimeout- Timeout connectng to the serverreadTimeout- Timeout reading the from the serverdefaultEncoding- 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
Read text from a File into a String and then close the connection.- Parameters:
file- The source fileencoding- 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
Read text from an InputStream into a String and then close the connection.- Parameters:
is- The source input streamencoding- Encoding of the file, null is allowed to use the default- Returns:
- The text document
- Throws:
IOException- In case of an I/O error.
-