Package de.stefanfrings.utils
Class TextReader
- java.lang.Object
-
- de.stefanfrings.utils.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 Summary
Constructors Constructor Description TextReader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
readText(CombinedURL url, int connTimeout, int readTimeout, String defaultEncoding)
Read text from an URL into a String.static String
readText(File file, String encoding)
Read text from a File into a String and then close the connection.static String
readText(InputStream is, String encoding)
Read text from an InputStream into a String and then close the connection.static String
readText(URLConnection con, String defaultEncoding)
Read text from an URLConnection into a String and then close the connection.static String
readText(URL url, String defaultEncoding)
Read text from a local URL into a String.
-
-
-
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 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
public static String readText(URL url, String defaultEncoding) throws IOException
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
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 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
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 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.
-
-