thredds.util
Class IO

java.lang.Object
  extended by thredds.util.IO

public class IO
extends java.lang.Object

Input/Output utilities.

Version:
$Id:IO.java 63 2006-07-12 21:50:51Z edavis $
Author:
John Caron

Nested Class Summary
static class IO.Result
           
 
Constructor Summary
IO()
           
 
Method Summary
static void copy(java.io.InputStream in, java.io.OutputStream out)
          copy all bytes from in to out.
static void copy(java.io.InputStream in, java.io.OutputStream out, int n)
          copy n bytes from in to out.
static void copyB(java.io.InputStream in, java.io.OutputStream out, int bufferSize)
          copy all bytes from in to out.
static void copyDirTree(java.lang.String fromDirName, java.lang.String toDirName)
          Copy an entire directory tree.
static void copyFile(java.io.File fileIn, java.io.File fileOut)
          copy one file to another.
static void copyFile(java.lang.String fileInName, java.io.OutputStream out)
          copy file to output stream
static void copyFile(java.lang.String fileInName, java.lang.String fileOutName)
          copy one file to another.
static void copyFileB(java.io.File fileIn, java.io.OutputStream out, int bufferSize)
          copy file to output stream, specify internal buffer size
static long copyRafB(RandomAccessFile raf, long offset, long length, java.io.OutputStream out, byte[] buffer)
          Copy part of a RandomAccessFile to output stream, specify internal buffer size
static void copyUrlB(java.lang.String urlString, java.io.OutputStream out, int bufferSize)
          copy contents of URL to output stream, specify internal buffer size
static void main4(java.lang.String[] args)
           
static void mainn(java.lang.String[] args)
           
static IO.Result putToURL(java.lang.String urlString, java.lang.String contents)
          use HTTP PUT to send the contents to the named URL.
static java.lang.String readContents(java.io.InputStream is)
          Read the contents from the inputStream and place into a String, with any error messages put in the return String.
static byte[] readContentsToByteArray(java.io.InputStream is)
          Read the contents from the inputStream and place into a byte array, with any error messages put in the return String.
static java.lang.String readFile(java.lang.String filename)
          Read the contents from the named file and place into a String, with any error messages put in the return String.
static byte[] readFileToByteArray(java.lang.String filename)
          Read the file and place contents into a byte array, with any error messages put in the return String.
static java.lang.String readURLcontents(java.lang.String urlString)
          Read the contents from the named URL and place into a String, with any error messages put in the return String.
static java.lang.String readURLcontentsWithException(java.lang.String urlString)
          Read the contents from the named URL and place into a String.
static java.lang.String readURLtoFile(java.lang.String urlString, java.io.File file)
          read the contents from the named URL, write to a file.
static java.lang.String readURLtoFileWithExceptions(java.lang.String urlString, java.io.File file)
          read the contents from the named URL, write to a file.
static java.lang.String readURLtoFileWithExceptions(java.lang.String urlString, java.io.File file, int buffer_size)
          read the contents from the named URL, write to a file.
static void testRead()
           
static void writeContents(java.lang.String contents, java.io.OutputStream os)
          Wite the contents from the String to a Stream,
static void writeToFile(java.io.InputStream in, java.lang.String fileOutName)
          copy input stream to file.
static void writeToFile(java.lang.String contents, java.io.File file)
          Write contents to a file
static void writeToFile(java.lang.String contents, java.lang.String fileOutName)
          Write contents to a file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IO

public IO()
Method Detail

copy

public static void copy(java.io.InputStream in,
                        java.io.OutputStream out)
                 throws java.io.IOException
copy all bytes from in to out.

Parameters:
in - InputStream
out - OutputStream
Throws:
java.io.IOException - on io error

copyB

public static void copyB(java.io.InputStream in,
                         java.io.OutputStream out,
                         int bufferSize)
                  throws java.io.IOException
copy all bytes from in to out.

Parameters:
in - InputStream
out - OutputStream
bufferSize - : internal buffer size.
Throws:
java.io.IOException - on io error

copy

public static void copy(java.io.InputStream in,
                        java.io.OutputStream out,
                        int n)
                 throws java.io.IOException
copy n bytes from in to out.

Parameters:
in - InputStream
out - OutputStream
n - number of bytes to copy
Throws:
java.io.IOException - on io error

readContents

public static java.lang.String readContents(java.io.InputStream is)
                                     throws java.io.IOException
Read the contents from the inputStream and place into a String, with any error messages put in the return String.

Parameters:
is - the inputStream to read from.
Returns:
String holding the contents, or an error message.
Throws:
java.io.IOException - on io error

readContentsToByteArray

public static byte[] readContentsToByteArray(java.io.InputStream is)
                                      throws java.io.IOException
Read the contents from the inputStream and place into a byte array, with any error messages put in the return String.

Parameters:
is - the inputStream to read from.
Returns:
byte[] holding the contents, or an error message.
Throws:
java.io.IOException - on io error

writeContents

public static void writeContents(java.lang.String contents,
                                 java.io.OutputStream os)
                          throws java.io.IOException
Wite the contents from the String to a Stream,

Parameters:
contents - String holding the contents.
os - write to this OutputStream
Throws:
java.io.IOException - on io error

copyFile

public static void copyFile(java.lang.String fileInName,
                            java.lang.String fileOutName)
                     throws java.io.IOException
copy one file to another.

Parameters:
fileInName - copy from this file, which must exist.
fileOutName - copy to this file, which is overrwritten if already exists.
Throws:
java.io.IOException - on io error

copyFile

public static void copyFile(java.io.File fileIn,
                            java.io.File fileOut)
                     throws java.io.IOException
copy one file to another.

Parameters:
fileIn - copy from this file, which must exist.
fileOut - copy to this file, which is overrwritten if already exists.
Throws:
java.io.IOException - on io error

copyFile

public static void copyFile(java.lang.String fileInName,
                            java.io.OutputStream out)
                     throws java.io.IOException
copy file to output stream

Parameters:
fileInName - open this file
out - copy here
Throws:
java.io.IOException - on io error

copyFileB

public static void copyFileB(java.io.File fileIn,
                             java.io.OutputStream out,
                             int bufferSize)
                      throws java.io.IOException
copy file to output stream, specify internal buffer size

Parameters:
fileIn - copy this file
out - copy to this stream
bufferSize - internal buffer size.
Throws:
java.io.IOException - on io error

copyRafB

public static long copyRafB(RandomAccessFile raf,
                            long offset,
                            long length,
                            java.io.OutputStream out,
                            byte[] buffer)
                     throws java.io.IOException
Copy part of a RandomAccessFile to output stream, specify internal buffer size

Parameters:
raf - copy this file
offset - start here (byte offset)
length - number of bytes to copy
out - copy to this stream
buffer - use this buffer.
Returns:
number of bytes copied
Throws:
java.io.IOException - on io error

copyDirTree

public static void copyDirTree(java.lang.String fromDirName,
                               java.lang.String toDirName)
                        throws java.io.IOException
Copy an entire directory tree.

Parameters:
fromDirName - from this directory (do nothing if not exist)
toDirName - to this directory (will create if not exist)
Throws:
java.io.IOException - on io error

readFileToByteArray

public static byte[] readFileToByteArray(java.lang.String filename)
                                  throws java.io.IOException
Read the file and place contents into a byte array, with any error messages put in the return String.

Parameters:
filename - the file to read from.
Returns:
byte[] holding the contents, or an error message.
Throws:
java.io.IOException - on io error

readFile

public static java.lang.String readFile(java.lang.String filename)
                                 throws java.io.IOException
Read the contents from the named file and place into a String, with any error messages put in the return String.

Parameters:
filename - the URL to read from.
Returns:
String holding the contents, or an error message.
Throws:
java.io.IOException - on io error

writeToFile

public static void writeToFile(java.lang.String contents,
                               java.io.File file)
                        throws java.io.IOException
Write contents to a file

Parameters:
contents - String holding the contents
file - write to this file (overwrite if exists)
Throws:
java.io.IOException - on io error

writeToFile

public static void writeToFile(java.lang.String contents,
                               java.lang.String fileOutName)
                        throws java.io.IOException
Write contents to a file

Parameters:
contents - String holding the contents
fileOutName - write to this file (overwrite if exists)
Throws:
java.io.IOException - on io error

writeToFile

public static void writeToFile(java.io.InputStream in,
                               java.lang.String fileOutName)
                        throws java.io.IOException
copy input stream to file. close input stream when done.

Parameters:
in - copy from here
fileOutName - open this file (overwrite) and copy to it.
Throws:
java.io.IOException - on io error

copyUrlB

public static void copyUrlB(java.lang.String urlString,
                            java.io.OutputStream out,
                            int bufferSize)
                     throws java.io.IOException
copy contents of URL to output stream, specify internal buffer size

Parameters:
urlString - copy the contents of this URL
out - copy to this stream
bufferSize - internal buffer size.
Throws:
java.io.IOException - on io error

readURLtoFile

public static java.lang.String readURLtoFile(java.lang.String urlString,
                                             java.io.File file)
read the contents from the named URL, write to a file.

Parameters:
urlString - the URL to read from.
file - write to this file
Returns:
status or error message.

readURLtoFileWithExceptions

public static java.lang.String readURLtoFileWithExceptions(java.lang.String urlString,
                                                           java.io.File file)
                                                    throws java.io.IOException
read the contents from the named URL, write to a file.

Parameters:
urlString - the URL to read from.
file - write to this file
Returns:
status or error message.
Throws:
java.io.IOException - if failure

readURLtoFileWithExceptions

public static java.lang.String readURLtoFileWithExceptions(java.lang.String urlString,
                                                           java.io.File file,
                                                           int buffer_size)
                                                    throws java.io.IOException
read the contents from the named URL, write to a file.

Parameters:
urlString - the URL to read from.
file - write to this file
buffer_size - read/write in this size chunks
Returns:
status or error message.
Throws:
java.io.IOException - if failure

readURLcontentsWithException

public static java.lang.String readURLcontentsWithException(java.lang.String urlString)
                                                     throws java.io.IOException
Read the contents from the named URL and place into a String.

Parameters:
urlString - the URL to read from.
Returns:
String holding the contents.
Throws:
java.io.IOException - if fails

readURLcontents

public static java.lang.String readURLcontents(java.lang.String urlString)
Read the contents from the named URL and place into a String, with any error messages put in the return String.

Parameters:
urlString - the URL to read from.
Returns:
String holding the contents, or an error message.

putToURL

public static IO.Result putToURL(java.lang.String urlString,
                                 java.lang.String contents)
use HTTP PUT to send the contents to the named URL.

Parameters:
urlString - the URL to read from. must be http:
contents - String holding the contents
Returns:
a Result object; generally 0 <= code <=400 is ok

testRead

public static void testRead()

main4

public static void main4(java.lang.String[] args)

mainn

public static void mainn(java.lang.String[] args)