hudson.util
Class IOUtils

java.lang.Object
  extended by org.apache.commons.io.IOUtils
      extended by hudson.util.IOUtils

public class IOUtils
extends org.apache.commons.io.IOUtils

Adds more to commons-io.

Since:
1.337
Author:
Kohsuke Kawaguchi

Field Summary
 
Fields inherited from class org.apache.commons.io.IOUtils
DIR_SEPARATOR, DIR_SEPARATOR_UNIX, DIR_SEPARATOR_WINDOWS, LINE_SEPARATOR, LINE_SEPARATOR_UNIX, LINE_SEPARATOR_WINDOWS
 
Constructor Summary
IOUtils()
           
 
Method Summary
static File absolutize(File base, String path)
          Resolves the given path with respect to given base.
static void copy(File src, OutputStream out)
           
static void copy(InputStream in, File out)
           
static void drain(InputStream in)
          Drains the input stream and closes it.
static boolean isAbsolute(String path)
          See FilePath.isAbsolute(String).
static File mkdirs(File dir)
          Ensures that the given directory exists (if not, it's created, including all the parent directories.)
static int mode(File f)
          Gets the mode of a file/directory, if appropriate.
static String readFirstLine(InputStream is, String encoding)
          Read the first line of the given stream, close it, and return that line.
static InputStream skip(InputStream in, long size)
          Fully skips the specified size from the given input stream.
 
Methods inherited from class org.apache.commons.io.IOUtils
closeQuietly, closeQuietly, closeQuietly, closeQuietly, contentEquals, contentEquals, copy, copy, copy, copy, copy, copy, copyLarge, copyLarge, lineIterator, lineIterator, readLines, readLines, readLines, toByteArray, toByteArray, toByteArray, toByteArray, toCharArray, toCharArray, toCharArray, toInputStream, toInputStream, toString, toString, toString, toString, toString, write, write, write, write, write, write, write, write, write, write, write, write, writeLines, writeLines, writeLines
 
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

drain

public static void drain(InputStream in)
                  throws IOException
Drains the input stream and closes it.

Throws:
IOException

copy

public static void copy(File src,
                        OutputStream out)
                 throws IOException
Throws:
IOException

copy

public static void copy(InputStream in,
                        File out)
                 throws IOException
Throws:
IOException

mkdirs

public static File mkdirs(File dir)
                   throws IOException
Ensures that the given directory exists (if not, it's created, including all the parent directories.)

Returns:
This method returns the 'dir' parameter so that the method call flows better.
Throws:
IOException

skip

public static InputStream skip(InputStream in,
                               long size)
                        throws IOException
Fully skips the specified size from the given input stream.

InputStream.skip(long) has two problems. One is that it doesn't let us reliably differentiate "hit EOF" case vs "inpustream just returning 0 since there's no data currently available at hand", and some subtypes (such as FileInputStream.skip(long) returning -1.

So to reliably skip just the N bytes, we'll actually read all those bytes.

Throws:
IOException
Since:
1.349

absolutize

public static File absolutize(File base,
                              String path)
Resolves the given path with respect to given base. If the path represents an absolute path, a file representing it is returned, otherwise a file representing a path relative to base is returned.

It would be nice if File#File(File, String) were doing this.

Parameters:
base - File that represents the parent, may be null if path is absolute
path - Path of the file, may not be null
Returns:
new File(name) if name represents an absolute path, new File(base, name) otherwise
See Also:
FilePath.absolutize()

isAbsolute

public static boolean isAbsolute(String path)
See FilePath.isAbsolute(String).

Parameters:
path - String representing Platform Specific (unlike FilePath, which may get Platform agnostic paths), may not be null
Returns:
true if String represents absolute path on this platform, false otherwise

mode

public static int mode(File f)
                throws PosixException
Gets the mode of a file/directory, if appropriate.

Returns:
a file mode, or -1 if not on Unix
Throws:
PosixException - if the file could not be statted, e.g. broken symlink

readFirstLine

public static String readFirstLine(InputStream is,
                                   String encoding)
                            throws IOException
Read the first line of the given stream, close it, and return that line.

Parameters:
encoding - If null, use the platform default encoding.
Throws:
IOException
Since:
1.422


Copyright © 2004-2013. All Rights Reserved.