com.cloudera.lib.io
Class IOUtils

java.lang.Object
  extended by com.cloudera.lib.io.IOUtils

public abstract class IOUtils
extends Object


Constructor Summary
IOUtils()
           
 
Method Summary
static void copy(InputStream is, OutputStream os)
          Copies an inputstream to an outputstream.
static void copy(InputStream is, OutputStream os, long offset, long len)
          Copies a range of bytes from an inputstream to an outputstream.
static void copy(Reader reader, Writer writer)
          Copies a reader to a writer.
static void copy(Reader reader, Writer writer, long offset, long len)
          Copies a range of chars from a reader to a writer.
static void delete(File file)
          Deletes the specified path recursively.
static String toString(Reader reader)
          Reads a reader into a string.
static void zipDir(File dir, String relativePath, ZipOutputStream zos)
          Zips the contents of a directory into a zip outputstream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOUtils

public IOUtils()
Method Detail

delete

public static void delete(File file)
                   throws IOException
Deletes the specified path recursively.

As a safety mechanism, it converts the specified file to an absolute path and it throws an exception if the path is shorter than 5 character (you dont want to delete things like /tmp, /usr, /etc, /var, /opt, /sbin, /dev).

Parameters:
file - path to delete.
Throws:
IOException - thrown if an IO error occurred.

copy

public static void copy(InputStream is,
                        OutputStream os)
                 throws IOException
Copies an inputstream to an outputstream.

Parameters:
is - inputstream to copy.
os - target outputstream.
Throws:
IOException - thrown if an IO error occurred.

copy

public static void copy(InputStream is,
                        OutputStream os,
                        long offset,
                        long len)
                 throws IOException
Copies a range of bytes from an inputstream to an outputstream.

Parameters:
is - inputstream to copy.
os - target outputstream.
offset - of the inputstream to start the copy from, the offset is relative to the current position.
len - length of the inputstream to copy, -1 means until the end of the inputstream.
Throws:
IOException - thrown if an IO error occurred.

copy

public static void copy(Reader reader,
                        Writer writer)
                 throws IOException
Copies a reader to a writer.

Parameters:
reader - reader to copy.
writer - target writer.
Throws:
IOException - thrown if an IO error occurred.

copy

public static void copy(Reader reader,
                        Writer writer,
                        long offset,
                        long len)
                 throws IOException
Copies a range of chars from a reader to a writer.

Parameters:
reader - reader to copy.
writer - target writer.
offset - of the reader to start the copy from, the offset is relative to the current position.
len - length of the reader to copy, -1 means until the end of the reader.
Throws:
IOException - thrown if an IO error occurred.

toString

public static String toString(Reader reader)
                       throws IOException
Reads a reader into a string.

Parameters:
reader - reader to read.
Returns:
string with the contents of the reader.
Throws:
IOException - thrown if an IO error occurred.

zipDir

public static void zipDir(File dir,
                          String relativePath,
                          ZipOutputStream zos)
                   throws IOException
Zips the contents of a directory into a zip outputstream.

Parameters:
dir - directory contents to zip.
relativePath - relative path top prepend to all files in the zip.
zos - zip output stream
Throws:
IOException - thrown if an IO error occurred.


Copyright © 2012 Cloudera. All Rights Reserved.