public final class FileUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
copyContents(java.io.InputStream in,
java.io.OutputStream out)
Just copies all bytes from in to out.
|
static void |
copyContents(java.io.Reader in,
java.io.Writer out)
Just copies all characters from in to out.
|
static java.lang.String |
getThrowingMethod(java.lang.Throwable t)
Returns the class and method name (+a line number) in which the
Throwable was thrown.
|
static java.io.File |
newTmpFile(java.lang.String content)
Creates a new temporary file using the default encoding
of ISO-8859-1 (Latin1).
|
static java.io.File |
newTmpFile(java.lang.String content,
java.lang.String encoding)
Makes a new temporary file and writes content into it.
|
static java.lang.String |
readContents(java.io.InputStream input,
java.lang.String encoding)
Reads in file contents.
|
static java.lang.String |
readContents(java.io.Reader in)
Returns the full contents of the Reader as a String.
|
static java.lang.String |
runSimpleCommand(java.lang.String command,
java.lang.String directory)
Runs a simple command in given directory.
|
public static java.io.File newTmpFile(java.lang.String content, java.lang.String encoding) throws java.io.IOException
File.createTempFile()
, and the usual
semantics apply. The files are not deleted automatically in exit.content
- Initial content of the temporary file.encoding
- Encoding to use.java.io.IOException
- If the content creation failed.File.createTempFile(String,String,File)
public static java.io.File newTmpFile(java.lang.String content) throws java.io.IOException
content
- The content to put into the file.java.io.IOException
- If writing was unsuccessful.newTmpFile( String, String )
,
File.createTempFile(String,String,File)
public static java.lang.String runSimpleCommand(java.lang.String command, java.lang.String directory) throws java.io.IOException, java.lang.InterruptedException
command
- The command to rundirectory
- The working directory to run the command injava.io.IOException
- If the command failedjava.lang.InterruptedException
- If the command was haltedpublic static void copyContents(java.io.Reader in, java.io.Writer out) throws java.io.IOException
in
- The reader to copy fromout
- The reader to copy tojava.io.IOException
- If reading or writing failed.public static void copyContents(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- The inputstream to copy fromout
- The outputstream to copy tojava.io.IOException
- In case reading or writing fails.public static java.lang.String readContents(java.io.InputStream input, java.lang.String encoding) throws java.io.IOException
This method is smart and falls back to ISO-8859-1 if the input stream does not seem to be in the specified encoding.
input
- The InputStream to read from.encoding
- The encoding to assume at first.java.io.IOException
- If the stream cannot be read or the stream cannot be
decoded (even) in Latin1public static java.lang.String readContents(java.io.Reader in) throws java.io.IOException
in
- The reader from which the contents shall be read.java.io.IOException
- If reading fails.public static java.lang.String getThrowingMethod(java.lang.Throwable t)
t
- A Throwable to analyze.stSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.