public class IO extends Object
IO utilities
| Modifier and Type | Class and Description |
|---|---|
static class |
IO.BufferedImageReadStage |
static class |
IO.BufferedImageWriteStage |
static class |
IO.ByteBufferReadStage |
static class |
IO.CharSequenceReadStage |
static class |
IO.CharSequenceWriteStage
Implement a
IO.WriteStageBase for source of CharSequence. |
static class |
IO.F |
static class |
IO.FileReadStage |
static class |
IO.FileWriteStage |
static interface |
IO.InputStreamHandler
|
static class |
IO.InputStreamReadStage |
static class |
IO.InputStreamWriteStage |
static class |
IO.ReaderReadStage |
static class |
IO.ReaderWriteStage |
static class |
IO.ReadStageBase<SOURCE,STAGE extends IO.ReadStageBase> |
static class |
IO.SObjectReadStage |
static class |
IO.SObjectWriteStage |
static class |
IO.UrlReadStage |
static class |
IO.UrlWriteStage |
static class |
IO.WriteStageBase<SOURCE,STAGE extends IO.WriteStageBase>
A stage class support fluent IO write operations.
|
static class |
IO.XMLDocumentWriteStage |
| Constructor and Description |
|---|
IO() |
| Modifier and Type | Method and Description |
|---|---|
static void |
append(byte[] data,
OutputStream os)
Write binary data to an output stream without closing the outputstream.
|
static void |
append(byte b,
OutputStream outputStream)
Alias of
write(byte, OutputStream). |
static void |
append(CharSequence content,
Writer writer)
write content into a writer without closing the writer when finished.
|
static void |
append(char c,
Writer writer)
Alias of
write(char, Writer) |
static int |
append(InputStream is,
OutputStream os)
Copy content from input stream to output stream without closing the output stream.
|
static ByteArrayOutputStream |
baos()
Returns a byte array output stream
|
static BufferedInputStream |
buffered(InputStream is) |
static BufferedOutputStream |
buffered(OutputStream os) |
static BufferedReader |
buffered(Reader r) |
static BufferedWriter |
buffered(Writer w) |
static String |
checksum(byte[] ba) |
static String |
checksum(File file)
Returns checksum of a file.
|
static String |
checksum(InputStream is)
Returns checksum from an input stream.
|
static File |
child(File file,
String fn) |
static List<File> |
children(File file) |
static void |
close(Closeable closeable) |
static int |
copy(InputStream is,
OutputStream os)
Read from InputStream
is and write to OutputStream os. |
static int |
copy(InputStream is,
OutputStream os,
boolean closeOs)
Copy an stream to another one.
|
static int |
copy(Reader reader,
Writer writer)
Copy from a
Reader into a Writer. |
static int |
copy(Reader reader,
Writer writer,
boolean closeWriter)
Copy from a
Reader into a Writer. |
static void |
copyDirectory(File source,
File target) |
static void |
delete(File file) |
static void |
delete(File f,
boolean deleteChildren) |
static void |
flush(Flushable flushable) |
static void |
flush(ImageInputStream flushable) |
static void |
flush(ObjectOutput oo) |
static InputStream |
inputStream()
Returns an empty input stream
|
static InputStream |
inputStream(byte[] ba)
Create an input stream from given byte array.
|
static InputStream |
inputStream(File file)
Returns a file input stream
|
static InputStream |
inputStream(String content)
Create an input stream from string content which will be encoded with UTF-8
|
static InputStream |
inputStream(URL url)
Create an input stream from a URL.
|
static InputStream |
is()
Deprecated.
|
static InputStream |
is(byte[] ba)
Deprecated.
|
static InputStream |
is(File file)
Deprecated.
|
static InputStream |
is(String content)
Deprecated.
|
static InputStream |
is(URL url)
Deprecated.
|
static Properties |
loadProperties(File file)
Load properties from a file
|
static Properties |
loadProperties(InputStream inputStream)
Load properties from an inputStream
|
static Properties |
loadProperties(Reader reader)
Load properties from an inputStream
|
static Properties |
loadProperties(String content)
Load properties from a string content
|
static Properties |
loadProperties(URL url)
Load properties from a URL
|
static OutputStream |
os()
Deprecated.
|
static OutputStream |
os(File file)
Deprecated.
|
static OutputStream |
outputStream(File file)
Returns a file output stream
|
static File |
parent(File file) |
static IO.BufferedImageReadStage |
read(BufferedImage image) |
static IO.BufferedImageReadStage |
read(BufferedImage image,
String contentType) |
static IO.InputStreamReadStage |
read(byte[] bytes) |
static IO.ByteBufferReadStage |
read(ByteBuffer byteBuffer) |
static IO.CharSequenceReadStage |
read(CharSequence csq) |
static IO.FileReadStage |
read(File file) |
static IO.InputStreamReadStage |
read(InputStream inputStream) |
static IO.SObjectReadStage |
read(ISObject sobj) |
static IO.ReaderReadStage |
read(Reader reader) |
static IO.UrlReadStage |
read(URL url) |
static byte[] |
readContent(File file)
Read binary content of a file (warning does not use on large file !)
|
static byte[] |
readContent(InputStream is) |
static String |
readContentAsString(File file)
Read file content to a String (always use utf-8)
|
static String |
readContentAsString(File file,
String encoding)
Read file content to a String
|
static String |
readContentAsString(InputStream is) |
static String |
readContentAsString(InputStream is,
String encoding) |
static String |
readContentAsString(URL url)
Read file content to a String (always use utf-8)
|
static String |
readContentAsString(URL url,
String encoding)
Read file content to a String
|
static Reader |
reader()
Returns an empty reader
|
static Reader |
reader(byte[] ba) |
static Reader |
reader(File file)
Returns a file reader
|
static Reader |
reader(InputStream is) |
static Reader |
reader(String content)
Returns a string reader from a content specified
|
static Reader |
reader(URL url) |
static List<String> |
readLines(File file) |
static List<String> |
readLines(File file,
int limit) |
static List<String> |
readLines(File file,
String encoding) |
static List<String> |
readLines(File file,
String encoding,
int limit) |
static List<String> |
readLines(InputStream inputStream) |
static List<String> |
readLines(InputStream inputStream,
int limit) |
static List<String> |
readLines(InputStream is,
String encoding) |
static List<String> |
readLines(InputStream is,
String encoding,
int limit) |
static List<String> |
readLines(Reader input) |
static List<String> |
readLines(Reader input,
int limit) |
static List<String> |
readLines(URL url) |
static List<String> |
readLines(URL url,
int limit) |
static List<String> |
readLines(URL url,
String encode) |
static List<String> |
readLines(URL url,
String encode,
int limit) |
static void |
registerInputStreamHandler(MimeType.Trait trait,
IO.InputStreamHandler handler)
|
static void |
registerInputStreamHandler(MimeType type,
IO.InputStreamHandler handler)
Associate an
IO.InputStreamHandler with a specific MimeType |
static File |
tmpFile() |
static File |
tmpFile(String prefix,
String suffix) |
static File |
tmpFile(String prefix,
String suffix,
File dir) |
static IO.BufferedImageWriteStage |
write(BufferedImage img) |
static IO.BufferedImageWriteStage |
write(BufferedImage img,
String contentType) |
static IO.InputStreamWriteStage |
write(byte[] bytes) |
static void |
write(byte[] data,
File file)
Write binary data to a file
|
static void |
write(byte[] data,
OutputStream os)
Write binary data to an outputstream and then close the outputstream
|
static void |
write(byte[] data,
OutputStream os,
boolean closeSink)
Write binary data to an outputstream.
|
static IO.InputStreamWriteStage |
write(ByteBuffer byteBuffer) |
static void |
write(byte b,
OutputStream os)
Write a byte into outputstream.
|
static IO.CharSequenceWriteStage |
write(char[] chars) |
static IO.CharSequenceWriteStage |
write(CharSequence csq) |
static void |
write(CharSequence content,
File file)
Write string content to a file with UTF-8 encoding.
|
static void |
write(CharSequence content,
File file,
String encoding)
Write String content to a file with encoding specified
|
static void |
write(CharSequence content,
Writer writer)
Write content into a writer and close the writer.
|
static void |
write(CharSequence content,
Writer writer,
boolean closeOs)
Write content into a writer.
|
static void |
write(char c,
Writer writer)
Write a character to a
Writer. |
static IO.XMLDocumentWriteStage |
write(Document document) |
static IO.FileWriteStage |
write(File file) |
static IO.InputStreamWriteStage |
write(InputStream inputStream) |
static int |
write(InputStream is,
File f)
Read from inputstream and write into file.
|
static int |
write(InputStream is,
OutputStream os)
|
static int |
write(InputStream is,
OutputStream os,
boolean closeSink)
|
static IO.SObjectWriteStage |
write(ISObject sobj) |
static IO.ReaderWriteStage |
write(Reader reader) |
static int |
write(Reader reader,
Writer writer)
Alias of
copy(Reader, Writer) |
static int |
write(Reader reader,
Writer writer,
boolean closeWriter)
Alias of
copy(Reader, Writer, boolean) |
static IO.UrlWriteStage |
write(URL url) |
static void |
writeContent(CharSequence content,
File file)
Deprecated.
|
static void |
writeContent(CharSequence content,
File file,
String encoding)
Deprecated.
|
static void |
writeContent(CharSequence content,
Writer writer)
Deprecated.
|
static Writer |
writer()
Returns a string writer
|
static Writer |
writer(File file)
Returns a file writer
|
static File |
zip(File... files)
Zip a list of files into a single file.
|
static ISObject |
zip(ISObject... objects)
Zip a list of sobject into a single sobject.
|
static void |
zipInto(File target,
File... files)
Zip a list of files into specified target file.
|
public static void registerInputStreamHandler(MimeType type, IO.InputStreamHandler handler)
Associate an IO.InputStreamHandler with a specific MimeType
type - The mimetype the handler listen tohandler - the handlerpublic static void registerInputStreamHandler(MimeType.Trait trait, IO.InputStreamHandler handler)
Register an IO.InputStreamHandler with all mime types by MimeType.Trait.
trait - the trait of mimetypehandler - the input stream handlerpublic static IO.CharSequenceWriteStage write(CharSequence csq)
public static IO.ReaderWriteStage write(Reader reader)
public static IO.InputStreamWriteStage write(InputStream inputStream)
public static IO.InputStreamWriteStage write(byte[] bytes)
public static IO.FileWriteStage write(File file)
public static IO.UrlWriteStage write(URL url)
public static IO.BufferedImageWriteStage write(BufferedImage img)
public static IO.BufferedImageWriteStage write(BufferedImage img, String contentType)
public static IO.XMLDocumentWriteStage write(Document document)
public static IO.InputStreamWriteStage write(ByteBuffer byteBuffer)
public static IO.SObjectWriteStage write(ISObject sobj)
public static IO.CharSequenceReadStage read(CharSequence csq)
public static IO.CharSequenceWriteStage write(char[] chars)
public static IO.ReaderReadStage read(Reader reader)
public static IO.InputStreamReadStage read(InputStream inputStream)
public static IO.SObjectReadStage read(ISObject sobj)
public static IO.InputStreamReadStage read(byte[] bytes)
public static IO.ByteBufferReadStage read(ByteBuffer byteBuffer)
public static IO.UrlReadStage read(URL url)
public static IO.FileReadStage read(File file)
public static IO.BufferedImageReadStage read(BufferedImage image)
public static IO.BufferedImageReadStage read(BufferedImage image, String contentType)
public static void close(Closeable closeable)
public static void flush(Flushable flushable)
public static void flush(ObjectOutput oo)
public static void flush(ImageInputStream flushable)
public static File tmpFile()
@Deprecated public static OutputStream os()
Returns a byte array output stream.
This method is deprecated. Please use baos() instead
public static ByteArrayOutputStream baos()
Returns a byte array output stream
public static OutputStream outputStream(File file)
Returns a file output stream
file - the file to which the returned output stream can be used to write to@Deprecated public static OutputStream os(File file)
Returns a file output stream.
Use outputStream(File) to replace this method.
file - the file to which the returned output stream can be used to write topublic static Writer writer()
Returns a string writer
public static Writer writer(File file)
Returns a file writer
file - the file to be writtenpublic static InputStream inputStream()
Returns an empty input stream
@Deprecated public static InputStream is()
Returns an empty input stream.
Use inputStream() to replace this method.
public static InputStream inputStream(File file)
Returns a file input stream
file - the file to be read@Deprecated public static InputStream is(File file)
Returns a file input stream.
Use inputStream(File) to replace this method
file - the file to be readpublic static InputStream inputStream(byte[] ba)
Create an input stream from given byte array.
ba - the byte array@Deprecated public static InputStream is(byte[] ba)
Use inputStream(byte[]) to replace this method
ba - public static InputStream inputStream(String content)
Create an input stream from string content which will be encoded with UTF-8
content - the string content@Deprecated public static InputStream is(String content)
Returns an input stream from a string which will be encoded with CharSet.defaultCharset().
use inputStream(String) to replace this method.
content - the content to be readpublic static InputStream inputStream(URL url)
Create an input stream from a URL.
url - the URL.@Deprecated public static InputStream is(URL url)
Use inputStream(URL) to replace this method.
public static Reader reader()
Returns an empty reader
public static Reader reader(File file)
Returns a file reader
file - the file to be readpublic static Reader reader(byte[] ba)
public static Reader reader(InputStream is)
public static Reader reader(String content)
Returns a string reader from a content specified
content - the content to be readpublic static BufferedOutputStream buffered(OutputStream os)
public static BufferedInputStream buffered(InputStream is)
public static BufferedWriter buffered(Writer w)
public static BufferedReader buffered(Reader r)
public static String checksum(File file)
Returns checksum of a file.
file - the filepublic static String checksum(InputStream is)
Returns checksum from an input stream.
is - the inputstreampublic static String checksum(byte[] ba)
public static void delete(File file)
public static void delete(File f, boolean deleteChildren)
public static Properties loadProperties(URL url)
Load properties from a URL
url - the URL of the properties filepublic static Properties loadProperties(File file)
Load properties from a file
file - the properties filepublic static Properties loadProperties(InputStream inputStream)
Load properties from an inputStream
inputStream - the input stream to property sourcepublic static Properties loadProperties(Reader reader)
Load properties from an inputStream
reader - the reader to property sourcepublic static Properties loadProperties(String content)
Load properties from a string content
content - the content of a properties filepublic static byte[] readContent(File file)
Read binary content of a file (warning does not use on large file !)
file - The file te readpublic static byte[] readContent(InputStream is)
public static String readContentAsString(File file)
Read file content to a String (always use utf-8)
file - The file to readpublic static String readContentAsString(URL url, String encoding)
Read file content to a String
url - The url resource to readencoding - encoding used to read the file into string contentpublic static String readContentAsString(URL url)
Read file content to a String (always use utf-8)
url - the url resource to readpublic static String readContentAsString(File file, String encoding)
Read file content to a String
file - The file to readencoding - encoding used to read the file into string contentpublic static String readContentAsString(InputStream is)
public static String readContentAsString(InputStream is, String encoding)
public static List<String> readLines(InputStream is, String encoding)
public static List<String> readLines(InputStream is, String encoding, int limit)
public static List<String> readLines(InputStream inputStream)
public static List<String> readLines(InputStream inputStream, int limit)
@Deprecated public static void writeContent(CharSequence content, File file)
Write String content to a file (always use utf-8).
This method is deprecated. Please use write(CharSequence, File) instead
content - The content to writefile - The file to write@Deprecated public static void writeContent(CharSequence content, File file, String encoding)
Write string content to a file with encoding specified.
This is deprecated. Please use write(CharSequence, File, String) instead
@Deprecated public static void writeContent(CharSequence content, Writer writer)
Write content into a writer.
This method is deprecated. Please use write(CharSequence, Writer) instead.
public static void write(CharSequence content, File file)
Write string content to a file with UTF-8 encoding.
content - the content to be written to the filefile - the file to which the content be written topublic static void write(CharSequence content, File file, String encoding)
Write String content to a file with encoding specified
content - The content to writefile - The file to writeencoding - encoding used to write the content to filepublic static void write(char c,
Writer writer)
Write a character to a Writer.
The writer is leave open after the character after writing.
c - the character to be writtenwriter - the writer to which the character is writtenpublic static void append(char c,
Writer writer)
Alias of write(char, Writer)
public static void append(CharSequence content, Writer writer)
write content into a writer without closing the writer when finished.
content - the content to be written to the writerwriter - to where the content be writtenpublic static void write(CharSequence content, Writer writer)
Write content into a writer and close the writer.
content - the content to be written to the writerwriter - to where the content be writtenpublic static void write(CharSequence content, Writer writer, boolean closeOs)
Write content into a writer.
content - the content to be written to the writerwriter - to where the content be writtenpublic static int append(InputStream is, OutputStream os)
Copy content from input stream to output stream without closing the output stream.
The input stream is closed anyway.
is - input streamos - output streampublic static int copy(InputStream is, OutputStream os)
Read from InputStream is and write to OutputStream os.
After writing both input stream and output stream are closed.
is - The input streamos - The output streampublic static int write(InputStream is, OutputStream os)
public static int copy(InputStream is, OutputStream os, boolean closeOs)
Copy an stream to another one. It close the input stream anyway.
If the param closeOs is true then close the output stream.
is - input streamos - output streamcloseOs - specify whether it shall close output stream after operationpublic static int write(InputStream is, OutputStream os, boolean closeSink)
public static int write(InputStream is, File f)
Read from inputstream and write into file.
is - the inputstreamf - the filepublic static int copy(Reader reader, Writer writer)
Copy from a Reader into a Writer.
Both reader and writer are closed.
reader - A reader - the sourcewriter - a writer - the targetpublic static int copy(Reader reader, Writer writer, boolean closeWriter)
Copy from a Reader into a Writer.
reader - A reader - the sourcewriter - a writer - the targetcloseWriter - indicate if it shall close the writer after operationpublic static void write(byte b,
OutputStream os)
Write a byte into outputstream.
The outputstream is not closed after written.
b - the byte to be writtenos - the output stream into which the byte is writtenpublic static void append(byte b,
OutputStream outputStream)
Alias of write(byte, OutputStream).
public static void write(byte[] data,
File file)
Write binary data to a file
data - The binary data to writefile - The file to writepublic static void write(byte[] data,
OutputStream os)
Write binary data to an outputstream and then close the outputstream
data - the binary data to writeos - the output streampublic static void append(byte[] data,
OutputStream os)
Write binary data to an output stream without closing the outputstream.
data - the binary data to be written.os - the output stream to which the binary data is writtenpublic static void write(byte[] data,
OutputStream os,
boolean closeSink)
Write binary data to an outputstream.
data - the binary data to writeos - the output streamcloseSink - if true then close the output stream once finished writingpublic static int write(Reader reader, Writer writer)
Alias of copy(Reader, Writer)
public static int write(Reader reader, Writer writer, boolean closeWriter)
Alias of copy(Reader, Writer, boolean)
public static ISObject zip(ISObject... objects)
Zip a list of sobject into a single sobject.
objects - the sobjects to be zipped.objects.public static File zip(File... files)
Zip a list of files into a single file. The name of the zip file is randomly picked up in the temp dir.
files - the files to be zipped.filesCopyright © 2014–2019 OSGL (Open Source General Library). All rights reserved.