public class IO extends Object
Modifier and Type | Class and Description |
---|---|
static class |
IO.HttpResult
Holds the result of an HTTP action.
|
Modifier and Type | Field and Description |
---|---|
static int |
default_file_buffersize |
static int |
default_socket_buffersize |
Constructor and Description |
---|
IO() |
Modifier and Type | Method and Description |
---|---|
static long |
appendToFile(InputStream in,
String fileOutName) |
static long |
copy(InputStream in,
OutputStream out)
copy all bytes from in to out.
|
static void |
copy(InputStream in,
OutputStream out,
int n)
copy n bytes from in to out.
|
static void |
copy2File(byte[] src,
String fileOut)
copy file to output stream
|
static long |
copy2null(FileChannel in,
int buffersize)
copy all bytes from in and throw them away.
|
static long |
copy2null(InputStream in,
int buffersize)
copy all bytes from in and throw them away.
|
static long |
copyB(InputStream in,
OutputStream out,
int bufferSize)
copy all bytes from in to out, specify buffer size
|
static void |
copyDirTree(String fromDirName,
String toDirName)
Copy an entire directory tree.
|
static void |
copyFile(File fileIn,
File fileOut)
copy one file to another.
|
static void |
copyFile(String fileInName,
OutputStream out)
copy file to output stream
|
static void |
copyFile(String fileInName,
String fileOutName)
copy one file to another.
|
static void |
copyFileB(File fileIn,
OutputStream out,
int bufferSize)
copy file to output stream, specify internal buffer size
|
static void |
copyFileWithChannels(File fileIn,
WritableByteChannel out) |
static long |
copyRafB(RandomAccessFile raf,
long offset,
long length,
OutputStream out,
byte[] buffer)
Copy part of a RandomAccessFile to output stream, specify internal buffer size
|
static long |
copyUrlB(String urlString,
OutputStream out,
int bufferSize)
copy contents of URL to output stream, specify internal buffer size.
|
static InputStream |
getFileResource(String resourcePath)
Open a resource as a Stream.
|
static InputStream |
getInputStreamFromUrl(String urlString)
get input stream from URL
|
static IO.HttpResult |
putToURL(String urlString,
String contents)
use HTTP PUT to send the contents to the named URL.
|
static String |
readContents(InputStream is)
Read the contents from the inputStream and place into a String,
with any error messages put in the return String.
|
static String |
readContents(InputStream is,
String charset)
Read the contents from the inputStream and place into a String,
with any error messages put in the return String.
|
static byte[] |
readContentsToByteArray(InputStream is)
Read the contents from the inputStream and place into a byte array,
with any error messages put in the return String.
|
static String |
readFile(String filename)
Read the contents from the named file and place into a String, assuming UTF-8 encoding.
|
static byte[] |
readFileToByteArray(String filename)
Read the file and place contents into a byte array,
with any error messages put in the return String.
|
static String |
readURLcontents(String urlString)
Read the contents from the named URL and place into a String,
with any error messages put in the return String.
|
static byte[] |
readURLContentsToByteArray(String urlString)
Read the contents from the given URL and place into a byte array,
with any error messages put in the return String.
|
static String |
readURLcontentsWithException(String urlString)
Read the contents from the named URL and place into a String.
|
static String |
readURLtoFile(String urlString,
File file)
read the contents from the named URL, write to a file.
|
static String |
readURLtoFileWithExceptions(String urlString,
File file)
read the contents from the named URL, write to a file.
|
static String |
readURLtoFileWithExceptions(String urlString,
File file,
int buffer_size)
read the contents from the named URL, write to a file.
|
static long |
touch(FileChannel in,
int buffersize) |
static long |
touch(InputStream in,
int buffersize) |
static void |
writeContents(String contents,
OutputStream os)
Wite the contents from the String to a Stream,
|
static void |
writeToFile(byte[] contents,
File file)
Write byte[] contents to a file.
|
static long |
writeToFile(InputStream in,
String fileOutName)
copy input stream to file.
|
static void |
writeToFile(String contents,
File file)
Write String contents to a file, using UTF-8 encoding.
|
static void |
writeToFile(String contents,
String fileOutName)
Write contents to a file, using UTF-8 encoding.
|
public static final int default_file_buffersize
public static final int default_socket_buffersize
public static InputStream getFileResource(String resourcePath)
resourcePath
- name of file path (use forward slashes!)public static long copy(InputStream in, OutputStream out) throws IOException
in
- InputStreamout
- OutputStreamIOException
- on io errorpublic static long copy2null(InputStream in, int buffersize) throws IOException
in
- InputStreambuffersize
- size of buffer to use, if -1 uses default value (9200)IOException
- on io errorpublic static long touch(InputStream in, int buffersize) throws IOException
IOException
public static long copy2null(FileChannel in, int buffersize) throws IOException
in
- FileChannelbuffersize
- size of buffer to use, if -1 uses default value (9200)IOException
- on io errorpublic static long touch(FileChannel in, int buffersize) throws IOException
IOException
public static long copyB(InputStream in, OutputStream out, int bufferSize) throws IOException
in
- InputStreamout
- OutputStreambufferSize
- : internal buffer size.IOException
- on io errorpublic static void copy(InputStream in, OutputStream out, int n) throws IOException
in
- InputStreamout
- OutputStreamn
- number of bytes to copyIOException
- on io errorpublic static String readContents(InputStream is) throws IOException
is
- the inputStream to read from.IOException
- on io errorpublic static String readContents(InputStream is, String charset) throws IOException
is
- the inputStream to read from.IOException
- on io errorpublic static byte[] readContentsToByteArray(InputStream is) throws IOException
is
- the inputStream to read from.IOException
- on io errorpublic static void writeContents(String contents, OutputStream os) throws IOException
contents
- String holding the contents.os
- write to this OutputStreamIOException
- on io errorpublic static void copyFile(String fileInName, String fileOutName) throws IOException
fileInName
- copy from this file, which must exist.fileOutName
- copy to this file, which is overrwritten if already exists.IOException
- on io errorpublic static void copyFile(File fileIn, File fileOut) throws IOException
fileIn
- copy from this file, which must exist.fileOut
- copy to this file, which is overrwritten if already exists.IOException
- on io errorpublic static void copy2File(byte[] src, String fileOut) throws IOException
src
- sourcefileOut
- copy to this fileIOException
- on io errorpublic static void copyFile(String fileInName, OutputStream out) throws IOException
fileInName
- open this fileout
- copy hereIOException
- on io errorpublic static void copyFileB(File fileIn, OutputStream out, int bufferSize) throws IOException
fileIn
- copy this fileout
- copy to this streambufferSize
- internal buffer size.IOException
- on io errorpublic static void copyFileWithChannels(File fileIn, WritableByteChannel out) throws IOException
IOException
public static long copyRafB(RandomAccessFile raf, long offset, long length, OutputStream out, byte[] buffer) throws IOException
raf
- copy this fileoffset
- start here (byte offset)length
- number of bytes to copyout
- copy to this streambuffer
- use this buffer.IOException
- on io errorpublic static void copyDirTree(String fromDirName, String toDirName) throws IOException
fromDirName
- from this directory (do nothing if not exist)toDirName
- to this directory (will create if not exist)IOException
- on io errorpublic static byte[] readFileToByteArray(String filename) throws IOException
filename
- the file to read from.IOException
- on io errorpublic static String readFile(String filename) throws IOException
filename
- the URL to read from.IOException
- on io errorpublic static void writeToFile(String contents, File file) throws IOException
contents
- String holding the contentsfile
- write to this file (overwrite if exists)IOException
- on io errorpublic static void writeToFile(byte[] contents, File file) throws IOException
contents
- String holding the contentsfile
- write to this file (overwrite if exists)IOException
- on io errorpublic static void writeToFile(String contents, String fileOutName) throws IOException
contents
- String holding the contentsfileOutName
- write to this file (overwrite if exists)IOException
- on io errorpublic static long writeToFile(InputStream in, String fileOutName) throws IOException
in
- copy from herefileOutName
- open this file (overwrite) and copy to it.IOException
- on io errorpublic static long appendToFile(InputStream in, String fileOutName) throws IOException
IOException
public static long copyUrlB(String urlString, OutputStream out, int bufferSize) throws IOException
urlString
- copy the contents of this URLout
- copy to this stream. If null, throw bytes awaybufferSize
- internal buffer size.IOException
- on io errorpublic static InputStream getInputStreamFromUrl(String urlString) throws IOException
urlString
- URLIOException
- on io errorpublic static String readURLtoFile(String urlString, File file)
urlString
- the URL to read from.file
- write to this filepublic static byte[] readURLContentsToByteArray(String urlString) throws IOException
urlString
- read from this URL.IOException
- on io errorpublic static String readURLtoFileWithExceptions(String urlString, File file) throws IOException
urlString
- the URL to read from.file
- write to this fileIOException
- if failurepublic static String readURLtoFileWithExceptions(String urlString, File file, int buffer_size) throws IOException
urlString
- the URL to read from.file
- write to this filebuffer_size
- read/write in this size chunksIOException
- if failurepublic static String readURLcontentsWithException(String urlString) throws IOException
urlString
- the URL to read from.IOException
- if failspublic static String readURLcontents(String urlString)
urlString
- the URL to read from.public static IO.HttpResult putToURL(String urlString, String contents)
urlString
- the URL to read from. must be http:contents
- String holding the contents