nl.justobjects.toolkit.io
Class IO

java.lang.Object
  |
  +--nl.justobjects.toolkit.io.IO

public class IO
extends java.lang.Object

Various I/O and Unix-type utilities.

Version:
$Id: IO.java,v 1.27 2003/01/06 00:23:48 just Exp $
Author:
$Author: just $ - Just van den Broecke - Just Objects B.V. ©

Field Summary
static int bufferSize
           
 
Constructor Summary
IO()
           
 
Method Summary
static java.lang.Object bytesToObject(byte[] data)
          Creates an Object from a bytearray containing a serialized Object.
static void copy(java.io.InputStream in, java.io.OutputStream out)
          Copy Stream in to Stream out until EOF or exception.
static void copy(java.io.InputStream in, java.io.OutputStream out, long byteCount)
          Copy Stream in to Stream out until EOF or exception.
static void cp(java.lang.String from, java.lang.String to)
          Standard UNIX-style file copy.
static void cpdir(java.lang.String from, java.lang.String to)
          Recursively copies directory.
static void createFilePath(java.lang.String fileName)
          Create directory path if none exists for a filename.
static java.lang.String[] DataInputStreamToStringArray(java.io.DataInputStream dis)
          Return contents of DataInputStream as String array.
static java.lang.String[] dir2StringArray(java.lang.String dir, java.lang.String skip)
          Make recursive list of directories and files.
static java.lang.String escapeMarkup(java.lang.String string)
          Replace < in String with < (HTML/XML escape)
static java.lang.String exec(java.lang.String[] commandLine)
          Execute external program.
static java.lang.String FileToString(java.lang.String fileName)
          Return contents of file as String.
static java.lang.String[] FileToStringArray(java.lang.String fileName)
          Return contents of file as array of String.
static java.util.Properties getProperties(java.io.InputStream inputStream)
          Make Properties object from Properties InputStream.
static java.util.Properties getProperties(java.lang.String name)
          Make Properties object from file or URL.
static java.util.Properties getProperties(java.net.URL url)
          Make Properties object from URL.
static java.util.Properties getProperties(java.net.URL baseURL, java.lang.String file)
          Make Properties object from URL.
static java.util.Properties getPropertiesFromClassPath(java.lang.String path)
          Make Properties object from file retrieved through CLASSPATH.
static java.lang.String getResourceFromClassPath(java.lang.String path)
          Get real file name for file retrieved through CLASSPATH.
static java.lang.String[] grep(java.lang.String aFile, java.lang.String aGrepString)
          Very basic grep: return lines in file that contain exact string.
static void main(java.lang.String[] args)
          Only used to test above methods.
static void mkdir(java.lang.String dirPath)
          Creates multiple directories according to path.
static void mv(java.lang.String from, java.lang.String to)
          Standard UNIX-style file move.
static boolean newer(java.io.File file1, java.lang.String file2)
          Compare modification dates of two files.
static boolean newer(java.lang.String file1, java.lang.String file2)
          Compare modification dates of two files.
static byte[] objectToBytes(java.lang.Object obj)
          Create an array of bytes from an Object.
static void p(java.lang.String s)
           
static java.lang.String replaceToken(java.lang.String string, java.lang.String fromToken, java.lang.String toToken)
          Replace all tokens in a string with new token.
static void replaceTokensInFile(java.lang.String fileName, java.lang.String fromToken, java.lang.String toToken)
          Replace all tokens in a file with new token.
static void resourceToFile(java.lang.String resourceName, java.lang.String fileName)
          Copy resource found in CLASSPATH to a File.
static boolean rm(java.lang.String fileName)
          Standard UNIX-style file remove of file.
static boolean rmdir(java.lang.String dirName)
          Recursive remove of (non-empty) directory tree.
static void StringArrayToFile(java.lang.String name, java.lang.String[] toBeWritten)
          Write a String array to a File
static void StringToFile(java.lang.String name, java.lang.String toBeWritten)
          Write a String to a File
static void StringToFile(java.lang.String name, java.lang.String toBeWritten, boolean append)
          Write a String to a File
static void StringToOutputStream(java.io.OutputStream os, java.lang.String toBeWritten)
          Write a String to an OutputStream
static java.lang.String url2String(java.lang.String anUrlString)
          Return contents of URL as String.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

bufferSize

public static int bufferSize
Constructor Detail

IO

public IO()
Method Detail

cpdir

public static void cpdir(java.lang.String from,
                         java.lang.String to)
                  throws java.io.IOException
Recursively copies directory.

cp

public static void cp(java.lang.String from,
                      java.lang.String to)
               throws java.io.IOException
Standard UNIX-style file copy.

createFilePath

public static void createFilePath(java.lang.String fileName)
                           throws java.io.IOException
Create directory path if none exists for a filename.

exec

public static java.lang.String exec(java.lang.String[] commandLine)
                             throws java.io.IOException
Execute external program.

grep

public static java.lang.String[] grep(java.lang.String aFile,
                                      java.lang.String aGrepString)
                               throws java.io.IOException
Very basic grep: return lines in file that contain exact string.

mv

public static void mv(java.lang.String from,
                      java.lang.String to)
               throws java.io.IOException
Standard UNIX-style file move.

mkdir

public static void mkdir(java.lang.String dirPath)
                  throws java.io.IOException
Creates multiple directories according to path.

newer

public static boolean newer(java.lang.String file1,
                            java.lang.String file2)
Compare modification dates of two files.

newer

public static boolean newer(java.io.File file1,
                            java.lang.String file2)
Compare modification dates of two files.

escapeMarkup

public static java.lang.String escapeMarkup(java.lang.String string)
Replace < in String with < (HTML/XML escape)

dir2StringArray

public static java.lang.String[] dir2StringArray(java.lang.String dir,
                                                 java.lang.String skip)
Make recursive list of directories and files.

FileToStringArray

public static java.lang.String[] FileToStringArray(java.lang.String fileName)
Return contents of file as array of String.
Parameters:
name - the filename

DataInputStreamToStringArray

public static java.lang.String[] DataInputStreamToStringArray(java.io.DataInputStream dis)
Return contents of DataInputStream as String array.
Parameters:
dis - the DataInputStream

FileToString

public static java.lang.String FileToString(java.lang.String fileName)
Return contents of file as String.
Parameters:
name - the filename

resourceToFile

public static void resourceToFile(java.lang.String resourceName,
                                  java.lang.String fileName)
                           throws java.lang.Exception
Copy resource found in CLASSPATH to a File.
Parameters:
resourceName - the resource name
fileName - the file to copy to

StringToFile

public static void StringToFile(java.lang.String name,
                                java.lang.String toBeWritten)
Write a String to a File
Parameters:
name - the filename
toBeWritten - the String to write

StringToFile

public static void StringToFile(java.lang.String name,
                                java.lang.String toBeWritten,
                                boolean append)
Write a String to a File
Parameters:
name - the filename
toBeWritten - the String to write

StringArrayToFile

public static void StringArrayToFile(java.lang.String name,
                                     java.lang.String[] toBeWritten)
Write a String array to a File
Parameters:
name - the filename
toBeWritten - the String array to write

StringToOutputStream

public static void StringToOutputStream(java.io.OutputStream os,
                                        java.lang.String toBeWritten)
Write a String to an OutputStream
Parameters:
os - the OutputStream
toBeWritten - the String to write

copy

public static void copy(java.io.InputStream in,
                        java.io.OutputStream out)
                 throws java.io.IOException
Copy Stream in to Stream out until EOF or exception.

replaceToken

public static java.lang.String replaceToken(java.lang.String string,
                                            java.lang.String fromToken,
                                            java.lang.String toToken)
Replace all tokens in a string with new token.

replaceTokensInFile

public static void replaceTokensInFile(java.lang.String fileName,
                                       java.lang.String fromToken,
                                       java.lang.String toToken)
Replace all tokens in a file with new token.

copy

public static void copy(java.io.InputStream in,
                        java.io.OutputStream out,
                        long byteCount)
                 throws java.io.IOException
Copy Stream in to Stream out until EOF or exception.

p

public static void p(java.lang.String s)

bytesToObject

public static java.lang.Object bytesToObject(byte[] data)
Creates an Object from a bytearray containing a serialized Object.
Parameters:
data[] - the byte array containing the serialized object.
Returns:
Object the object.

objectToBytes

public static byte[] objectToBytes(java.lang.Object obj)
Create an array of bytes from an Object.
Parameters:
obj - Het object.
Returns:
byte[] the serialized Object.

getProperties

public static java.util.Properties getProperties(java.lang.String name)
Make Properties object from file or URL.

getProperties

public static java.util.Properties getProperties(java.net.URL baseURL,
                                                 java.lang.String file)
Make Properties object from URL.

getProperties

public static java.util.Properties getProperties(java.io.InputStream inputStream)
Make Properties object from Properties InputStream.

getProperties

public static java.util.Properties getProperties(java.net.URL url)
Make Properties object from URL.

getPropertiesFromClassPath

public static java.util.Properties getPropertiesFromClassPath(java.lang.String path)
                                                       throws java.lang.Exception
Make Properties object from file retrieved through CLASSPATH.

getResourceFromClassPath

public static java.lang.String getResourceFromClassPath(java.lang.String path)
                                                 throws java.lang.Exception
Get real file name for file retrieved through CLASSPATH.

rm

public static boolean rm(java.lang.String fileName)
                  throws java.io.IOException
Standard UNIX-style file remove of file.

rmdir

public static boolean rmdir(java.lang.String dirName)
                     throws java.io.IOException
Recursive remove of (non-empty) directory tree.

url2String

public static java.lang.String url2String(java.lang.String anUrlString)
Return contents of URL as String.
Parameters:
name - the filename

main

public static void main(java.lang.String[] args)
Only used to test above methods.


Copyright © 2000-2001 - Just Objects B.V.