sam.io
Class IO

java.lang.Object
  |
  +--sam.io.IO

public class IO
extends java.lang.Object

Input/output toolkit


Field Summary
static java.io.OutputStream NULL_OUTPUT
          Basic null output.
 
Method Summary
static void askWetherToRetry(java.io.IOException e)
          Asks the user wether to retry an interrupted I/O operation
static void bufferedDump(java.io.InputStream input, java.io.OutputStream output)
          Dumps an input data stream to an output stream This implementation loads and writes data in a bufferized fashion
static void bufferedDump(java.io.InputStream input, java.io.OutputStream output, long count)
          Dumps an input data stream to an output stream This implementation loads and writes data in a bufferized fashion
static java.io.File createTemporaryFile(java.io.File directory)
          Creates a new temporary file.
static java.io.InputStream getAsStream(java.lang.String content)
          Turns a String to a readable stream
static java.io.InputStream getAsStream(java.lang.String[] lines)
          Turns a list of Strings to a readable stream
static java.lang.String getFromStream(java.io.InputStream stream)
          Turns a stream to a String
static java.lang.String getFromStream(java.io.InputStream stream, boolean close)
          Turns a stream to a String
static java.lang.String[] getTokens(java.io.InputStream stream, java.lang.String delimiters)
          Tokenizes a stream.
static void jar(byte[] data, java.lang.String name, java.util.jar.JarOutputStream jar)
          Dumps a byte[] array of data to a new entry in a Jar archive
static void jar(byte[] data, java.lang.String name, java.util.jar.JarOutputStream jar, int compressionLevel)
          Dumps a byte[] array of data to a new entry in a Jar archive
static void jar(java.io.InputStream input, long length, java.lang.String name, java.util.jar.JarOutputStream jar)
          Dumps a stream to a new entry in a Jar archive
static void jar(java.io.InputStream input, long length, java.lang.String name, java.util.jar.JarOutputStream jar, int compressionLevel)
          Dumps a stream to a new entry in a Jar archive
static void jar(java.io.InputStream input, java.lang.String name, java.util.jar.JarOutputStream jar)
          Dumps a stream to a new entry in a Jar archive
static void jar(java.io.InputStream input, java.lang.String name, java.util.jar.JarOutputStream jar, int compressionLevel)
          Dumps a stream to a new entry in a Jar archive
static java.io.InputStream preextract(java.io.InputStream data, java.io.File temporary)
          Pre-extracts data.
static java.io.OutputStream putNextEntry(java.util.jar.JarOutputStream jar, java.lang.String name, int compressionLevel)
          Creates a new entry in a Jar archive
static byte[] readFully(java.io.InputStream input)
          Loads a full stream to memory
static void unBufferedDump(java.io.InputStream input, java.io.OutputStream output)
          Deprecated.  
static void unBufferedDump(java.io.InputStream input, java.io.OutputStream output, long count)
          Deprecated.  
static void unjar(java.util.jar.JarFile jar, java.lang.String name, java.io.File file)
          Extracts a whole entry to a file
static void unjar(java.util.jar.JarFile jar, java.lang.String name, java.io.OutputStream output)
          Extracts a whole entry to a stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_OUTPUT

public static final java.io.OutputStream NULL_OUTPUT
Basic null output. All bytes stored into this OutputStream are simply dropped.

Method Detail

getAsStream

public static java.io.InputStream getAsStream(java.lang.String content)
Turns a String to a readable stream


getAsStream

public static java.io.InputStream getAsStream(java.lang.String[] lines)
Turns a list of Strings to a readable stream


getFromStream

public static java.lang.String getFromStream(java.io.InputStream stream)
                                      throws java.io.IOException
Turns a stream to a String

java.io.IOException

getTokens

public static java.lang.String[] getTokens(java.io.InputStream stream,
                                           java.lang.String delimiters)
                                    throws java.io.IOException
Tokenizes a stream. Note that this implementation does not use the standard java.io.StreamTokenizer class.

java.io.IOException

getFromStream

public static java.lang.String getFromStream(java.io.InputStream stream,
                                             boolean close)
                                      throws java.io.IOException
Turns a stream to a String

Parameters:
stream - the stream to read from
close - wether to close the input stream once exhausted
java.io.IOException

preextract

public static java.io.InputStream preextract(java.io.InputStream data,
                                             java.io.File temporary)
                                      throws java.io.IOException
Pre-extracts data. This dumps a stream fully to a temporary file which is then re-opened for reading.

Parameters:
data - the data stream to be pre-extracted
temporary - the temporary file or directory to pre-extract data into
java.io.IOException

createTemporaryFile

public static java.io.File createTemporaryFile(java.io.File directory)
                                        throws java.io.IOException
Creates a new temporary file.

java.io.IOException

putNextEntry

public static java.io.OutputStream putNextEntry(java.util.jar.JarOutputStream jar,
                                                java.lang.String name,
                                                int compressionLevel)
                                         throws java.io.IOException
Creates a new entry in a Jar archive

Parameters:
jar - the Jar archive to write to
name - the Jar entry name to create, which might include a /-separated path
compressionLevel - the compression level ranging from 0 (no compression) to 9 (best but slowest compression).
Returns:
an OutputStream to be written into, which automatically closes the underlying entry on close() Warning: forgetting the close() call will cause the entry to be closed once in the GC's thread, which means at non-deterministic points, which might corrupt the underlying ZIP archive.
java.io.IOException

jar

public static void jar(java.io.InputStream input,
                       long length,
                       java.lang.String name,
                       java.util.jar.JarOutputStream jar)
                throws java.io.IOException
Dumps a stream to a new entry in a Jar archive

Parameters:
jar - the Jar archive to write to
name - the Jar entry name to create, which might include a /-separated path Data is stored according to the default compression level
java.io.IOException
See Also:
Settings.Defaults.JAR_COMPRESSION_LEVEL

jar

public static void jar(java.io.InputStream input,
                       long length,
                       java.lang.String name,
                       java.util.jar.JarOutputStream jar,
                       int compressionLevel)
                throws java.io.IOException
Dumps a stream to a new entry in a Jar archive

Parameters:
input - the input data stream
length - the expected length of the input stream
jar - the Jar archive to write to
name - the Jar entry name to create, which might include a /-separated path
compressionLevel - the compression level ranging from 0 (no compression) to 9 (best but slowest compression).
java.io.IOException

jar

public static void jar(java.io.InputStream input,
                       java.lang.String name,
                       java.util.jar.JarOutputStream jar)
                throws java.io.IOException
Dumps a stream to a new entry in a Jar archive

Parameters:
input - the input data stream
jar - the Jar archive to write to
name - the Jar entry name to create, which might include a /-separated path Data is stored according to the default compression level
java.io.IOException
See Also:
Settings.Defaults.JAR_COMPRESSION_LEVEL

jar

public static void jar(java.io.InputStream input,
                       java.lang.String name,
                       java.util.jar.JarOutputStream jar,
                       int compressionLevel)
                throws java.io.IOException
Dumps a stream to a new entry in a Jar archive

Parameters:
input - the input data stream
jar - the Jar archive to write to
name - the Jar entry name to create, which might include a /-separated path
compressionLevel - the compression level ranging from 0 (no compression) to 9 (best but slowest compression).
java.io.IOException

jar

public static void jar(byte[] data,
                       java.lang.String name,
                       java.util.jar.JarOutputStream jar)
                throws java.io.IOException
Dumps a byte[] array of data to a new entry in a Jar archive

Parameters:
data - the input data
jar - the Jar archive to write to
name - the Jar entry name to create, which might include a /-separated path Data is stored according to the default compression level
java.io.IOException
See Also:
Settings.Defaults.JAR_COMPRESSION_LEVEL

jar

public static void jar(byte[] data,
                       java.lang.String name,
                       java.util.jar.JarOutputStream jar,
                       int compressionLevel)
                throws java.io.IOException
Dumps a byte[] array of data to a new entry in a Jar archive

Parameters:
data - the input data
jar - the Jar archive to write to
name - the Jar entry name to create, which might include a /-separated path
compressionLevel - the compression level ranging from 0 (no compression) to 9 (best but slowest compression).
java.io.IOException

unjar

public static void unjar(java.util.jar.JarFile jar,
                         java.lang.String name,
                         java.io.File file)
                  throws java.io.IOException
Extracts a whole entry to a file

Parameters:
jar - the jar archive
name - the Jar entry name to create, which might include a /-separated path
file - the output file
java.io.IOException

unjar

public static void unjar(java.util.jar.JarFile jar,
                         java.lang.String name,
                         java.io.OutputStream output)
                  throws java.io.IOException
Extracts a whole entry to a stream

Parameters:
jar - the jar archive
name - the Jar entry name to create, which might include a /-separated path
output - the output stream
java.io.IOException

readFully

public static byte[] readFully(java.io.InputStream input)
                        throws java.io.IOException
Loads a full stream to memory

Parameters:
input - the input data stream
Returns:
the byte[] array of data
java.io.IOException

bufferedDump

public static void bufferedDump(java.io.InputStream input,
                                java.io.OutputStream output,
                                long count)
                         throws java.io.IOException
Dumps an input data stream to an output stream This implementation loads and writes data in a bufferized fashion

Parameters:
input - the input data stream
output - the output stream
java.io.IOException

unBufferedDump

public static void unBufferedDump(java.io.InputStream input,
                                  java.io.OutputStream output,
                                  long count)
                           throws java.io.IOException
Deprecated.  

Dumps an input data stream to an output stream This implementation loads and writes data byte-per-byte

Parameters:
input - the input data stream
output - the output stream
java.io.IOException

bufferedDump

public static void bufferedDump(java.io.InputStream input,
                                java.io.OutputStream output)
                         throws java.io.IOException
Dumps an input data stream to an output stream This implementation loads and writes data in a bufferized fashion

Parameters:
input - the input data stream
output - the output stream
java.io.IOException

unBufferedDump

public static void unBufferedDump(java.io.InputStream input,
                                  java.io.OutputStream output)
                           throws java.io.IOException
Deprecated.  

Dumps an input data stream to an output stream This implementation loads and writes data byte-per-byte

Parameters:
input - the input data stream
output - the output stream
java.io.IOException

askWetherToRetry

public static void askWetherToRetry(java.io.IOException e)
                             throws java.io.IOException
Asks the user wether to retry an interrupted I/O operation

java.io.IOException