Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.archive.util
Class IoUtils

    java.lang.Object
      org.archive.util.IoUtils

    public class IoUtils

extends java.lang.Object

I/O Utility methods.

Version:
  $Date: 2007-02-20 23:25:20 +0000 (Tue, 20 Feb 2007) $, $Revision: 4919 $
Author:
  stack

Field Summary
`protected static java.util.logging.Logger` | `logger`

Constructor Summary
`IoUtils()`

Method Summary
`static java.lang.Object` | `deserializeFromByteArray(byte[] in)` Utility method to deserialize Object from byte[].
`static java.lang.Object` | `deserializeFromFile(java.io.File file)` Utility method to deserialize an Object from given File.
`static float` | `encodingMaxBytesPerChar(java.lang.String encoding)` Return the maximum number of bytes per character in the named encoding, or 0 if encoding is invalid or unsupported.
`static java.io.File` | `ensureWriteableDirectory(java.io.File dir)` Ensure writeable directory.
`static java.util.List` | `ensureWriteableDirectory(java.util.List<java.io.File> dirs)` Ensure writeable directories.
`static java.io.File` | `ensureWriteableDirectory(java.lang.String dir)` Ensure writeable directory.
`static java.lang.String` | `getClasspathPath(java.io.File file)`
`static void` | `readFully(java.io.InputStream input, byte[] buf)`
`static java.lang.String` | `readFullyAsString(java.io.InputStream inputStream)` Read the entire stream to EOF, returning what's read as a String.
`static void` | `readFullyToFile(java.io.InputStream is, java.io.File toFile)` Read the entire stream to EOF into the passed file.
`static long` | `readFullyToFile(java.io.InputStream is, java.io.File toFile, byte[] buffer)` Read the entire stream to EOF into the passed file.
`static byte[]` | `serializeToByteArray(java.lang.Object object)` Utility method to serialize Object to byte[].
`static void` | `serializeToFile(java.lang.Object object, java.io.File file)` Utility method to serialize an object to the given File.
`static java.io.IOException` | `wrapAsIOException(java.lang.Throwable e)` Wrap generic Throwable as a checked IOException

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### logger

    protected static java.util.logging.Logger logger

Constructor Detail

### IoUtils

    public IoUtils()

Method Detail

### getClasspathPath

    public static java.lang.String getClasspathPath(java.io.File file)

  Parameters:
    `file` - File to operate on.
  Returns:
    Path suitable for use getting resources off the CLASSPATH (CLASSPATH resources always use '/' as path separator, even on windows).

### ensureWriteableDirectory

    public static java.io.File ensureWriteableDirectory(java.lang.String dir)
                                                 throws java.io.IOException

  Ensure writeable directory. If doesn't exist, we attempt creation.

  Parameters:
    `dir` - Directory to test for exitence and is writeable.
  Returns:
    The passed `dir`.
  Throws:
    `java.io.IOException` - If passed directory does not exist and is not createable, or directory is not writeable or is not a directory.

### ensureWriteableDirectory

    public static java.util.List ensureWriteableDirectory(java.util.List<java.io.File> dirs)
                                                   throws java.io.IOException

  Ensure writeable directories. If doesn't exist, we attempt creation.

  Parameters:
    `dirs` - List of Files to test.
  Returns:
    The passed `dirs`.
  Throws:
    `java.io.IOException` - If passed directory does not exist and is not createable, or directory is not writeable or is not a directory.

### ensureWriteableDirectory

    public static java.io.File ensureWriteableDirectory(java.io.File dir)
                                                 throws java.io.IOException

  Ensure writeable directory. If doesn't exist, we attempt creation.

  Parameters:
    `dir` - Directory to test for exitence and is writeable.
  Returns:
    The passed `dir`.
  Throws:
    `java.io.IOException` - If passed directory does not exist and is not createable, or directory is not writeable or is not a directory.

### readFullyAsString

    public static java.lang.String readFullyAsString(java.io.InputStream inputStream)
                                              throws java.io.IOException

  Read the entire stream to EOF, returning what's read as a String.

  Parameters:
    `inputStream` -
  Returns:
    String of the whole inputStream's contents
  Throws:
    `java.io.IOException`

### readFullyToFile

    public static void readFullyToFile(java.io.InputStream is,
                                       java.io.File toFile)
                                throws java.io.IOException

  Read the entire stream to EOF into the passed file.

  Parameters:
    `is` -
    `toFile` - File to read into .
  Throws:
    `java.io.IOException`
    `java.io.IOException`

### readFullyToFile

    public static long readFullyToFile(java.io.InputStream is,
                                       java.io.File toFile,
                                       byte[] buffer)
                                throws java.io.IOException

  Read the entire stream to EOF into the passed file. Closes `is` when done or if an exception.

  Parameters:
    `is` - Stream to read.
    `toFile` - File to read into .
    `buffer` - Buffer to use reading.
  Returns:
    Count of bytes read.
  Throws:
    `java.io.IOException`

### wrapAsIOException

    public static java.io.IOException wrapAsIOException(java.lang.Throwable e)

  Wrap generic Throwable as a checked IOException

  Parameters:
    `e` - wrapped exception
  Returns:
    IOException

### readFully

    public static void readFully(java.io.InputStream input,
                                 byte[] buf)
                          throws java.io.IOException

  Throws:
    `java.io.IOException`

### encodingMaxBytesPerChar

    public static float encodingMaxBytesPerChar(java.lang.String encoding)

  Return the maximum number of bytes per character in the named encoding, or 0 if encoding is invalid or unsupported.

  Parameters:
    `encoding` - Encoding to consider. For now, should be java canonical name for the encoding.
  Returns:
    True if multibyte encoding.

### serializeToFile

    public static void serializeToFile(java.lang.Object object,
                                       java.io.File file)
                                throws java.io.IOException

  Utility method to serialize an object to the given File.

  Parameters:
    `object` - Object to serialize
    `file` - File to receive serialized copy
  Throws:
    `java.io.IOException`

### deserializeFromFile

    public static java.lang.Object deserializeFromFile(java.io.File file)
                                                throws java.io.IOException

  Utility method to deserialize an Object from given File.

  Parameters:
    `file` - File source
  Returns:
    deserialized Object
  Throws:
    `java.io.IOException`

### serializeToByteArray

    public static byte[] serializeToByteArray(java.lang.Object object)

  Utility method to serialize Object to byte[].

  Parameters:
    `object` - Object to be serialized
  Returns:
    byte[] serialized form

### deserializeFromByteArray

    public static java.lang.Object deserializeFromByteArray(byte[] in)

  Utility method to deserialize Object from byte[].

  Parameters:
    `in` - byte[] source
  Returns:
    Object deserialized

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2008 Internet Archive. All Rights Reserved.