com.knowgate.dfs
Class FileSystem

java.lang.Object
  extended by com.knowgate.dfs.FileSystem
Direct Known Subclasses:
FileSystemWorkArea

public class FileSystem
extends java.lang.Object

Abstract FileSystem object for encasulating NFS and FTP file transfer.

FileSystem can work in 100% Pure Java mode or using native operating system atomic calls.

This is an alpha state testing module.


Field Summary
static int OS_PUREJAVA
           
static int OS_UNIX
           
static int OS_WINDOWS
           
protected  java.lang.String SLASH
           
 
Constructor Summary
FileSystem()
          Create new File System Operation mode will be Pure Java by default User and Password fro FTP access wil be readed from hipergate.cnf file
FileSystem(int iMode)
          Create new File System Operation mode may be set for faster file access throught direct usage of operating system atomic calls.
FileSystem(int iMode, java.lang.String sUser, java.lang.String sPassword)
          Create new File System
FileSystem(java.util.Properties oProps)
           
FileSystem(java.lang.String sUser, java.lang.String sPassword)
          Create new File System Operation mode will be Pure Java by default
FileSystem(java.lang.String sUser, java.lang.String sPassword, java.lang.String sRealm)
          Create new File System Operation mode will be Pure Java by default
 
Method Summary
static void convert(java.lang.String sFilePath, java.lang.String sOldCharset, java.lang.String sNewCharset)
          Convert a text file from one character set to another The input file is overwritten.
 boolean copy(java.lang.String sSourceURI, java.lang.String sTargetURI)
          Copy a file This method is able to copy a file from local or network disk location to and FTP location or viceversa.
 boolean delete(java.lang.String sFullURI)
          Delete o file or directory Can recursively delete local or FTP directories
 boolean delete(java.lang.String sFullURI, java.lang.String sDeferedFiles)
          Mark an URI for deffered deletion Because web servers often cache and lock files as they are accessed, it is sometimes not possible to delete recently accessed files inmediately.
static java.lang.String detectEncoding(java.io.File oFile, java.lang.String sDefault)
          Detect file encoding
 java.lang.String detectEncoding(java.lang.String sFilePath, java.lang.String sDefault)
          Detect file encoding
 void downloadhtmlpage(java.lang.String sBasePath, java.lang.String sFilePath, java.io.OutputStream oOutStrm)
          Download an HTML page and all its referenced files into a ZIP
 boolean exists(java.lang.String sSourceURI)
          Checks whether a file or directory exists
protected  java.lang.String file()
           
 int filelen(java.lang.String sFullURI)
          Get file length Currently only local and network files length can be queried
protected  java.lang.String host()
           
 boolean mkdirs(java.lang.String sFullURI)
          Create a complete directory branch.
 boolean move(java.lang.String sSourceURI, java.lang.String sTargetURI)
          Move a file from one location to another
 void os(int iOperatingSystem)
           
 java.lang.String password()
           
 void password(java.lang.String sPassword)
           
protected  java.lang.String path()
           
static char[] readfile(java.lang.String sFilePath)
          Read a text file and returns a character array with it Enconding is UTF-8 by default
static char[] readfile(java.lang.String sFilePath, java.lang.String sCharSet)
          Read a text file and returns a character array with it
 byte[] readfilebin(java.lang.String sFilePath)
          Read a binary file into a byte array
 java.lang.Object readfileobj(java.lang.String sFilePath)
          Read a serializable object from a text file
 java.lang.String readfilestr(java.lang.String sFilePath, java.lang.String sEncoding)
          Read a text file into a String
 java.lang.String realm()
           
 boolean rename(java.lang.String sSourceURI, java.lang.String sTargetURI)
          Rename file
 boolean rmdir(java.lang.String sFullURI)
          Remove a directory and all its subdirectories and files.
protected  void splitURI(java.lang.String sURI)
           
 java.lang.String user()
           
 void user(java.lang.String sUser)
           
 void writefilebin(java.lang.String sFilePath, byte[] aBytes)
          Write a byte array to a text file
 void writefileobj(java.lang.String sFilePath, java.io.Serializable oObj)
          Write a serializable object to a text file
 void writefilestr(java.lang.String sFilePath, java.lang.String sText, java.lang.String sEncoding)
          Write a String to a text file using given encoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SLASH

protected java.lang.String SLASH

OS_PUREJAVA

public static final int OS_PUREJAVA
See Also:
Constant Field Values

OS_UNIX

public static final int OS_UNIX
See Also:
Constant Field Values

OS_WINDOWS

public static final int OS_WINDOWS
See Also:
Constant Field Values
Constructor Detail

FileSystem

public FileSystem()
           throws java.lang.NumberFormatException,
                  java.lang.IllegalArgumentException

Create new File System

Operation mode will be Pure Java by default

User and Password fro FTP access wil be readed from hipergate.cnf file

Throws:
java.lang.NumberFormatException - If javamode property is not a positive integer number.
java.lang.IllegalArgumentException - If javamode property is not 0, 1 or 2.

FileSystem

public FileSystem(int iMode)

Create new File System

Operation mode may be set for faster file access throught direct usage of operating system atomic calls.

User and Password fro FTP access wil be readed from hipergate.cnf file

Parameters:
iMode - Operation Mode { OS_PUREJAVA | OS_UNIX | OS_WINDOWS }

FileSystem

public FileSystem(java.lang.String sUser,
                  java.lang.String sPassword)

Create new File System

Operation mode will be Pure Java by default

Parameters:
sUser - User for FTP access
sPassword - Password for FTP access

FileSystem

public FileSystem(java.lang.String sUser,
                  java.lang.String sPassword,
                  java.lang.String sRealm)

Create new File System

Operation mode will be Pure Java by default

Parameters:
sUser - User for FTP access
sPassword - Password for FTP access
sRealm - Realm for HTTP authentication
Since:
4.0

FileSystem

public FileSystem(int iMode,
                  java.lang.String sUser,
                  java.lang.String sPassword)

Create new File System

Parameters:
iMode - Operation Mode: OS_PUREJAVA or OS_UNIX or OS_WINDOWS
sUser - User for FTP access
sPassword - Password for FTP access

FileSystem

public FileSystem(java.util.Properties oProps)
           throws java.lang.NumberFormatException,
                  java.lang.IllegalArgumentException
Parameters:
oProps - Properties collection.
Property names:
javamode : "0" (default) for Pure Java, "1" for UNIX, "2" for Windows.
fileuser : User for FTP access (default is "anonymous"). filepassword : Password for FTP access (default is "").
Throws:
java.lang.NumberFormatException - If javamode property is not a positive integer number.
java.lang.IllegalArgumentException - If javamode property is not 0, 1 or 2.
Method Detail

os

public void os(int iOperatingSystem)
Parameters:
iOperatingSystem - = { FileSystem.OS_PUREJAVA, FileSystem.OS_UNIX, FileSystem.OS_WINDOWS }

user

public void user(java.lang.String sUser)
Parameters:
sUser - user for FTP access

user

public java.lang.String user()
Returns:
user for FTP access.

password

public void password(java.lang.String sPassword)
Parameters:
sPassword - Password for FTP or HTTP access

password

public java.lang.String password()
Returns:
Password for FTP or HTTP access

realm

public java.lang.String realm()
Returns:
Realm for HTTP access

host

protected java.lang.String host()

path

protected java.lang.String path()

file

protected java.lang.String file()

splitURI

protected void splitURI(java.lang.String sURI)

copy

public boolean copy(java.lang.String sSourceURI,
                    java.lang.String sTargetURI)
             throws java.net.MalformedURLException,
                    java.io.IOException,
                    java.lang.Exception

Copy a file

This method is able to copy a file from local or network disk location to and FTP location or viceversa.

Parameters:
sSourceURI - Source URI, it must have the following syntax: protocol://[server:[port]]/path/filename Even whe working with local files protocol must be specified, ej. copy ("file:///tmp/upload/image.jpg", "file:///opt/storage/approved/image.jpg")
sTargetURI - Target URI
Throws:
java.lang.Exception
java.io.IOException
java.net.MalformedURLException

exists

public boolean exists(java.lang.String sSourceURI)
               throws java.io.IOException
Checks whether a file or directory exists

Parameters:
sSouceURI - Source URI (including protocol preffix)
Throws:
java.io.IOException
Since:
4.0

filelen

public int filelen(java.lang.String sFullURI)
            throws java.io.IOException

Get file length

Currently only local and network files length can be queried

Parameters:
sFullURI - File URI (protocol+path)
Returns:
File length in bytes
Throws:
java.io.IOException

rmdir

public boolean rmdir(java.lang.String sFullURI)
              throws java.io.IOException
Remove a directory and all its subdirectories and files.

Parameters:
sFullURI - Directory URI. For example: file:///tmp/upload
Returns:
true if Directory was successfully deleted. This return value should always be checked as Java functions may not return any error but not delete a directory that is in use by another process.
Throws:
java.io.IOException

delete

public boolean delete(java.lang.String sFullURI)
               throws java.io.IOException

Delete o file or directory

Can recursively delete local or FTP directories

Parameters:
sFullURI - File or directory URI. For example ftp://localhost/opt/temp/upload/logo.gif
Returns:
true if File or Directory was successfully deleted. This return value should always be checked as Java functions may not return any error but not delete a directory or file that is in use by another process.
Throws:
java.io.IOException

delete

public boolean delete(java.lang.String sFullURI,
                      java.lang.String sDeferedFiles)
               throws java.io.IOException

Mark an URI for deffered deletion

Because web servers often cache and lock files as they are accessed, it is sometimes not possible to delete recently accessed files inmediately. This method just appends the given URI at the end of a plain text file containing a list of file names. This file name list can be later used upon Web Server re-start for purging files that could no be deleted before because they where locked.

Parameters:
sFullURI - File URI to delete, ej. file:///opt/knowgate/files/deleteme.txt
sDeferedFiles - Local path to file containing delete list
Throws:
java.io.IOException

move

public boolean move(java.lang.String sSourceURI,
                    java.lang.String sTargetURI)
             throws java.lang.Exception,
                    java.io.IOException

Move a file from one location to another

Parameters:
sSourceURI - Source URI
sTargetURI - Target URI
Returns:
Throws:
java.lang.Exception
java.io.IOException

rename

public boolean rename(java.lang.String sSourceURI,
                      java.lang.String sTargetURI)
               throws java.lang.Exception,
                      java.io.IOException,
                      java.net.ProtocolException
Rename file

Parameters:
sSourceURI - Source URI (ej. "file:///tmp/files/oldfile.txt")
sTargetURI - Target URI (ej. "file:///tmp/files/newfile.txt")
Throws:
java.lang.Exception
java.io.IOException
java.net.ProtocolException - If source and target file does not use the same protocol, either file:// or ftp://
Since:
2.1

mkdirs

public boolean mkdirs(java.lang.String sFullURI)
               throws java.lang.Exception,
                      java.io.IOException

Create a complete directory branch.

Parameters:
sFullURI - Full path of directory to create, ej. file:///tmp/uploads/binaries/images ej. ftp://ftpserver/tmp/uploads/binaries/images
Throws:
java.lang.Exception
java.io.IOException

convert

public static void convert(java.lang.String sFilePath,
                           java.lang.String sOldCharset,
                           java.lang.String sNewCharset)
                    throws java.io.FileNotFoundException,
                           java.io.IOException,
                           java.io.UnsupportedEncodingException

Convert a text file from one character set to another

The input file is overwritten.

Parameters:
sFilePath - File Path
sOldCharset - Original file character set
sNewCharset - New character set
Throws:
java.io.FileNotFoundException
java.io.IOException
java.io.UnsupportedEncodingException

detectEncoding

public static java.lang.String detectEncoding(java.io.File oFile,
                                              java.lang.String sDefault)
                                       throws java.io.FileNotFoundException,
                                              java.io.IOException
Detect file encoding

Parameters:
oFile - File
sDefault - String Character encoding to be returned if no clear character encoding was identified
Returns:
String UTF-16LE, UTF-16BE or UTF-8
Throws:
java.io.FileNotFoundException
java.io.IOException
Since:
3.1

detectEncoding

public java.lang.String detectEncoding(java.lang.String sFilePath,
                                       java.lang.String sDefault)
                                throws java.io.FileNotFoundException,
                                       java.io.IOException,
                                       com.enterprisedt.net.ftp.FTPException
Detect file encoding

Parameters:
sFilePath - File Path including protocol. Like "file:///tmp/myfile.txt" or "ftp://myhost:21/dir/myfile.txt"
sDefault - String Character encoding to be returned if no clear character encoding was identified
Returns:
String UTF-16LE, UTF-16BE or UTF-8
Throws:
java.io.FileNotFoundException
java.io.IOException
com.enterprisedt.net.ftp.FTPException
Since:
3.1

readfile

public static char[] readfile(java.lang.String sFilePath)
                       throws java.io.FileNotFoundException,
                              java.io.IOException,
                              java.lang.OutOfMemoryError,
                              com.enterprisedt.net.ftp.FTPException

Read a text file and returns a character array with it

Enconding is UTF-8 by default

Parameters:
sFilePath - Full path of file to be readed. Like "file:///tmp/myfile.txt" or "ftp://myhost:21/dir/myfile.txt"
Returns:
character array with full contents of file
Throws:
java.io.FileNotFoundException
java.io.IOException
java.lang.OutOfMemoryError
com.enterprisedt.net.ftp.FTPException

readfile

public static char[] readfile(java.lang.String sFilePath,
                              java.lang.String sCharSet)
                       throws java.io.FileNotFoundException,
                              java.io.IOException,
                              java.lang.OutOfMemoryError,
                              com.enterprisedt.net.ftp.FTPException

Read a text file and returns a character array with it

Parameters:
sFilePath - Full path of file to be readed. Like "file:///tmp/myfile.txt" or "ftp://myhost:21/dir/myfile.txt"
sCharSet - Encoding character set name
Returns:
character array with full contents of file
Throws:
java.io.FileNotFoundException
java.io.IOException
java.lang.OutOfMemoryError
com.enterprisedt.net.ftp.FTPException

readfilebin

public byte[] readfilebin(java.lang.String sFilePath)
                   throws java.net.MalformedURLException,
                          com.enterprisedt.net.ftp.FTPException,
                          java.io.FileNotFoundException,
                          java.io.IOException,
                          java.lang.OutOfMemoryError

Read a binary file into a byte array

Parameters:
sFilePath - Full path of file to be readed. Like "file:///tmp/myfile.txt" or "ftp://myhost:21/dir/myfile.txt"
Returns:
byte array with full contents of file
Throws:
java.io.FileNotFoundException
java.io.IOException
java.lang.OutOfMemoryError
java.net.MalformedURLException
com.enterprisedt.net.ftp.FTPException

readfilestr

public java.lang.String readfilestr(java.lang.String sFilePath,
                                    java.lang.String sEncoding)
                             throws java.net.MalformedURLException,
                                    com.enterprisedt.net.ftp.FTPException,
                                    java.io.FileNotFoundException,
                                    java.io.IOException,
                                    java.lang.OutOfMemoryError

Read a text file into a String

Parameters:
sFilePath - Full path of file to be readed. Like "file:///tmp/myfile.txt" or "ftp://myhost:21/dir/myfile.txt"
sEncoding - Text Encoding for file {UTF-8, ISO-8859-1, ...}
if null then if first two bytes of file are FF FE then UTF-8 will be assumed
else ISO-8859-1 will be assumed.
Returns:
String with full contents of file
Throws:
java.io.FileNotFoundException
java.io.IOException
java.lang.OutOfMemoryError
java.net.MalformedURLException
com.enterprisedt.net.ftp.FTPException

writefilestr

public void writefilestr(java.lang.String sFilePath,
                         java.lang.String sText,
                         java.lang.String sEncoding)
                  throws java.io.IOException,
                         java.lang.OutOfMemoryError
Write a String to a text file using given encoding

Parameters:
sFilePath - Full file path. For example "file:///tmp/myfile.txt" or "ftp://localhost:21/tmp/myfile.txt"
sText - String to be written
sEncoding - Encoding to be used see Java Supported Encodings
Throws:
java.io.IOException
java.lang.OutOfMemoryError

writefilebin

public void writefilebin(java.lang.String sFilePath,
                         byte[] aBytes)
                  throws java.io.IOException
Write a byte array to a text file

Parameters:
sFilePath - Full file path. For example "file:///tmp/myfile.bin" or "ftp://localhost:21/tmp/myfile.bin"
aBytes - Bytes to be written
Throws:
java.io.IOException
Since:
3.0

readfileobj

public java.lang.Object readfileobj(java.lang.String sFilePath)
                             throws java.net.MalformedURLException,
                                    java.io.FileNotFoundException,
                                    java.io.IOException,
                                    com.enterprisedt.net.ftp.FTPException,
                                    java.lang.ClassNotFoundException
Read a serializable object from a text file

Parameters:
sFilePath - Full file path. For example "file:///tmp/myfile.bin" or "ftp://localhost:21/tmp/myfile.bin"
Throws:
java.net.MalformedURLException - if sFilePath does not begin with file://or ftp://
java.lang.ClassNotFoundException
java.io.FileNotFoundException
java.io.IOException
com.enterprisedt.net.ftp.FTPException
Since:
4.0

writefileobj

public void writefileobj(java.lang.String sFilePath,
                         java.io.Serializable oObj)
                  throws java.io.IOException
Write a serializable object to a text file

Parameters:
sFilePath - Full file path. For example "file:///tmp/myfile.bin" or "ftp://localhost:21/tmp/myfile.bin"
oObj - Serializable object to be written
Throws:
java.io.IOException
Since:
4.0

downloadhtmlpage

public void downloadhtmlpage(java.lang.String sBasePath,
                             java.lang.String sFilePath,
                             java.io.OutputStream oOutStrm)
                      throws java.io.IOException
Download an HTML page and all its referenced files into a ZIP

Parameters:
sBasePath - String Base path for page and its referenced files
sFilePath - String File path from sBasePath
oOutStrm - OutputStream where ZIP is written
Throws:
java.io.IOException
Since:
5.5