Package hudson.util
Class IOUtils
java.lang.Object
hudson.util.IOUtils
Adds more to commons-io.
- Since:
- 1.337
- Author:
- Kohsuke Kawaguchi
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
absolutize
(File base, String path) Resolves the given path with respect to given base.static void
closeQuietly
(InputStream input) Deprecated.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
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
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) SeeFilePath.isAbsolute(String)
.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
Ensures that the given directory exists (if not, it's created, including all the parent directories.)static int
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
Deprecated.Use insteadIOUtils.readLines(java.io.Reader)
static InputStream
skip
(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[]
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
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
Deprecated.Use insteadIOUtils.toString(java.io.Reader)
static void
write
(byte[] data, OutputStream output) Deprecated.Use insteadIOUtils.write(byte[], java.io.OutputStream)
static void
Deprecated.Use insteadIOUtils.write(byte[], java.io.Writer)
static void
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
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
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)
-
Constructor Details
-
IOUtils
public IOUtils()
-
-
Method Details
-
drain
Drains the input stream and closes it.- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
mkdirs
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.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
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:
-
isAbsolute
SeeFilePath.isAbsolute(String)
.- 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
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
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.Use Java 7try
-with-resources instead. -
closeQuietly
Deprecated.Use Java 7try
-with-resources instead. -
closeQuietly
Deprecated.Use Java 7try
-with-resources instead. -
closeQuietly
Deprecated.Use Java 7try
-with-resources instead. -
toByteArray
Deprecated.Use insteadIOUtils.toByteArray(java.io.InputStream)
- Throws:
IOException
-
toByteArray
Deprecated.Use insteadIOUtils.toByteArray(java.io.Reader)
- Throws:
IOException
-
toByteArray
Deprecated.Use insteadIOUtils.toByteArray(java.io.Reader, String)
- Throws:
IOException
-
toByteArray
Deprecated.Use insteadIOUtils.toByteArray(String)
- Throws:
IOException
-
toCharArray
Deprecated.Use insteadIOUtils.toCharArray(java.io.InputStream)
- Throws:
IOException
-
toCharArray
Deprecated.Use insteadIOUtils.toCharArray(java.io.InputStream, String)
- Throws:
IOException
-
toCharArray
Deprecated.Use insteadIOUtils.toCharArray(java.io.Reader)
- Throws:
IOException
-
toString
Deprecated.Use insteadIOUtils.toString(java.io.InputStream)
- Throws:
IOException
-
toString
Deprecated.Use insteadIOUtils.toString(java.io.InputStream, String)
- Throws:
IOException
-
toString
Deprecated.Use insteadIOUtils.toString(java.io.Reader)
- Throws:
IOException
-
toString
Deprecated.Use insteadIOUtils.toString(byte[])
- Throws:
IOException
-
toString
Deprecated.Use insteadIOUtils.toString(byte[], String)
- Throws:
IOException
-
readLines
Deprecated.Use insteadIOUtils.readLines(java.io.InputStream)
- Throws:
IOException
-
readLines
Deprecated.Use insteadIOUtils.readLines(java.io.InputStream, String)
- Throws:
IOException
-
readLines
Deprecated.Use insteadIOUtils.readLines(java.io.Reader)
- Throws:
IOException
-
lineIterator
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.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.Use insteadIOUtils.write(byte[], java.io.OutputStream)
- Throws:
IOException
-
write
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.Use insteadIOUtils.write(char[], java.io.OutputStream)
- Throws:
IOException
-
write
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.Use insteadIOUtils.write(char[], java.io.Writer)
- Throws:
IOException
-
write
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.Use insteadIOUtils.write(StringBuffer, java.io.Writer)
- Throws:
IOException
-
write
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.Use insteadIOUtils.copy(java.io.InputStream, java.io.OutputStream)
- Throws:
IOException
-
copyLarge
Deprecated.Use insteadIOUtils.copyLarge(java.io.InputStream, java.io.OutputStream)
- Throws:
IOException
-
copy
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.Use insteadIOUtils.copy(java.io.Reader, java.io.Writer)
- Throws:
IOException
-
copyLarge
Deprecated.Use insteadIOUtils.copyLarge(java.io.Reader, java.io.Writer)
- Throws:
IOException
-
copy
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.Use insteadIOUtils.contentEquals(java.io.Reader, java.io.Reader)
- Throws:
IOException
-
try
-with-resources instead.