org.apache.oozie.util
Class IOUtils

java.lang.Object
  extended by org.apache.oozie.util.IOUtils

public abstract class IOUtils
extends Object

IO Utility methods.


Constructor Summary
IOUtils()
           
 
Method Summary
static void copyCharStream(Reader reader, Writer writer)
          Copies an char input stream into an char output stream.
static void copyStream(InputStream is, OutputStream os)
          Copies an inputstream into an output stream.
static File createJar(File baseDir, String jarName, Class... classes)
          Creates a JAR file with the specified classes.
static void delete(File file)
          Delete recursively a local directory.
static String getReaderAsString(Reader reader, int maxLen)
          Return a reader as string.
static Reader getResourceAsReader(String path, int maxLen)
          Return a classpath resource as a reader.
static InputStream getResourceAsStream(String path, int maxLen)
          Return a classpath resource as a stream.
static String getResourceAsString(String path, int maxLen)
          Return a classpath resource as string.
static void zipDir(File dir, String relativePath, ZipOutputStream zos)
          Zips a local directory, recursively, into a ZIP stream.
 
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
Delete recursively a local directory.

Parameters:
file - directory to delete.
Throws:
IOException - thrown if the directory could not be deleted.

getReaderAsString

public static String getReaderAsString(Reader reader,
                                       int maxLen)
                                throws IOException
Return a reader as string.

Parameters:
reader - reader to read into a string.
maxLen - max content length allowed, if -1 there is no limit.
Returns:
the reader content.
Throws:
IOException - thrown if the resource could not be read.

getResourceAsStream

public static InputStream getResourceAsStream(String path,
                                              int maxLen)
                                       throws IOException
Return a classpath resource as a stream.

Parameters:
path - classpath for the resource.
maxLen - max content length allowed.
Returns:
the stream for the resource.
Throws:
IOException - thrown if the resource could not be read.

getResourceAsReader

public static Reader getResourceAsReader(String path,
                                         int maxLen)
                                  throws IOException
Return a classpath resource as a reader.

It is assumed that the resource is a text resource.

Parameters:
path - classpath for the resource.
maxLen - max content length allowed.
Returns:
the reader for the resource.
Throws:
IOException - thrown if the resource could not be read.

getResourceAsString

public static String getResourceAsString(String path,
                                         int maxLen)
                                  throws IOException
Return a classpath resource as string.

It is assumed that the resource is a text resource.

Parameters:
path - classpath for the resource.
maxLen - max content length allowed.
Returns:
the resource content.
Throws:
IOException - thrown if the resource could not be read.

copyStream

public static void copyStream(InputStream is,
                              OutputStream os)
                       throws IOException
Copies an inputstream into an output stream.

Parameters:
is - inputstream to copy from.
os - outputstream to copy to.
Throws:
IOException - thrown if the copy failed.

copyCharStream

public static void copyCharStream(Reader reader,
                                  Writer writer)
                           throws IOException
Copies an char input stream into an char output stream.

Parameters:
reader - reader to copy from.
writer - writer to copy to.
Throws:
IOException - thrown if the copy failed.

zipDir

public static void zipDir(File dir,
                          String relativePath,
                          ZipOutputStream zos)
                   throws IOException
Zips a local directory, recursively, into a ZIP stream.

Parameters:
dir - directory to ZIP.
relativePath - basePath in the ZIP for the files, normally "/".
zos - the ZIP output stream to ZIP the directory.
Throws:
IOException - thrown if the directory could not be zipped.

createJar

public static File createJar(File baseDir,
                             String jarName,
                             Class... classes)
                      throws IOException
Creates a JAR file with the specified classes.

Parameters:
baseDir - local directory to create the JAR file, the staging 'classes' directory is created in there.
jarName - JAR file name, including extesion.
classes - classes to add to the JAR.
Returns:
an absolute File to the created JAR file.
Throws:
IOException - thrown if the JAR file could not be created.


Copyright © 2013 Apache Software Foundation. All Rights Reserved.