com.ecyrd.jspwiki
Class FileUtil

java.lang.Object
  |
  +--com.ecyrd.jspwiki.FileUtil

public class FileUtil
extends java.lang.Object

Generic utilities related to file and stream handling.


Constructor Summary
FileUtil()
           
 
Method Summary
static void copyContents(java.io.InputStream in, java.io.OutputStream out)
          Just copies all characters 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.io.File newTmpFile(java.lang.String content)
          Default encoding is ISO-8859-1
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.
 
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 java.io.File newTmpFile(java.lang.String content,
                                      java.lang.String encoding)
                               throws java.io.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:
java.io.IOException - If the content creation failed.

newTmpFile

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

java.io.IOException

runSimpleCommand

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

Returns:
Standard output from the command.
java.io.IOException
java.lang.InterruptedException

copyContents

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

java.io.IOException
Since:
1.5.8

copyContents

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

java.io.IOException
Since:
1.9.31

readContents

public static java.lang.String readContents(java.io.InputStream input,
                                            java.lang.String encoding)
                                     throws java.io.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.

java.io.IOException

readContents

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

java.io.IOException
Since:
1.5.8