Constructor and Description |
---|
IOUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
closeSafely(Closeable... objects)
Close a list of resources.
|
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.
|
public IOUtils()
public static void delete(File file) throws IOException
file
- directory to delete.IOException
- thrown if the directory could not be deleted.public static String getReaderAsString(Reader reader, int maxLen) throws IOException
reader
- reader to read into a string.maxLen
- max content length allowed, if -1 there is no limit.IOException
- thrown if the resource could not be read.public static InputStream getResourceAsStream(String path, int maxLen) throws IOException
path
- classpath for the resource.maxLen
- max content length allowed.IOException
- thrown if the resource could not be read.public static Reader getResourceAsReader(String path, int maxLen) throws IOException
It is assumed that the resource is a text resource.
path
- classpath for the resource.maxLen
- max content length allowed.IOException
- thrown if the resource could not be read.public static String getResourceAsString(String path, int maxLen) throws IOException
It is assumed that the resource is a text resource.
path
- classpath for the resource.maxLen
- max content length allowed.IOException
- thrown if the resource could not be read.public static void copyStream(InputStream is, OutputStream os) throws IOException
is
- inputstream to copy from.os
- outputstream to copy to.IOException
- thrown if the copy failed.public static void copyCharStream(Reader reader, Writer writer) throws IOException
reader
- reader to copy from.writer
- writer to copy to.IOException
- thrown if the copy failed.public static void zipDir(File dir, String relativePath, ZipOutputStream zos) throws IOException
dir
- directory to ZIP.relativePath
- basePath in the ZIP for the files, normally "/".zos
- the ZIP output stream to ZIP the directory.IOException
- thrown if the directory could not be zipped.public static File createJar(File baseDir, String jarName, Class... classes) throws IOException
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.IOException
- thrown if the JAR file could not be created.public static void closeSafely(Closeable... objects)
Any thrown exceptions are suppressed.
objects
- list of objects to closeCopyright © 2018 Apache Software Foundation. All rights reserved.