SmartFrog 3.10.000

org.smartfrog.services.filesystem
Class FileSystem

java.lang.Object
  extended by org.smartfrog.services.filesystem.FileSystem

public class FileSystem
extends java.lang.Object

Filesystem operations


Field Summary
static int BUF_SIZE
           
static java.lang.String ERROR_FILE_IS_A_DIRECTORY
           
static java.lang.String ERROR_INACCESSIBLE_FILE
           
static java.lang.String ERROR_UNDEPLOYED_CD
          Error text when a looked up reference resolves to something that is not yet deployed.
 
Method Summary
static void close(java.nio.channels.FileChannel channel)
          Close a channel; do nothing if null.
static void close(java.io.InputStream stream)
          Close a stream; do nothing if null.
static void close(java.io.OutputStream stream)
          Close a stream; do nothing if null.
static void close(java.io.Reader channel)
          Close a reader; do nothing if null.
static void close(java.io.Writer channel)
          Close a stream; do nothing if null.
static long copy(java.io.InputStream in, java.io.OutputStream out, byte[] copyBuffer)
          Copies an InputStream to an OutputStream using the specified buffer.
static java.io.File createTempDir(java.lang.String prefix, java.lang.String suffix, java.lang.String parent)
          Create a temp directory in the directory named, with the given prefix and suffix.
static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix, java.lang.String dir)
          Create a temp file in the directory names, with the given prefix and suffix.
static void fCopy(java.io.File src, java.io.File dest)
          Copies a File to a File
static void fCopy(java.io.FileInputStream src, java.io.File dest)
          Copies an FileInputStream to a File
static long fCopy(java.io.InputStream in, java.io.File outputFile)
          Copies an InputStream to a file All streams are closed afterwards.
static long fCopy(java.io.InputStream in, java.io.OutputStream out)
          Copies an InputStream to an OutputStream using a local internal buffer for performance.
static void fCopy(Prim src, Prim dest)
          Copies a File to a File
static long globalBufferCopy(java.io.InputStream in, java.io.OutputStream out)
          Copies an InputStream to an OutputStream using a global internal buffer for performance.
static java.lang.String lookupAbsolutePath(Prim component, Reference attribute, java.lang.String defval, java.io.File baseDir, boolean mandatory, PlatformHelper platform)
          This static call is a helper for any component that wants to get either an absolute path or a FileIntf binding to an attribute.
static java.lang.String lookupAbsolutePath(Prim component, java.lang.String attribute, java.lang.String defval, java.io.File baseDir, boolean mandatory, PlatformHelper platform)
          This static call is a helper for any component that wants to get either an absolute path or a FileIntf binding to an attribute.
static java.lang.StringBuffer readFile(java.io.File file)
          Read a file fully into a string buffer.
static void recursiveDelete(java.io.File dir)
          recursive directory deletion.
static java.io.File resolveAbsolutePath(Prim component)
          Look up the absolutePath attribute of any component, then turn it into a file.
static java.lang.StringBuffer tail(java.io.File file, int numLines)
          Reads last (numLines) lines from end of a file.
static java.lang.StringBuffer tail(java.lang.String filepath, int numLines)
          Get the tail of a file
static java.io.File tempDir(java.lang.String prefix, java.lang.String suffix, java.io.File dir)
          Create a temporary file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_UNDEPLOYED_CD

public static final java.lang.String ERROR_UNDEPLOYED_CD
Error text when a looked up reference resolves to something that is not yet deployed. "This attribute resolvesto a not-yet-deployed component: "

See Also:
Constant Field Values

ERROR_INACCESSIBLE_FILE

public static final java.lang.String ERROR_INACCESSIBLE_FILE
See Also:
Constant Field Values

ERROR_FILE_IS_A_DIRECTORY

public static final java.lang.String ERROR_FILE_IS_A_DIRECTORY
See Also:
Constant Field Values

BUF_SIZE

public static final int BUF_SIZE
See Also:
Constant Field Values
Method Detail

close

public static void close(java.io.InputStream stream)
Close a stream; do nothing if null. Ignore all thrown IOExceptions

Parameters:
stream - inputstream to close

close

public static void close(java.io.OutputStream stream)
Close a stream; do nothing if null. Ignore all thrown IOExceptions

Parameters:
stream - output stream to close

close

public static void close(java.io.Writer channel)
Close a stream; do nothing if null. Ignore all thrown IOExceptions

Parameters:
channel - writer channel to close

close

public static void close(java.io.Reader channel)
Close a reader; do nothing if null. Ignore all thrown IOExceptions

Parameters:
channel - reader channel to close

close

public static void close(java.nio.channels.FileChannel channel)
Close a channel; do nothing if null. Ignore all thrown IOExceptions

Parameters:
channel - file channel to close

tempDir

public static java.io.File tempDir(java.lang.String prefix,
                                   java.lang.String suffix,
                                   java.io.File dir)
                            throws java.io.IOException
Create a temporary file. There is a very small, very very small, race condition here as we delete the temp file and recreate it as a dir. This may also be a security risk in the right hands.

Parameters:
prefix - prefix
suffix - suffix -include the . for a .ext style suffix
dir - parent dir; use null for java.io.tmpdir
Returns:
File
Throws:
java.io.IOException - error in creating file

recursiveDelete

public static void recursiveDelete(java.io.File dir)
recursive directory deletion. If handed a file, will delete that.

Parameters:
dir - directory

lookupAbsolutePath

public static java.lang.String lookupAbsolutePath(Prim component,
                                                  Reference attribute,
                                                  java.lang.String defval,
                                                  java.io.File baseDir,
                                                  boolean mandatory,
                                                  PlatformHelper platform)
                                           throws SmartFrogResolutionException,
                                                  java.rmi.RemoteException
This static call is a helper for any component that wants to get either an absolute path or a FileIntf binding to an attribute. The attribute is looked up on a component. If it is bound to anything that implements FileIntf, then that component is asked for an absolute path. if it is bound to a string, then the string is turned into an absolute path, relative to any directory named, after the string is converted into platform appropriate forward/back slashes.

Parameters:
component - component to look up the path from
attribute - the name of the attribute to look up
defval - a default value. This should already be in the local format for the target platform, and absolute. Can be null. No used when mandatory is true
baseDir - optional base directory for a relative file when constructing from a string
mandatory - flag that triggers the throwing of a SmartFrogResolutionException when things go wrong
platform - a platform to use for converting filetypes. Set to null to use the default helper for this platform.
Returns:
the absolute path
Throws:
SmartFrogResolutionException - error in resolving
java.rmi.RemoteException - In case of network/rmi error

lookupAbsolutePath

public static java.lang.String lookupAbsolutePath(Prim component,
                                                  java.lang.String attribute,
                                                  java.lang.String defval,
                                                  java.io.File baseDir,
                                                  boolean mandatory,
                                                  PlatformHelper platform)
                                           throws SmartFrogResolutionException,
                                                  java.rmi.RemoteException
This static call is a helper for any component that wants to get either an absolute path or a FileIntf binding to an attribute. The attribute is looked up on a component. If it is bound to anything that implements FileIntf, then that component is asked for an absolute path. if it is bound to a string, then the string is turned into an absolute path, relative to any directory named, after the string is converted into platform appropriate forward/back slashes.

Parameters:
component - component to look up the path from
attribute - the name of the attribute to look up
defval - a default value. This should already be in the local format for the target platform, and absolute. Can be null. Not used when mandatory is true
baseDir - optional base directory for a relative file when constructing from a string
mandatory - flag that triggers the throwing of a SmartFrogResolutionException when things go wrong
platform - a platform to use for converting filetypes. Set to null to use the default helper for this platform.
Returns:
the resolved absolute path
Throws:
SmartFrogResolutionException - error in resolving
java.rmi.RemoteException - In case of network/rmi error

resolveAbsolutePath

public static java.io.File resolveAbsolutePath(Prim component)
                                        throws SmartFrogResolutionException,
                                               java.rmi.RemoteException
Look up the absolutePath attribute of any component, then turn it into a file.

Parameters:
component - component to resolve against
Returns:
file representing the path.
Throws:
SmartFrogResolutionException - If the attribute is not defined.
java.rmi.RemoteException - In case of network/rmi error

fCopy

public static void fCopy(Prim src,
                         Prim dest)
                  throws java.io.IOException,
                         SmartFrogResolutionException
Copies a File to a File

Parameters:
src - File
dest - File
Throws:
java.io.IOException - for IO Trouble
SmartFrogResolutionException - if the source or dest doesnt have a filename

fCopy

public static void fCopy(java.io.File src,
                         java.io.File dest)
                  throws java.io.IOException
Copies a File to a File

Parameters:
src - File
dest - File
Throws:
java.io.IOException - if an I/O error occurs (may result in partially done work)

fCopy

public static void fCopy(java.io.FileInputStream src,
                         java.io.File dest)
                  throws java.io.IOException
Copies an FileInputStream to a File

Parameters:
src - FileInputStream
dest - File
Throws:
java.io.IOException - if an I/O error occurs (may result in partially done work)

fCopy

public static long fCopy(java.io.InputStream in,
                         java.io.File outputFile)
                  throws java.io.IOException
Copies an InputStream to a file All streams are closed afterwards.

Parameters:
in - stream to copy from
outputFile - file to copy to
Returns:
the number of bytes copied
Throws:
java.io.IOException - if an I/O error occurs (may result in partially done work)

fCopy

public static long fCopy(java.io.InputStream in,
                         java.io.OutputStream out)
                  throws java.io.IOException
Copies an InputStream to an OutputStream using a local internal buffer for performance. Compared to globalBufferCopy(InputStream, OutputStream) this method allows for better concurrency, but each time it is called generates a buffer which will be garbage.

All streams are closed afterwards.

Parameters:
in - stream to copy from
out - stream to copy to
Returns:
the number of bytes copied
Throws:
java.io.IOException - if an I/O error occurs (may result in partially done work)
See Also:
globalBufferCopy(InputStream, OutputStream)

globalBufferCopy

public static long globalBufferCopy(java.io.InputStream in,
                                    java.io.OutputStream out)
                             throws java.io.IOException
Copies an InputStream to an OutputStream using a global internal buffer for performance. Compared to fCopy(InputStream, OutputStream) this method generated no garbage, but decreases concurrency. All streams are closed afterwards.

Parameters:
in - stream to copy from
out - stream to copy to
Returns:
the number of bytes copied
Throws:
java.io.IOException - if an I/O error occurs (may result in partially done work)
See Also:
fCopy(InputStream, OutputStream)

copy

public static long copy(java.io.InputStream in,
                        java.io.OutputStream out,
                        byte[] copyBuffer)
                 throws java.io.IOException
Copies an InputStream to an OutputStream using the specified buffer. All streams are closed afterwards.

Parameters:
in - stream to copy from
out - stream to copy to
copyBuffer - buffer used for copying
Returns:
the number of bytes copied
Throws:
java.io.IOException - if an I/O error occurs (may result in partially done work)
See Also:
globalBufferCopy(InputStream, OutputStream), fCopy(InputStream, OutputStream)

readFile

public static java.lang.StringBuffer readFile(java.io.File file)
                                       throws java.io.IOException
Read a file fully into a string buffer.

Parameters:
file - file to read
Returns:
StringBuffer
Throws:
java.io.IOException - if an I/O error occurs (may result in partially done work)

tail

public static java.lang.StringBuffer tail(java.io.File file,
                                          int numLines)
                                   throws java.io.IOException
Reads last (numLines) lines from end of a file.

Parameters:
file - file to read
numLines - number of lines (last) to read
Returns:
StringBuffer
Throws:
java.io.IOException - if an I/O error occurs (may result in partially done work)

tail

public static java.lang.StringBuffer tail(java.lang.String filepath,
                                          int numLines)
                                   throws java.io.IOException
Get the tail of a file

Parameters:
filepath - file to read
numLines - number of lines (last) to read
Returns:
StringBuffer
Throws:
java.io.IOException - if an I/O error occurs (may result in partially done work)

createTempFile

public static java.io.File createTempFile(java.lang.String prefix,
                                          java.lang.String suffix,
                                          java.lang.String dir)
                                   throws SmartFrogException
Create a temp file in the directory names, with the given prefix and suffix. Also creates any parent directories

Parameters:
prefix - prefix -required.
suffix - suffix, e,g. ".ext";
dir - parent dir; can be null
Returns:
the directory.
Throws:
SmartFrogException - a wrapper for any IOException.

createTempDir

public static java.io.File createTempDir(java.lang.String prefix,
                                         java.lang.String suffix,
                                         java.lang.String parent)
                                  throws SmartFrogException
Create a temp directory in the directory named, with the given prefix and suffix. This is done by creating a temp file, deleting it and creating a dir of the same name. There is a fractional moment of race condition there, where bad things could happen.

Parameters:
parent - parent dir; can be null
prefix - prefix -required.
suffix - suffix, e,g. ".ext";
Returns:
the directory.
Throws:
SmartFrogException - a wrapper for any IOException.

SmartFrog CORE 3.10.000

(C) Copyright 1998-2006 Hewlett-Packard Development Company, LP