OBEROn SDK

com.oberon.util
Class FileUtils

java.lang.Object
  extended by com.oberon.util.FileUtils

public class FileUtils
extends java.lang.Object

Utilities for file (Local,FTP,HTTP) manipulation

Version:
5.0

Constructor Summary
FileUtils()
           
 
Method Summary
static void cleanDirs(java.lang.String path)
          Remove all files from a local directory and its sub-directories
static void cleanFTPDirs(com.oberon.ooql.ftp.FTPClient client, java.lang.String path)
          Remove all files from a FTP directory and its sub-directories
static void cleanHTTPDirs(com.oberon.ooql.sdk.common.WebServiceClient client, java.lang.String path)
          Remove all files from a HTTP directory and its sub-directories
static com.oberon.ooql.ftp.FTPClient connectFTP(java.lang.String host, int port, java.lang.String user, java.lang.String password)
          Connects to an FTP server and login with the user account
static com.oberon.ooql.sdk.common.WebServiceClient connectHTTP(java.lang.String url, java.lang.String user, java.lang.String password)
          Connects to an HTTP server and login with the user account
static void copyFile(java.io.File inputFile, java.lang.String toPath, java.lang.String toName, boolean move)
          Copy a local file to a given path If the given path doesn't exist, it will be created
static void createLocalDir(java.lang.String path)
          Create a new dir path in the local file-system
static void deleteFTPFile(java.lang.String host, int port, java.lang.String user, java.lang.String password, java.lang.String fileName)
          Delete a file inside the FTP server (login with the user account)
static void deleteHTTPFile(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String fileName)
          Delete a file inside the HTTP server (login with the user account)
static byte[] getBytesFromFile(java.lang.String fileName)
          Get binary data from a local file
static byte[] getBytesFromStream(java.io.DataInputStream is)
          Get binary data from an input stream
static byte[] getBytesFromStream(java.io.DataInputStream is, ProgressCounter counter)
          Get binary data from an input stream
static void getFTPFile(java.lang.String host, int port, java.lang.String user, java.lang.String password, java.lang.String path, java.lang.String fileName, java.lang.String toPath, java.lang.String toName, boolean move)
          Download a file from an FTP server (login with the user account) to a local file
static void getFTPFile(java.lang.String host, int port, java.lang.String user, java.lang.String password, java.lang.String path, java.lang.String fileName, java.lang.String toPath, java.lang.String toName, boolean move, com.oberon.ooql.ftp.FTPDataTransferListener listener)
          Download a file from an FTP server (login with the user account) to a local file
static void getHTTPFile(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String path, java.lang.String fileName, java.lang.String toPath, java.lang.String toName, boolean move)
          Download a file from an HTTP server (login with the user account) to a local file
static java.util.Vector<java.lang.String> listFiles(java.lang.String path)
          List files in a local file-system directory and its sub-directories
static java.util.Vector<java.lang.String> listFiles(java.lang.String path, boolean subdirs)
          List files in a local file-system directory
static java.util.Vector<java.lang.String> listFTPFiles(java.lang.String host, int port, java.lang.String user, java.lang.String password, java.lang.String path)
          List files in a FTP folder ( and its sub-folders )
static java.util.Vector<java.lang.String> listHTTPFiles(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String path)
          List files in a HTTP folder ( and its sub-folders )
static void moveFTPFile(java.lang.String host, int port, java.lang.String user, java.lang.String password, java.lang.String fromFile, java.lang.String toPath, java.lang.String toName)
          Move/rename a file inside the FTP server (login with the user account)
static void moveHTTPFile(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String fromFile, java.lang.String toPath, java.lang.String toName)
          Move/rename a file inside the HTTP server (login with the user account)
static void putFTPFile(java.lang.String host, int port, java.lang.String user, java.lang.String password, java.io.File sourceFile, java.lang.String toPath, java.lang.String toName, boolean move)
          Upload a local file to an FTP server (login with the user account)
static void putFTPFile(java.lang.String host, int port, java.lang.String user, java.lang.String password, java.io.File sourceFile, java.lang.String toPath, java.lang.String toName, boolean move, com.oberon.ooql.ftp.FTPDataTransferListener listener)
          Upload a local file to an FTP server (login with the user account)
static void putHTTPFile(java.lang.String url, java.lang.String user, java.lang.String password, java.io.File sourceFile, java.lang.String toPath, java.lang.String toName, boolean move)
          Upload a local file to an HTTP server (login with the user account)
static void removeLocalDir(java.lang.String path)
          Remove a directory and its sub-directories
static java.io.File saveToFile(java.lang.String path, java.lang.String fileName, byte[] data)
          Save binary data to a local file If the given path doesn't exist, it will be created
static void saveToStream(java.io.DataOutputStream os, byte[] data)
          Send binary data to an output stream
static void saveToStream(java.io.DataOutputStream os, byte[] data, ProgressCounter counter)
          Send binary data to an output stream
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

getBytesFromFile

public static byte[] getBytesFromFile(java.lang.String fileName)
                               throws java.io.IOException,
                                      OberonException
Get binary data from a local file

Parameters:
fileName - the full path of local file
Throws:
java.io.IOException
OberonException

getBytesFromStream

public static byte[] getBytesFromStream(java.io.DataInputStream is)
                                 throws java.io.IOException,
                                        OberonException
Get binary data from an input stream

Throws:
java.io.IOException
OberonException

getBytesFromStream

public static byte[] getBytesFromStream(java.io.DataInputStream is,
                                        ProgressCounter counter)
                                 throws java.io.IOException,
                                        OberonException
Get binary data from an input stream

Throws:
java.io.IOException
OberonException

createLocalDir

public static void createLocalDir(java.lang.String path)
                           throws OberonException
Create a new dir path in the local file-system

Parameters:
path - the full path (all intermediate dirs will be created)
Throws:
OberonException

saveToFile

public static java.io.File saveToFile(java.lang.String path,
                                      java.lang.String fileName,
                                      byte[] data)
                               throws java.io.IOException,
                                      OberonException
Save binary data to a local file If the given path doesn't exist, it will be created

Parameters:
path - the full path of directory where save the file
fileName - the file name
data - the binary data
Throws:
java.io.IOException
OberonException
See Also:
createLocalDir(String)

saveToStream

public static void saveToStream(java.io.DataOutputStream os,
                                byte[] data)
                         throws java.io.IOException,
                                OberonException
Send binary data to an output stream

Throws:
java.io.IOException
OberonException

saveToStream

public static void saveToStream(java.io.DataOutputStream os,
                                byte[] data,
                                ProgressCounter counter)
                         throws java.io.IOException,
                                OberonException
Send binary data to an output stream

Throws:
java.io.IOException
OberonException

copyFile

public static void copyFile(java.io.File inputFile,
                            java.lang.String toPath,
                            java.lang.String toName,
                            boolean move)
                     throws java.io.IOException,
                            OberonException
Copy a local file to a given path If the given path doesn't exist, it will be created

Parameters:
inputFile - the source file
toPath - the destination full-path
toName - the destination file name
move - if true, remove the source file
Throws:
java.io.IOException
OberonException

listFiles

public static java.util.Vector<java.lang.String> listFiles(java.lang.String path,
                                                           boolean subdirs)
List files in a local file-system directory

Parameters:
path - the directory full path
subdirs - if true recurse to sub directories
Returns:
Vector of file names

listFiles

public static java.util.Vector<java.lang.String> listFiles(java.lang.String path)
List files in a local file-system directory and its sub-directories

Parameters:
path - the directory full path
Returns:
Vector of - full path - file names

cleanDirs

public static void cleanDirs(java.lang.String path)
Remove all files from a local directory and its sub-directories


removeLocalDir

public static void removeLocalDir(java.lang.String path)
Remove a directory and its sub-directories


connectFTP

public static com.oberon.ooql.ftp.FTPClient connectFTP(java.lang.String host,
                                                       int port,
                                                       java.lang.String user,
                                                       java.lang.String password)
                                                throws OberonException
Connects to an FTP server and login with the user account

Parameters:
host - the host name or IP address
port - the FTP port
user - the user account
password - the user account password
Throws:
OberonException

getFTPFile

public static void getFTPFile(java.lang.String host,
                              int port,
                              java.lang.String user,
                              java.lang.String password,
                              java.lang.String path,
                              java.lang.String fileName,
                              java.lang.String toPath,
                              java.lang.String toName,
                              boolean move)
                       throws OberonException
Download a file from an FTP server (login with the user account) to a local file

Parameters:
host - the host name or IP address
port - the FTP port
user - the user account
password - the user account password
path - the FTP file full-path
fileName - the FTP file name
toPath - the local full-path
toName - the local file name
move - if true, remove the source FTP file
Throws:
OberonException

getFTPFile

public static void getFTPFile(java.lang.String host,
                              int port,
                              java.lang.String user,
                              java.lang.String password,
                              java.lang.String path,
                              java.lang.String fileName,
                              java.lang.String toPath,
                              java.lang.String toName,
                              boolean move,
                              com.oberon.ooql.ftp.FTPDataTransferListener listener)
                       throws OberonException
Download a file from an FTP server (login with the user account) to a local file

Parameters:
host - the host name or IP address
port - the FTP port
user - the user account
password - the user account password
path - the FTP file full-path
fileName - the FTP file name
toPath - the local full-path
toName - the local file name
move - if true, remove the source FTP file
listener - data transfer listener
Throws:
OberonException
Since:
5.0

putFTPFile

public static void putFTPFile(java.lang.String host,
                              int port,
                              java.lang.String user,
                              java.lang.String password,
                              java.io.File sourceFile,
                              java.lang.String toPath,
                              java.lang.String toName,
                              boolean move)
                       throws OberonException
Upload a local file to an FTP server (login with the user account)

Parameters:
host - the host name or IP address
port - the FTP port
user - the user account
password - the user account password
sourceFile - the local file
toPath - the destination FTP full-path
toName - the destination file name
move - if true, remove the source local file
Throws:
OberonException

putFTPFile

public static void putFTPFile(java.lang.String host,
                              int port,
                              java.lang.String user,
                              java.lang.String password,
                              java.io.File sourceFile,
                              java.lang.String toPath,
                              java.lang.String toName,
                              boolean move,
                              com.oberon.ooql.ftp.FTPDataTransferListener listener)
                       throws OberonException
Upload a local file to an FTP server (login with the user account)

Parameters:
host - the host name or IP address
port - the FTP port
user - the user account
password - the user account password
sourceFile - the local file
toPath - the destination FTP full-path
toName - the destination file name
move - if true, remove the source local file
listener - data transfer listener
Throws:
OberonException
Since:
5.0

moveFTPFile

public static void moveFTPFile(java.lang.String host,
                               int port,
                               java.lang.String user,
                               java.lang.String password,
                               java.lang.String fromFile,
                               java.lang.String toPath,
                               java.lang.String toName)
                        throws OberonException
Move/rename a file inside the FTP server (login with the user account)

Parameters:
host - the host name or IP address
port - the FTP port
user - the user account
password - the user account password
fromFile - the FTP full path file name
toPath - the destination FTP full-path
toName - the destination file name
Throws:
OberonException

deleteFTPFile

public static void deleteFTPFile(java.lang.String host,
                                 int port,
                                 java.lang.String user,
                                 java.lang.String password,
                                 java.lang.String fileName)
                          throws OberonException
Delete a file inside the FTP server (login with the user account)

Parameters:
host - the host name or IP address
port - the FTP port
user - the user account
password - the user account password
fileName - the FTP full path file name to delete
Throws:
OberonException

listFTPFiles

public static java.util.Vector<java.lang.String> listFTPFiles(java.lang.String host,
                                                              int port,
                                                              java.lang.String user,
                                                              java.lang.String password,
                                                              java.lang.String path)
                                                       throws OberonException
List files in a FTP folder ( and its sub-folders )

Parameters:
host - the host name or IP address
port - the FTP port
user - the user account
password - the user account password
path - the directory full path
Returns:
Vector of - full path - file names
Throws:
OberonException

cleanFTPDirs

public static void cleanFTPDirs(com.oberon.ooql.ftp.FTPClient client,
                                java.lang.String path)
                         throws java.lang.Exception
Remove all files from a FTP directory and its sub-directories

Throws:
java.lang.Exception

connectHTTP

public static com.oberon.ooql.sdk.common.WebServiceClient connectHTTP(java.lang.String url,
                                                                      java.lang.String user,
                                                                      java.lang.String password)
                                                               throws OberonException
Connects to an HTTP server and login with the user account

Parameters:
url - the url of the webservice for file manipulation
user - the user account
password - the user account password
Throws:
OberonException

getHTTPFile

public static void getHTTPFile(java.lang.String url,
                               java.lang.String user,
                               java.lang.String password,
                               java.lang.String path,
                               java.lang.String fileName,
                               java.lang.String toPath,
                               java.lang.String toName,
                               boolean move)
                        throws OberonException
Download a file from an HTTP server (login with the user account) to a local file

Parameters:
url - the url of the webservice for file manipulation
user - the user account
password - the user account password
path - the HTTP file full-path
fileName - the HTTP file name
toPath - the local full-path
toName - the local file name
move - if true, remove the source HTTP file
Throws:
OberonException

putHTTPFile

public static void putHTTPFile(java.lang.String url,
                               java.lang.String user,
                               java.lang.String password,
                               java.io.File sourceFile,
                               java.lang.String toPath,
                               java.lang.String toName,
                               boolean move)
                        throws OberonException
Upload a local file to an HTTP server (login with the user account)

Parameters:
url - the url of the webservice for file manipulation
user - the user account
password - the user account password
sourceFile - the local file
toPath - the destination HTTP full-path
toName - the destination file name
move - if true, remove the source local file
Throws:
OberonException

moveHTTPFile

public static void moveHTTPFile(java.lang.String url,
                                java.lang.String user,
                                java.lang.String password,
                                java.lang.String fromFile,
                                java.lang.String toPath,
                                java.lang.String toName)
                         throws OberonException
Move/rename a file inside the HTTP server (login with the user account)

Parameters:
url - the url of the webservice for file manipulation
user - the user account
password - the user account password
fromFile - the HTTP full path file name
toPath - the destination HTTP full-path
toName - the destination file name
Throws:
OberonException

deleteHTTPFile

public static void deleteHTTPFile(java.lang.String url,
                                  java.lang.String user,
                                  java.lang.String password,
                                  java.lang.String fileName)
                           throws OberonException
Delete a file inside the HTTP server (login with the user account)

Parameters:
url - the url of the webservice for file manipulation
user - the user account
password - the user account password
fileName - the HTTP full path file name to delete
Throws:
OberonException

listHTTPFiles

public static java.util.Vector<java.lang.String> listHTTPFiles(java.lang.String url,
                                                               java.lang.String user,
                                                               java.lang.String password,
                                                               java.lang.String path)
                                                        throws OberonException
List files in a HTTP folder ( and its sub-folders )

Parameters:
url - the url of the webservice for file manipulation
user - the user account
password - the user account password
path - the directory full path
Returns:
Vector of - full path - file names
Throws:
OberonException

cleanHTTPDirs

public static void cleanHTTPDirs(com.oberon.ooql.sdk.common.WebServiceClient client,
                                 java.lang.String path)
                          throws java.lang.Exception
Remove all files from a HTTP directory and its sub-directories

Throws:
java.lang.Exception

OBEROn SDK

Copyright © 2008-2014 Mirko Solazzi. All Rights Reserved.