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
-
-
Constructor Summary
Constructors Constructor Description IOUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Fileabsolutize(File base, String path)Resolves the given path with respect to given base.static voidcloseQuietly(InputStream input)Deprecated.Use Java 7try-with-resources instead.static voidcloseQuietly(OutputStream output)Deprecated.Use Java 7try-with-resources instead.static voidcloseQuietly(Reader input)Deprecated.Use Java 7try-with-resources instead.static voidcloseQuietly(Writer output)Deprecated.Use Java 7try-with-resources instead.static booleancontentEquals(InputStream input1, InputStream input2)Deprecated.Use insteadIOUtils.contentEquals(java.io.InputStream, java.io.InputStream)static booleancontentEquals(Reader input1, Reader input2)Deprecated.Use insteadIOUtils.contentEquals(java.io.Reader, java.io.Reader)static voidcopy(File src, OutputStream out)static voidcopy(InputStream in, File out)static intcopy(InputStream input, OutputStream output)Deprecated.Use insteadIOUtils.copy(java.io.InputStream, java.io.OutputStream)static voidcopy(InputStream input, Writer output)Deprecated.Use insteadIOUtils.copy(java.io.InputStream, java.io.Writer)static voidcopy(InputStream input, Writer output, String encoding)Deprecated.Use insteadIOUtils.copy(java.io.InputStream, java.io.Writer, String)static voidcopy(Reader input, OutputStream output)Deprecated.Use insteadIOUtils.copy(java.io.Reader, java.io.OutputStream)static voidcopy(Reader input, OutputStream output, String encoding)Deprecated.Use insteadIOUtils.copy(java.io.Reader, java.io.OutputStream, String)static intcopy(Reader input, Writer output)Deprecated.Use insteadIOUtils.copy(java.io.Reader, java.io.Writer)static longcopyLarge(InputStream input, OutputStream output)Deprecated.Use insteadIOUtils.copyLarge(java.io.InputStream, java.io.OutputStream)static longcopyLarge(Reader input, Writer output)Deprecated.Use insteadIOUtils.copyLarge(java.io.Reader, java.io.Writer)static voiddrain(InputStream in)Drains the input stream and closes it.static booleanisAbsolute(String path)static org.apache.commons.io.LineIteratorlineIterator(InputStream input, String encoding)Deprecated.Use insteadIOUtils.lineIterator(java.io.InputStream, String)static org.apache.commons.io.LineIteratorlineIterator(Reader reader)Deprecated.Use insteadIOUtils.lineIterator(java.io.Reader)static Filemkdirs(File dir)Ensures that the given directory exists (if not, it's created, including all the parent directories.)static intmode(File f)Gets the mode of a file/directory, if appropriate.static StringreadFirstLine(InputStream is, String encoding)Read the first line of the given stream, close it, and return that line.static ListreadLines(InputStream input)Deprecated.Use insteadIOUtils.readLines(java.io.InputStream)static ListreadLines(InputStream input, String encoding)Deprecated.Use insteadIOUtils.readLines(java.io.InputStream, String)static ListreadLines(Reader input)Deprecated.Use insteadIOUtils.readLines(java.io.Reader)static InputStreamskip(InputStream in, long size)Deprecated.useIOUtils.skipFully(InputStream, long)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 InputStreamtoInputStream(String input)Deprecated.Use insteadIOUtils.toInputStream(String)static InputStreamtoInputStream(String input, String encoding)Deprecated.Use insteadIOUtils.toInputStream(String, String)static StringtoString(byte[] input)Deprecated.Use insteadIOUtils.toString(byte[])static StringtoString(byte[] input, String encoding)Deprecated.Use insteadIOUtils.toString(byte[], String)static StringtoString(InputStream input)Deprecated.Use insteadIOUtils.toString(java.io.InputStream)static StringtoString(InputStream input, String encoding)Deprecated.Use insteadIOUtils.toString(java.io.InputStream, String)static StringtoString(Reader input)Deprecated.Use insteadIOUtils.toString(java.io.Reader)static voidwrite(byte[] data, OutputStream output)Deprecated.Use insteadIOUtils.write(byte[], java.io.OutputStream)static voidwrite(byte[] data, Writer output)Deprecated.Use insteadIOUtils.write(byte[], java.io.Writer)static voidwrite(byte[] data, Writer output, String encoding)Deprecated.Use insteadIOUtils.write(byte[], java.io.Writer, String)static voidwrite(char[] data, OutputStream output)Deprecated.Use insteadIOUtils.write(char[], java.io.OutputStream)static voidwrite(char[] data, OutputStream output, String encoding)Deprecated.Use insteadIOUtils.write(char[], java.io.OutputStream, String)static voidwrite(char[] data, Writer output)Deprecated.Use insteadIOUtils.write(char[], java.io.OutputStream)static voidwrite(StringBuffer data, OutputStream output)Deprecated.Use insteadIOUtils.write(StringBuffer, java.io.OutputStream)static voidwrite(StringBuffer data, OutputStream output, String encoding)Deprecated.Use insteadIOUtils.write(StringBuffer, java.io.OutputStream, String)static voidwrite(StringBuffer data, Writer output)Deprecated.Use insteadIOUtils.write(StringBuffer, java.io.Writer)static voidwrite(String data, OutputStream output)Deprecated.Use insteadIOUtils.write(String, java.io.OutputStream)static voidwrite(String data, OutputStream output, String encoding)Deprecated.Use insteadIOUtils.write(String, java.io.OutputStream, String)static voidwrite(String data, Writer output)Deprecated.Use insteadIOUtils.write(char[], java.io.Writer)static voidwriteLines(Collection lines, String lineEnding, OutputStream output)Deprecated.Use insteadIOUtils.writeLines(java.util.Collection, String, java.io.OutputStream)static voidwriteLines(Collection lines, String lineEnding, OutputStream output, String encoding)Deprecated.Use insteadIOUtils.writeLines(java.util.Collection, String, java.io.OutputStream, String)static voidwriteLines(Collection lines, String lineEnding, Writer writer)Deprecated.Use insteadIOUtils.writeLines(java.util.Collection, String, java.io.Writer)
-
-
-
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
@Deprecated public static InputStream skip(InputStream in, long size) throws IOException
Deprecated.useIOUtils.skipFully(InputStream, long)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
-
-