Package hudson.util
Class IOUtils
- java.lang.Object
-
- hudson.util.IOUtils
-
public class IOUtils extends Object
Adds more to commons-io.- Since:
- 1.337
- Author:
- Kohsuke Kawaguchi
-
-
Field Summary
Fields Modifier and Type Field Description static char
DIR_SEPARATOR
Deprecated.Use insteadIOUtils.DIR_SEPARATOR
static char
DIR_SEPARATOR_UNIX
Deprecated.Use insteadIOUtils.DIR_SEPARATOR_UNIX
static char
DIR_SEPARATOR_WINDOWS
Deprecated.Use insteadIOUtils.DIR_SEPARATOR_WINDOWS
static String
LINE_SEPARATOR
Deprecated.Use insteadIOUtils.LINE_SEPARATOR
static String
LINE_SEPARATOR_UNIX
Deprecated.Use insteadIOUtils.LINE_SEPARATOR_UNIX
static String
LINE_SEPARATOR_WINDOWS
Deprecated.Use insteadIOUtils.LINE_SEPARATOR_WINDOWS
-
Constructor Summary
Constructors Constructor Description IOUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static File
absolutize(File base, String path)
Resolves the given path with respect to given base.static void
closeQuietly(InputStream input)
Deprecated.Use Java 7try
-with-resources instead.static void
closeQuietly(OutputStream output)
Deprecated.Use Java 7try
-with-resources instead.static void
closeQuietly(Reader input)
Deprecated.Use Java 7try
-with-resources instead.static void
closeQuietly(Writer output)
Deprecated.Use Java 7try
-with-resources instead.static boolean
contentEquals(InputStream input1, InputStream input2)
Deprecated.Use insteadIOUtils.contentEquals(java.io.InputStream, java.io.InputStream)
static boolean
contentEquals(Reader input1, Reader input2)
Deprecated.Use insteadIOUtils.contentEquals(java.io.Reader, java.io.Reader)
static void
copy(File src, OutputStream out)
static void
copy(InputStream in, File out)
static int
copy(InputStream input, OutputStream output)
Deprecated.Use insteadIOUtils.copy(java.io.InputStream, java.io.OutputStream)
static void
copy(InputStream input, Writer output)
Deprecated.Use insteadIOUtils.copy(java.io.InputStream, java.io.Writer)
static void
copy(InputStream input, Writer output, String encoding)
Deprecated.Use insteadIOUtils.copy(java.io.InputStream, java.io.Writer, String)
static void
copy(Reader input, OutputStream output)
Deprecated.Use insteadIOUtils.copy(java.io.Reader, java.io.OutputStream)
static void
copy(Reader input, OutputStream output, String encoding)
Deprecated.Use insteadIOUtils.copy(java.io.Reader, java.io.OutputStream, String)
static int
copy(Reader input, Writer output)
Deprecated.Use insteadIOUtils.copy(java.io.Reader, java.io.Writer)
static long
copyLarge(InputStream input, OutputStream output)
Deprecated.Use insteadIOUtils.copyLarge(java.io.InputStream, java.io.OutputStream)
static long
copyLarge(Reader input, Writer output)
Deprecated.Use insteadIOUtils.copyLarge(java.io.Reader, java.io.Writer)
static void
drain(InputStream in)
Drains the input stream and closes it.static boolean
isAbsolute(String path)
static org.apache.commons.io.LineIterator
lineIterator(InputStream input, String encoding)
Deprecated.Use insteadIOUtils.lineIterator(java.io.InputStream, String)
static org.apache.commons.io.LineIterator
lineIterator(Reader reader)
Deprecated.Use insteadIOUtils.lineIterator(java.io.Reader)
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 List
readLines(InputStream input)
Deprecated.Use insteadIOUtils.readLines(java.io.InputStream)
static List
readLines(InputStream input, String encoding)
Deprecated.Use insteadIOUtils.readLines(java.io.InputStream, String)
static List
readLines(Reader input)
Deprecated.Use insteadIOUtils.readLines(java.io.Reader)
static InputStream
skip(InputStream in, long size)
Fully skips the specified size from the given input stream.static byte[]
toByteArray(InputStream input)
Deprecated.Use insteadIOUtils.toByteArray(java.io.InputStream)
static byte[]
toByteArray(Reader input)
Deprecated.Use insteadIOUtils.toByteArray(java.io.Reader)
static byte[]
toByteArray(Reader input, String encoding)
Deprecated.Use insteadIOUtils.toByteArray(java.io.Reader, String)
static byte[]
toByteArray(String input)
Deprecated.Use insteadIOUtils.toByteArray(String)
static char[]
toCharArray(InputStream is)
Deprecated.Use insteadIOUtils.toCharArray(java.io.InputStream)
static char[]
toCharArray(InputStream is, String encoding)
Deprecated.Use insteadIOUtils.toCharArray(java.io.InputStream, String)
static char[]
toCharArray(Reader input)
Deprecated.Use insteadIOUtils.toCharArray(java.io.Reader)
static InputStream
toInputStream(String input)
Deprecated.Use insteadIOUtils.toInputStream(String)
static InputStream
toInputStream(String input, String encoding)
Deprecated.Use insteadIOUtils.toInputStream(String, String)
static String
toString(byte[] input)
Deprecated.Use insteadIOUtils.toString(byte[])
static String
toString(byte[] input, String encoding)
Deprecated.Use insteadIOUtils.toString(byte[], String)
static String
toString(InputStream input)
Deprecated.Use insteadIOUtils.toString(java.io.InputStream)
static String
toString(InputStream input, String encoding)
Deprecated.Use insteadIOUtils.toString(java.io.InputStream, String)
static String
toString(Reader input)
Deprecated.Use insteadIOUtils.toString(java.io.Reader)
static void
write(byte[] data, OutputStream output)
Deprecated.Use insteadIOUtils.write(byte[], java.io.OutputStream)
static void
write(byte[] data, Writer output)
Deprecated.Use insteadIOUtils.write(byte[], java.io.Writer)
static void
write(byte[] data, Writer output, String encoding)
Deprecated.Use insteadIOUtils.write(byte[], java.io.Writer, String)
static void
write(char[] data, OutputStream output)
Deprecated.Use insteadIOUtils.write(char[], java.io.OutputStream)
static void
write(char[] data, OutputStream output, String encoding)
Deprecated.Use insteadIOUtils.write(char[], java.io.OutputStream, String)
static void
write(char[] data, Writer output)
Deprecated.Use insteadIOUtils.write(char[], java.io.OutputStream)
static void
write(StringBuffer data, OutputStream output)
Deprecated.Use insteadIOUtils.write(StringBuffer, java.io.OutputStream)
static void
write(StringBuffer data, OutputStream output, String encoding)
Deprecated.Use insteadIOUtils.write(StringBuffer, java.io.OutputStream, String)
static void
write(StringBuffer data, Writer output)
Deprecated.Use insteadIOUtils.write(StringBuffer, java.io.Writer)
static void
write(String data, OutputStream output)
Deprecated.Use insteadIOUtils.write(String, java.io.OutputStream)
static void
write(String data, OutputStream output, String encoding)
Deprecated.Use insteadIOUtils.write(String, java.io.OutputStream, String)
static void
write(String data, Writer output)
Deprecated.Use insteadIOUtils.write(char[], java.io.Writer)
static void
writeLines(Collection lines, String lineEnding, OutputStream output)
Deprecated.Use insteadIOUtils.writeLines(java.util.Collection, String, java.io.OutputStream)
static void
writeLines(Collection lines, String lineEnding, OutputStream output, String encoding)
Deprecated.Use insteadIOUtils.writeLines(java.util.Collection, String, java.io.OutputStream, String)
static void
writeLines(Collection lines, String lineEnding, Writer writer)
Deprecated.Use insteadIOUtils.writeLines(java.util.Collection, String, java.io.Writer)
-
-
-
Field Detail
-
DIR_SEPARATOR_UNIX
@Deprecated public static final char DIR_SEPARATOR_UNIX
Deprecated.Use insteadIOUtils.DIR_SEPARATOR_UNIX
- See Also:
- Constant Field Values
-
DIR_SEPARATOR_WINDOWS
@Deprecated public static final char DIR_SEPARATOR_WINDOWS
Deprecated.Use insteadIOUtils.DIR_SEPARATOR_WINDOWS
- See Also:
- Constant Field Values
-
DIR_SEPARATOR
@Deprecated public static final char DIR_SEPARATOR
Deprecated.Use insteadIOUtils.DIR_SEPARATOR
-
LINE_SEPARATOR_UNIX
@Deprecated public static final String LINE_SEPARATOR_UNIX
Deprecated.Use insteadIOUtils.LINE_SEPARATOR_UNIX
-
LINE_SEPARATOR_WINDOWS
@Deprecated public static final String LINE_SEPARATOR_WINDOWS
Deprecated.Use insteadIOUtils.LINE_SEPARATOR_WINDOWS
-
LINE_SEPARATOR
@Deprecated public static final String LINE_SEPARATOR
Deprecated.Use insteadIOUtils.LINE_SEPARATOR
-
-
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 "inputstream just returning 0 since there's no data currently available at hand", and some subtypes (such asFileInputStream.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 absolutepath
- 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)
- Parameters:
path
- String representingPlatform 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 IOException
Gets the mode of a file/directory, if appropriate. Only includes read, write, and execute permissions for the owner, group, and others, i.e. the max return value is 0777. Consider usingFiles.getPosixFilePermissions(java.nio.file.Path, java.nio.file.LinkOption...)
instead if you only care about access permissions.If the file is symlink, the mode is that of the link target, not the link itself.
- Returns:
- a file mode, or -1 if not on Unix
- Throws:
IOException
- 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
-
closeQuietly
@Deprecated public static void closeQuietly(Reader input)
Deprecated.Use Java 7try
-with-resources instead.
-
closeQuietly
@Deprecated public static void closeQuietly(Writer output)
Deprecated.Use Java 7try
-with-resources instead.
-
closeQuietly
@Deprecated public static void closeQuietly(InputStream input)
Deprecated.Use Java 7try
-with-resources instead.
-
closeQuietly
@Deprecated public static void closeQuietly(OutputStream output)
Deprecated.Use Java 7try
-with-resources instead.
-
toByteArray
@Deprecated public static byte[] toByteArray(InputStream input) throws IOException
Deprecated.Use insteadIOUtils.toByteArray(java.io.InputStream)
- Throws:
IOException
-
toByteArray
@Deprecated public static byte[] toByteArray(Reader input) throws IOException
Deprecated.Use insteadIOUtils.toByteArray(java.io.Reader)
- Throws:
IOException
-
toByteArray
@Deprecated public static byte[] toByteArray(Reader input, String encoding) throws IOException
Deprecated.Use insteadIOUtils.toByteArray(java.io.Reader, String)
- Throws:
IOException
-
toByteArray
@Deprecated public static byte[] toByteArray(String input) throws IOException
Deprecated.Use insteadIOUtils.toByteArray(String)
- Throws:
IOException
-
toCharArray
@Deprecated public static char[] toCharArray(InputStream is) throws IOException
Deprecated.Use insteadIOUtils.toCharArray(java.io.InputStream)
- Throws:
IOException
-
toCharArray
@Deprecated public static char[] toCharArray(InputStream is, String encoding) throws IOException
Deprecated.Use insteadIOUtils.toCharArray(java.io.InputStream, String)
- Throws:
IOException
-
toCharArray
@Deprecated public static char[] toCharArray(Reader input) throws IOException
Deprecated.Use insteadIOUtils.toCharArray(java.io.Reader)
- Throws:
IOException
-
toString
@Deprecated public static String toString(InputStream input) throws IOException
Deprecated.Use insteadIOUtils.toString(java.io.InputStream)
- Throws:
IOException
-
toString
@Deprecated public static String toString(InputStream input, String encoding) throws IOException
Deprecated.Use insteadIOUtils.toString(java.io.InputStream, String)
- Throws:
IOException
-
toString
@Deprecated public static String toString(Reader input) throws IOException
Deprecated.Use insteadIOUtils.toString(java.io.Reader)
- Throws:
IOException
-
toString
@Deprecated public static String toString(byte[] input) throws IOException
Deprecated.Use insteadIOUtils.toString(byte[])
- Throws:
IOException
-
toString
@Deprecated public static String toString(byte[] input, String encoding) throws IOException
Deprecated.Use insteadIOUtils.toString(byte[], String)
- Throws:
IOException
-
readLines
@Deprecated public static List readLines(InputStream input) throws IOException
Deprecated.Use insteadIOUtils.readLines(java.io.InputStream)
- Throws:
IOException
-
readLines
@Deprecated public static List readLines(InputStream input, String encoding) throws IOException
Deprecated.Use insteadIOUtils.readLines(java.io.InputStream, String)
- Throws:
IOException
-
readLines
@Deprecated public static List readLines(Reader input) throws IOException
Deprecated.Use insteadIOUtils.readLines(java.io.Reader)
- Throws:
IOException
-
lineIterator
@Deprecated public static org.apache.commons.io.LineIterator lineIterator(Reader reader)
Deprecated.Use insteadIOUtils.lineIterator(java.io.Reader)
-
lineIterator
@Deprecated public static org.apache.commons.io.LineIterator lineIterator(InputStream input, String encoding) throws IOException
Deprecated.Use insteadIOUtils.lineIterator(java.io.InputStream, String)
- Throws:
IOException
-
toInputStream
@Deprecated public static InputStream toInputStream(String input)
Deprecated.Use insteadIOUtils.toInputStream(String)
-
toInputStream
@Deprecated public static InputStream toInputStream(String input, String encoding) throws IOException
Deprecated.Use insteadIOUtils.toInputStream(String, String)
- Throws:
IOException
-
write
@Deprecated public static void write(byte[] data, OutputStream output) throws IOException
Deprecated.Use insteadIOUtils.write(byte[], java.io.OutputStream)
- Throws:
IOException
-
write
@Deprecated public static void write(byte[] data, Writer output) throws IOException
Deprecated.Use insteadIOUtils.write(byte[], java.io.Writer)
- Throws:
IOException
-
write
@Deprecated public static void write(byte[] data, Writer output, String encoding) throws IOException
Deprecated.Use insteadIOUtils.write(byte[], java.io.Writer, String)
- Throws:
IOException
-
write
@Deprecated public static void write(char[] data, Writer output) throws IOException
Deprecated.Use insteadIOUtils.write(char[], java.io.OutputStream)
- Throws:
IOException
-
write
@Deprecated public static void write(char[] data, OutputStream output) throws IOException
Deprecated.Use insteadIOUtils.write(char[], java.io.OutputStream)
- Throws:
IOException
-
write
@Deprecated public static void write(char[] data, OutputStream output, String encoding) throws IOException
Deprecated.Use insteadIOUtils.write(char[], java.io.OutputStream, String)
- Throws:
IOException
-
write
@Deprecated public static void write(String data, Writer output) throws IOException
Deprecated.Use insteadIOUtils.write(char[], java.io.Writer)
- Throws:
IOException
-
write
@Deprecated public static void write(String data, OutputStream output) throws IOException
Deprecated.Use insteadIOUtils.write(String, java.io.OutputStream)
- Throws:
IOException
-
write
@Deprecated public static void write(String data, OutputStream output, String encoding) throws IOException
Deprecated.Use insteadIOUtils.write(String, java.io.OutputStream, String)
- Throws:
IOException
-
write
@Deprecated public static void write(StringBuffer data, Writer output) throws IOException
Deprecated.Use insteadIOUtils.write(StringBuffer, java.io.Writer)
- Throws:
IOException
-
write
@Deprecated public static void write(StringBuffer data, OutputStream output) throws IOException
Deprecated.Use insteadIOUtils.write(StringBuffer, java.io.OutputStream)
- Throws:
IOException
-
write
@Deprecated public static void write(StringBuffer data, OutputStream output, String encoding) throws IOException
Deprecated.Use insteadIOUtils.write(StringBuffer, java.io.OutputStream, String)
- Throws:
IOException
-
writeLines
@Deprecated public static void writeLines(Collection lines, String lineEnding, OutputStream output) throws IOException
Deprecated.Use insteadIOUtils.writeLines(java.util.Collection, String, java.io.OutputStream)
- Throws:
IOException
-
writeLines
@Deprecated public static void writeLines(Collection lines, String lineEnding, OutputStream output, String encoding) throws IOException
Deprecated.Use insteadIOUtils.writeLines(java.util.Collection, String, java.io.OutputStream, String)
- Throws:
IOException
-
writeLines
@Deprecated public static void writeLines(Collection lines, String lineEnding, Writer writer) throws IOException
Deprecated.Use insteadIOUtils.writeLines(java.util.Collection, String, java.io.Writer)
- Throws:
IOException
-
copy
@Deprecated public static int copy(InputStream input, OutputStream output) throws IOException
Deprecated.Use insteadIOUtils.copy(java.io.InputStream, java.io.OutputStream)
- Throws:
IOException
-
copyLarge
@Deprecated public static long copyLarge(InputStream input, OutputStream output) throws IOException
Deprecated.Use insteadIOUtils.copyLarge(java.io.InputStream, java.io.OutputStream)
- Throws:
IOException
-
copy
@Deprecated public static void copy(InputStream input, Writer output) throws IOException
Deprecated.Use insteadIOUtils.copy(java.io.InputStream, java.io.Writer)
- Throws:
IOException
-
copy
@Deprecated public static void copy(InputStream input, Writer output, String encoding) throws IOException
Deprecated.Use insteadIOUtils.copy(java.io.InputStream, java.io.Writer, String)
- Throws:
IOException
-
copy
@Deprecated public static int copy(Reader input, Writer output) throws IOException
Deprecated.Use insteadIOUtils.copy(java.io.Reader, java.io.Writer)
- Throws:
IOException
-
copyLarge
@Deprecated public static long copyLarge(Reader input, Writer output) throws IOException
Deprecated.Use insteadIOUtils.copyLarge(java.io.Reader, java.io.Writer)
- Throws:
IOException
-
copy
@Deprecated public static void copy(Reader input, OutputStream output) throws IOException
Deprecated.Use insteadIOUtils.copy(java.io.Reader, java.io.OutputStream)
- Throws:
IOException
-
copy
@Deprecated public static void copy(Reader input, OutputStream output, String encoding) throws IOException
Deprecated.Use insteadIOUtils.copy(java.io.Reader, java.io.OutputStream, String)
- Throws:
IOException
-
contentEquals
@Deprecated public static boolean contentEquals(InputStream input1, InputStream input2) throws IOException
Deprecated.Use insteadIOUtils.contentEquals(java.io.InputStream, java.io.InputStream)
- Throws:
IOException
-
contentEquals
@Deprecated public static boolean contentEquals(Reader input1, Reader input2) throws IOException
Deprecated.Use insteadIOUtils.contentEquals(java.io.Reader, java.io.Reader)
- Throws:
IOException
-
-