java.lang.Object
org.seppiko.commons.utils.StreamUtil
File and Stream Util
- Author:
- Leonard Woo
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopy(InputStream is, OutputStream os)Deprecated.static 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 BufferedReaderloadReader(InputStream is)Load reader from InputStreamstatic BufferedReaderloadReader(InputStream is, Charset charset)Load inputstram to reader with charsetstatic BufferedReaderloadString(String str)Load string to readerstatic StringreaderToString(BufferedReader reader, 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
-
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 ignoreNewLine) throws IOExceptionConvert reader to String- Parameters:
reader- ReaderignoreNewLine- true - read all content without new line- Returns:
- reader content without newline char
- 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
-
copy
Deprecated.Copy inputstream to outputstream- Parameters:
is- InputStreamos- OutputStream- Throws:
IOException- I/O exception
-