java.lang.Object
org.seppiko.commons.utils.StreamUtil
File and Stream Util
- Author:
- Leonard Woo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
exportOutputStream
(byte[] bytes, OutputStream os) export byte array to output streamstatic File
Find and load file from pathnamestatic InputStream
findFileInputStream
(Class<?> clazz, String pathname) Find and load file from pathnamestatic InputStream
Get file streamstatic InputStream
Find and get file steamstatic InputStream
Get file streamstatic File
Load the target file and create it if it fails.static BufferedReader
Load reader from InputStreamstatic BufferedReader
loadReader
(InputStream is, Charset charset) Load inputstram to reader with charsetstatic BufferedReader
loadString
(String str) Load string to readerstatic String
readerToString
(BufferedReader reader) Convert reader all to Stringstatic String
readerToString
(BufferedReader reader, boolean lineStrip, boolean ignoreNewLine) Convert reader to Stringstatic void
Write byte array to filestatic Writer
Write file If not exist create itstatic Writer
Write file If not exist create it
-
Constructor Details
-
StreamUtil
public StreamUtil()
-
-
Method Details
-
findFileInputStream
Find and load file from pathname- Parameters:
clazz
- classloader loading pointpathname
- relative path- Returns:
- file input stream if file not found is null
-
findFile
Find and load file from pathname- Parameters:
clazz
- classloader loading pointpathname
- relative path- Returns:
- file
-
loadFile
Load the target file and create it if it fails.- Parameters:
path
- file pathname- Returns:
- target file
- Throws:
IllegalArgumentException
- File could not be loadedIOException
- The path is a folder address or failed to create a subfolder.
-
getStream
Find and get file steam- Parameters:
clazz
- classloader loading pointpathname
- relative path- Returns:
- File input stream if not found is null
-
getStream
Get file stream- Parameters:
filepath
- File path- Returns:
- File input stream if file not found is null
-
getStream
Get file stream- Parameters:
file
- File object- Returns:
- File input stream if file not found is null
-
loadString
Load string to reader- Parameters:
str
- String- Returns:
- Reader
-
loadReader
Load reader from InputStream- Parameters:
is
- Inputstream- Returns:
- Reader
-
loadReader
Load inputstram to reader with charset- Parameters:
is
- Inputstreamcharset
- Charest seeStandardCharsets
- Returns:
- Reader
-
exportOutputStream
export byte array to output stream- Parameters:
bytes
- byte arrayos
- output stream- Throws:
IOException
- byte array write failed
-
readerToString
public static String readerToString(BufferedReader reader, boolean lineStrip, boolean ignoreNewLine) throws IOException Convert reader to String- Parameters:
reader
- reader objectlineStrip
- true - remote every line begin and end whitespaceignoreNewLine
- true - read all content without new line- Returns:
- reader content without newline char
- Throws:
IOException
- read exception
-
readerToString
Convert reader all to String- Parameters:
reader
- reader object- Returns:
- reader content
- Throws:
IOException
- read exception
-
writeFile
Write file If not exist create it- Parameters:
pathname
- file out path- Returns:
- file writer
- Throws:
IOException
- file create or file writer exception
-
writeFile
Write file If not exist create it- Parameters:
file
- file object- Returns:
- file writer
- Throws:
IOException
- file create or file writer exception
-
writeFile
Write byte array to file- Parameters:
b
- bytesfile
- File- Throws:
IOException
- I/O exception
-