java.lang.Object
org.seppiko.commons.utils.StreamUtil
File and Stream Util
- Author:
- Leonard Woo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidexportOutputStream(byte[] bytes, OutputStream os) export byte array to output streamstatic FileFind and load file from pathnamestatic InputStreamfindFileInputStream(Class<?> clazz, String pathname) Find and load file from pathnamestatic InputStreamGet file streamstatic InputStreamFind and get file steamstatic InputStreamGet file streamstatic FileLoad the target file and create it if it fails.static BufferedReaderLoad reader from InputStreamstatic BufferedReaderloadReader(InputStream is, Charset charset) Load inputstram to reader with charsetstatic BufferedReaderloadString(String str) Load string to readerstatic StringreaderToString(BufferedReader reader) Convert reader all to Stringstatic StringreaderToString(BufferedReader reader, boolean lineStrip, boolean ignoreNewLine) Convert reader to Stringstatic voidWrite byte array to filestatic WriterWrite file If not exist create itstatic WriterWrite 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
-