com.ecyrd.jspwiki
Class FileUtil

java.lang.Object
  extended by com.ecyrd.jspwiki.FileUtil

public class FileUtil
extends Object

Generic utilities related to file and stream handling.


Constructor Summary
FileUtil()
           
 
Method Summary
static void copyContents(InputStream in, OutputStream out)
          Just copies all characters from in to out.
static void copyContents(Reader in, Writer out)
          Just copies all characters from in to out.
static String getThrowingMethod(Throwable t)
           
static File newTmpFile(String content)
          Default encoding is ISO-8859-1
static File newTmpFile(String content, String encoding)
          Makes a new temporary file and writes content into it.
static String readContents(InputStream input, String encoding)
          Reads in file contents.
static String readContents(Reader in)
          Returns the full contents of the Reader as a String.
static String runSimpleCommand(String command, String directory)
          Runs a simple command in given directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

newTmpFile

public static File newTmpFile(String content,
                              String encoding)
                       throws IOException
Makes a new temporary file and writes content into it.

Parameters:
content - Initial content of the temporary file.
encoding - Encoding to use.
Returns:
The handle to the new temporary file
Throws:
IOException - If the content creation failed.

newTmpFile

public static File newTmpFile(String content)
                       throws IOException
Default encoding is ISO-8859-1

Throws:
IOException

runSimpleCommand

public static String runSimpleCommand(String command,
                                      String directory)
                               throws IOException,
                                      InterruptedException
Runs a simple command in given directory. The environment is inherited from the parent process.

Returns:
Standard output from the command.
Throws:
IOException
InterruptedException

copyContents

public static void copyContents(Reader in,
                                Writer out)
                         throws IOException
Just copies all characters from in to out.

Throws:
IOException
Since:
1.5.8

copyContents

public static void copyContents(InputStream in,
                                OutputStream out)
                         throws IOException
Just copies all characters from in to out.

Throws:
IOException
Since:
1.9.31

readContents

public static String readContents(InputStream input,
                                  String encoding)
                           throws IOException
Reads in file contents.

This method is smart and falls back to ISO-8859-1 if the input stream does not seem to be in the specified encoding.

Throws:
IOException

readContents

public static String readContents(Reader in)
                           throws IOException
Returns the full contents of the Reader as a String.

Throws:
IOException
Since:
1.5.8

getThrowingMethod

public static String getThrowingMethod(Throwable t)