public class IOUtil extends Object
Constructor and Description |
---|
IOUtil() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
readBytes(File file)
Reads all bytes from the specified file and returns them as a byte array.
|
static byte[] |
readBytes(InputStream in)
Reads all bytes from the supplied input stream and returns them as a byte array.
|
static int |
readBytes(InputStream in,
byte[] byteArray)
Fills the supplied byte array with bytes read from the specified InputStream.
|
static byte[] |
readBytes(InputStream in,
int maxBytes)
Reads at most maxBytes bytes from the supplied input stream and returns them as a byte array.
|
static char[] |
readChars(Reader r)
Reads all characters from the supplied reader and returns them.
|
static int |
readChars(Reader r,
char[] charArray)
Fills the supplied character array with characters read from the specified Reader.
|
static char[] |
readChars(URL url)
Read the contents of a (unbuffered) resource into a character array.
|
static Properties |
readProperties(File propsFile)
Read properties from the specified file.
|
static Properties |
readProperties(File propsFile,
Properties defaults)
Read properties from the specified file.
|
static Properties |
readProperties(InputStream in)
Read properties from the specified InputStream.
|
static Properties |
readProperties(InputStream in,
Properties defaults)
Read properties from the specified InputStream.
|
static String |
readString(File file)
Read the contents as a string from the given (unbuffered) file.
|
static String |
readString(InputStream in)
Read the contents of an (unbuffered) input stream into a single string.
|
static String |
readString(Reader r)
Reads all characters from the supplied reader and returns them as a string.
|
static String |
readString(Reader r,
int maxChars)
Reads a string of at most length maxChars from the supplied Reader.
|
static String |
readString(URL url)
Read the contents of a (unbuffered) resource into one single string.
|
static long |
transfer(InputStream in,
File file)
Writes all bytes from an InputStream to a file.
|
static long |
transfer(InputStream in,
OutputStream out)
Transfers all bytes that can be read from in to out.
|
static long |
transfer(Reader reader,
File file)
Writes all characters from a Reader to a file using the default character encoding.
|
static long |
transfer(Reader in,
Writer out)
Transfers all characters that can be read from in to out .
|
static Reader |
urlToReader(URL url)
Read the contents of a resource into a reader.
|
static void |
writeBytes(byte[] data,
File file)
Write the contents of a byte array (unbuffered) to a file.
|
static void |
writeBytes(byte[] data,
OutputStream out)
Write he contents of a byte array (unbuffered) to an output stream.
|
static void |
writeProperties(Properties props,
File file,
boolean includeDefaults)
Write the specified properties to the specified file.
|
static void |
writeProperties(Properties props,
OutputStream out,
boolean includeDefaults)
Write the specified properties to the specified output stream.
|
static void |
writeStream(InputStream in,
File file)
Writes all data that can be read from the supplied InputStream to the specified file.
|
static void |
writeString(String contents,
File file)
Write the contents of a string (unbuffered) to a file
|
public static String readString(File file) throws IOException
file
- file to readIOException
public static String readString(URL url) throws IOException
url
- url to get the data fromIOException
public static String readString(InputStream in) throws IOException
in
- input streamIOException
public static String readString(Reader r) throws IOException
r
- The Reader supplying the charactersIOException
public static String readString(Reader r, int maxChars) throws IOException
r
- The Reader to read the string from.maxChars
- The maximum number of characters to read.IOException
public static char[] readChars(URL url) throws IOException
url
- url to get the data fromIOException
public static char[] readChars(Reader r) throws IOException
r
- The Reader supplying the charactersIOException
public static int readChars(Reader r, char[] charArray) throws IOException
r
- The Reader to read the characters from.charArray
- The character array to fill with characters.IOException
public static byte[] readBytes(File file) throws IOException
file
- The file to read.IOException
- If an I/O error occurred while reading from the file.IllegalArgumentException
- If the file size exceeds the maximum array length (larger than
Integer.MAX_VALUE
.public static byte[] readBytes(InputStream in) throws IOException
in
- The InputStream supplying the bytes.IOException
public static byte[] readBytes(InputStream in, int maxBytes) throws IOException
in
- The InputStream supplying the bytes.maxBytes
- The maximum number of bytes to read from the input stream.IOException
public static int readBytes(InputStream in, byte[] byteArray) throws IOException
in
- The InputStream to read the bytes from.byteArray
- The byte array to fill with bytes.IOException
public static Properties readProperties(File propsFile) throws IOException
propsFile
- the file to read fromIOException
- when the file could not be read properlypublic static Properties readProperties(File propsFile, Properties defaults) throws IOException
propsFile
- the file to read fromdefaults
- the default properties to useIOException
- when the file could not be read properlypublic static Properties readProperties(InputStream in) throws IOException
in
- the stream to read from. The stream will be closed by this method.IOException
- when the stream could not be read properlypublic static Properties readProperties(InputStream in, Properties defaults) throws IOException
in
- the stream to read from. The stream will be closed by this method.defaults
- the default propertiesIOException
- when the stream could not be read properlypublic static void writeProperties(Properties props, File file, boolean includeDefaults) throws IOException
props
- the properties to writefile
- the file to write toincludeDefaults
- true when default values need to be includedIOException
- when the properties could not be written to the file properlypublic static void writeProperties(Properties props, OutputStream out, boolean includeDefaults) throws IOException
props
- the properties to writeout
- the output stream to write toincludeDefaults
- true if default values need to be includedIOException
- when the properties could not be written to the output stream properlypublic static void writeStream(InputStream in, File file) throws IOException
in
- An InputStream.file
- The file to write the data to.IOException
- If an I/O error occurred.public static void writeString(String contents, File file) throws IOException
contents
- string contents to writefile
- file to write toIOException
public static void writeBytes(byte[] data, File file) throws IOException
data
- data to writefile
- fileIOException
public static void writeBytes(byte[] data, OutputStream out) throws IOException
data
- data to writeout
- fileIOException
public static Reader urlToReader(URL url) throws IOException
url
- urlIOException
public static final long transfer(InputStream in, OutputStream out) throws IOException
in
- The InputStream to read data from.out
- The OutputStream to write data to.IOException
public static final long transfer(InputStream in, File file) throws IOException
in
- The InputStream containing the data to write to the file.file
- The file to write the data to.IOException
- If an I/O error occurred while trying to write the data to the file.public static final long transfer(Reader in, Writer out) throws IOException
in
- The Reader to read characters from.out
- The Writer to write characters to.IOException
public static final long transfer(Reader reader, File file) throws IOException
reader
- The Reader containing the data to write to the file.file
- The file to write the data to.IOException
- If an I/O error occurred while trying to write the data to the file.FileWriter
Copyright © 2015-2019 Eclipse Foundation. All Rights Reserved.