com.levigo.jadice.document.io
Class IOUtils

java.lang.Object
  extended by com.levigo.jadice.document.io.IOUtils

public class IOUtils
extends Object


Field Summary
static int COPY_CHUNK_SIZE
           
static int DEFAULT_BUFFER_SIZE
           
 
Constructor Summary
IOUtils()
           
 
Method Summary
static long copy(InputStream in, OutputStream out)
           
static long copy(InputStream in, OutputStream out, int bufferSize)
           
static void copyAndClose(InputStream is, OutputStream os)
          Copies all data from input to output.
static void copyStream(SeekableInputStream is, ImageOutputStream os)
           
static void deleteAllBelow(File file)
          Recursively delete everything below a given directory, but don't remove the directory itself.
static void deleteRecursively(File file)
          Recursively delete a file or directory.
static long determineLength(SeekableInputStream is)
          Determines and returns the stream length either by checking whether the stream returns a reasonable length (some instances may not be able to do that) or just reading over it, until an EOF is hit.
static void discardStream(InputStream is)
          Copies all data from the input stream.
static void drainAsynchronously(InputStream is)
          Eagerly drain the given input stream.
static void drainSynchronously(InputStream is)
          Eagerly drain the given input stream.
static long forcedDetermineLength(SeekableInputStream is)
          Determines and returns the stream length by reading over the complete stream until an EOF was found.
static boolean isTryFileCaching()
          Return whether to try to cache data in local files by default.
static void setTryFileCaching(boolean tryFileCaching)
          Set whether to try to cache data in local files by default.
static SeekableInputStream wrap(InputStream is)
          Wraps the given stream into a SeekableInputStream.
static SeekableInputStream wrap(InputStream inputStream, boolean tryLocalTmpFileAccess)
          Wraps the given stream into SeekableInputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

COPY_CHUNK_SIZE

public static final int COPY_CHUNK_SIZE
See Also:
Constant Field Values
Constructor Detail

IOUtils

public IOUtils()
Method Detail

copy

public static long copy(InputStream in,
                        OutputStream out)
                 throws IOException
Throws:
IOException

copy

public static long copy(InputStream in,
                        OutputStream out,
                        int bufferSize)
                 throws IOException
Throws:
IOException

copyAndClose

public static void copyAndClose(InputStream is,
                                OutputStream os)
                         throws IOException
Copies all data from input to output. Closes the streams afterwards.

Parameters:
is -
os -
Throws:
IOException

discardStream

public static void discardStream(InputStream is)
                          throws IOException
Copies all data from the input stream. Does NOT close the input stream.

Parameters:
is -
Throws:
IOException

deleteRecursively

public static void deleteRecursively(File file)
Recursively delete a file or directory.

Parameters:
file -

deleteAllBelow

public static void deleteAllBelow(File file)
Recursively delete everything below a given directory, but don't remove the directory itself.

Parameters:
file -

copyStream

public static void copyStream(SeekableInputStream is,
                              ImageOutputStream os)
                       throws IOException
Throws:
IOException

determineLength

public static long determineLength(SeekableInputStream is)
                            throws IOException
Determines and returns the stream length either by checking whether the stream returns a reasonable length (some instances may not be able to do that) or just reading over it, until an EOF is hit. Users of given stream need to deal with synchronization against other users of the same stream instance.

Parameters:
is - the stream to determine its length
Returns:
the length, the length returned by SeekableInputStream.length() if positive, or the length of the stream determined by reading over it. the length is measured in bytes.
Throws:
IOException - if an I/O error occurs.

forcedDetermineLength

public static long forcedDetermineLength(SeekableInputStream is)
                                  throws IOException
Determines and returns the stream length by reading over the complete stream until an EOF was found.

Note: Users of given stream need to deal with synchronization against other users of the same stream instance.

Parameters:
is - the stream to determine its length
Returns:
the length of the stream determined by reading over it. The length is measured in bytes.
Throws:
IOException - if an I/O error occurs.

drainSynchronously

public static void drainSynchronously(InputStream is)
Eagerly drain the given input stream. This method will block until all data has been read and the stream's EOF has been reached.

Parameters:
is -

drainAsynchronously

public static void drainAsynchronously(InputStream is)
Eagerly drain the given input stream. Draining will be performed in the background. This method will synchronize on the InputStream while doing block-wise reads.

Parameters:
is -

wrap

public static final SeekableInputStream wrap(InputStream is)
                                      throws IOException
Wraps the given stream into a SeekableInputStream. Checks the given input stream and if necessary wraps it with an appropriate SeekableInputStream implementation. This method will try to buffer all data into a temporary file if possible. If additionally a BufferManager is available on the classpath and temporary buffering is possible, the buffering of data will be handled by the BufferManager. If temporary buffering is not possible (e.g. due to security restrictions), all data will be buffered in memory.

Parameters:
is - the stream to wrap
Returns:
a SeekableInputStream instance wrapping the original InputStream
Throws:
IOException - if an i/o error occurred
IllegalArgumentException - if the given InputStream is null

wrap

public static final SeekableInputStream wrap(InputStream inputStream,
                                             boolean tryLocalTmpFileAccess)
                                      throws IOException
Wraps the given stream into SeekableInputStream. Checks the given input stream and if necessary wraps it with an appropriate SeekableInputStream, which is returned. If tryLocalTmpFileAccess is true, this method will try to buffer all data into a temporary file if possible. If additionally a BufferManager is available on the classpath and temporary buffering is possible, the buffering of data will be handled by the BufferManager. If temporary buffering is not possible (e.g. due to security restrictions), all data will be buffered in memory.

Parameters:
inputStream - the stream to wrap
tryLocalTmpFileAccess - enable/disable temporary file data buffering.
Returns:
a SeekableInputStream instance wrapping the original InputStream
Throws:
IOException - if an i/o error occurred
IllegalArgumentException - if the given InputStream is null

setTryFileCaching

public static void setTryFileCaching(boolean tryFileCaching)
Set whether to try to cache data in local files by default. This value is used by wrap(InputStream).

Parameters:
tryFileCaching - true if local file caching should be tried by default

isTryFileCaching

public static boolean isTryFileCaching()
Return whether to try to cache data in local files by default.

Returns:
true if local file caching is tried by default


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.