Package org.seppiko.commons.utils
Class StreamUtil
java.lang.Object
org.seppiko.commons.utils.StreamUtil
public class StreamUtil
extends java.lang.Object
File and Stream Util
- Author:
- Leonard Woo
-
Constructor Summary
Constructors Constructor Description StreamUtil() -
Method Summary
Modifier and Type Method Description static voidcopy(java.io.InputStream is, java.io.OutputStream os)Copy inputstream to outputstreamstatic java.io.InputStreamfindFile(java.lang.Class<?> clazz, java.lang.String path)Find and load file from pathnamestatic java.io.InputStreamgetStream(java.io.File file)Get file streamstatic java.io.InputStreamgetStream(java.lang.String filepath)Get file streamstatic java.io.BufferedReaderloadReader(java.io.InputStream is)Load reader from InputStreamstatic java.io.BufferedReaderloadReader(java.io.InputStream is, java.nio.charset.Charset charset)Load inputstram to reader with charsetstatic java.io.BufferedReaderloadString(java.lang.String str)Load string to readerstatic java.lang.StringreaderToString(java.io.BufferedReader reader)Convert reader to Stringstatic voidtoFile(byte[] b, java.io.File file)Output to filestatic java.io.WriterwriteFile(java.io.File file)Write file If not exist create itstatic java.io.WriterwriteFile(java.lang.String pathname)Write file If not exist create itMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
StreamUtil
public StreamUtil()
-
-
Method Details
-
findFile
public static java.io.InputStream findFile(java.lang.Class<?> clazz, java.lang.String path) throws java.io.FileNotFoundExceptionFind and load file from pathname- Parameters:
clazz- classloader loading pointpath- relative path- Returns:
- file input stream
- Throws:
java.io.FileNotFoundException- file not found
-
getStream
public static java.io.InputStream getStream(java.lang.String filepath) throws java.io.FileNotFoundExceptionGet file stream- Parameters:
filepath- File path- Returns:
- File input stream
- Throws:
java.io.FileNotFoundException- File not found
-
getStream
public static java.io.InputStream getStream(java.io.File file) throws java.io.FileNotFoundExceptionGet file stream- Parameters:
file- File object- Returns:
- File input stream
- Throws:
java.io.FileNotFoundException- File not found
-
loadString
public static java.io.BufferedReader loadString(java.lang.String str)Load string to reader- Parameters:
str- String- Returns:
- Reader
-
loadReader
public static java.io.BufferedReader loadReader(java.io.InputStream is)Load reader from InputStream- Parameters:
is- Inputstream- Returns:
- Reader
-
loadReader
public static java.io.BufferedReader loadReader(java.io.InputStream is, java.nio.charset.Charset charset)Load inputstram to reader with charset- Parameters:
is- Inputstreamcharset- Charest seeStandardCharsets- Returns:
- Reader
-
readerToString
public static java.lang.String readerToString(java.io.BufferedReader reader) throws java.io.IOExceptionConvert reader to String- Parameters:
reader- Reader- Returns:
- reader content without newline char
- Throws:
java.io.IOException- read exception
-
writeFile
public static java.io.Writer writeFile(java.lang.String pathname) throws java.io.IOExceptionWrite file If not exist create it- Parameters:
pathname- file out path- Returns:
- file writer
- Throws:
java.io.IOException- file create or file writer exception
-
writeFile
public static java.io.Writer writeFile(java.io.File file) throws java.io.IOExceptionWrite file If not exist create it- Parameters:
file- file object- Returns:
- file writer
- Throws:
java.io.IOException- file create or file writer exception
-
toFile
public static void toFile(byte[] b, java.io.File file) throws java.io.IOExceptionOutput to file- Parameters:
b- bytesfile- File- Throws:
java.io.IOException- I/O exception
-
copy
public static void copy(java.io.InputStream is, java.io.OutputStream os) throws java.io.IOExceptionCopy inputstream to outputstream- Parameters:
is- InputStreamos- OutputStream- Throws:
java.io.IOException- I/O exception
-