jcs.util
Class FileUtil

java.lang.Object
  |
  +--jcs.util.FileUtil

public class FileUtil
extends java.lang.Object

A class with miscellaneous methods for a client environment:

  main:        a client-side command-line interpreter to invoke 
               the other methods
  putString:   copies a file to a Java String in the SQL server
  getString:   copies a string from the SQL server to a file
  putStream:   streams a file to a Java String or TEXT column 
               in the SQL server
  getStream:   streams a string or TEXT column from the SQL server 
               to a file
  file2String: copies a client file to a String variable
  string2File: copies a String variable to a client file
  
These are convenience methods that illustrate file I/O techniques.


Method Summary
static java.lang.String file2String(java.lang.String fileName)
          Copies a client operating system file to a Java String in a Client variable.
static void getStream(java.lang.String outFile, java.lang.String query, java.lang.String server)
          Streams a TEXT or String column in the SQL server to a client operating system file .
static void getString(java.lang.String outFile, java.lang.String query, java.lang.String server)
          Copies a Java String from the SQL server to a client operating system file.
static void main(java.lang.String[] args)
          Invokes the putString, getString, putStream, and getStream methods from a client command line.
static void putStream(java.lang.String inFile, java.lang.String insertStmt, java.lang.String server)
          Streams a client operating system file to a TEXT or String column in the SQL server.
static void putString(java.lang.String inFile, java.lang.String insertStmt, java.lang.String server)
          Copies a client operating system file to a Java String in the SQL server.
static void string2File(java.lang.String fileName, java.lang.String source)
          Copies a Java String in a Client variable to a client operating system file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(java.lang.String[] args)
Invokes the putString, getString, putStream, and getStream methods from a client command line.

Usage:

  java jcs.util.FileUtil -S server -A [putString | putStream]
                   -I input-file-name   -Q sql-insert-statement 
  java jcs.util.FileUtil -S server -A [getString | getStream] 
                   -O output-file-name  -Q sql-query 
  

Assume a file named "emps.xml", and the following table:

  create table stringtable 
     (id varchar(50), textcol text, stringcol java.lang.String)  
  

Example command lines:

 
  java jcs.util.FileUtil -A putString  -I emps.xml         \
     -S "antibes:4000?user=sa"                             \
     -Q "insert into stringtable (id, stringcol)           \ 
                values ('example-1', ?)"

  java jcs.util.FileUtil  -A getString -O emps.getString   \
     -S "antibes:4000?user=sa"                             \
     -Q "select stringcol                                  \
         from stringtable where id='example-1' "   

  java jcs.util.FileUtil  -A putStream -I emps.xml         \
     -S "antibes:4000?user=sa"                                \ 
     -Q "insert into stringtable (id, textcol)                \
                  values ('example-2', ?)"  

  java jcs.util.FileUtil   -A getStream -O emps.getStream        \
     -S "antibes:4000?user=sa"                                      \
     -Q "select textcol from stringtable where id='example-2' " 
  
Parameters:
args - the String[] containing command line arguments
See Also:
putString(java.lang.String, java.lang.String, java.lang.String), getString(java.lang.String, java.lang.String, java.lang.String), putStream(java.lang.String, java.lang.String, java.lang.String), getStream(java.lang.String, java.lang.String, java.lang.String)

putString

public static void putString(java.lang.String inFile,
                             java.lang.String insertStmt,
                             java.lang.String server)
                      throws java.lang.Exception
Copies a client operating system file to a Java String in the SQL server.

This method can be invoked directly, or from the main method command line.

Assume a text file named "emps.xml", and the following table:

     create table stringtable 
         (id varchar(50), textcol text, stringcol java.lang.String)  
  

Example Java code:

  String server = "antibes:4000?user=sa";
  String putStringVar = " insert into stringtable (id, stringcol) "
             +"     values ('some-id', ?)";
  jcs.util.FileUtil.putString("emps.xml", putStringVar, server);
  
Parameters:
inFile - a string that is the name of the file from which to copy
insertStmt - a string containing an SQL statement that has a single question-mark parameter. The datatype of that parameter must be String.
server - a string that identifies the server in which to execute the statement.
Throws:
java.lang.Exception - Thrown by java.sql methods
See Also:
ExecSql.connectTo(java.lang.String)

getString

public static void getString(java.lang.String outFile,
                             java.lang.String query,
                             java.lang.String server)
                      throws java.lang.Exception
Copies a Java String from the SQL server to a client operating system file.

This method can be invoked directly, or from the main method command line.

Assume the following table:

  create table stringtable 
     (id varchar(50), textcol text, stringcol java.lang.String)  
  

Example Java code:

  String server = "antibes:4000?user=sa";
  String getStringVar 
     = "select stringcol from stringtable  where id='some-id' ";
  jcs.util.FileUtil.getString2("emps.getString", getStringVar, server);
  
Parameters:
outFile - a string that is the name of the file to store into
query - a string that contains an SQL query that returns a result set with one row and one column. The datatype of that column must be String.
server - a string that identifies the server in which to execute the statement
Throws:
java.lang.Exception - Thrown by java.sql methods
See Also:
ExecSql.connectTo(java.lang.String)

putStream

public static void putStream(java.lang.String inFile,
                             java.lang.String insertStmt,
                             java.lang.String server)
                      throws java.lang.Exception
Streams a client operating system file to a TEXT or String column in the SQL server.

This method can be invoked directly, or from the main method command line.

Assume a file named "emps.xml", and the following table:

     create table stringtable 
         (id varchar(50), textcol text, stringcol java.lang.String)  
  

Example Java code:

 
  String server = "antibes:4000?user=sa";
  String putStreamVar 
       = "insert into stringtable(id, textcol) "
         +"values ('putStreamId', ?)";
  jcs.util.FileUtil.putStream("emps.xml", putStreamVar, server);
  
Parameters:
inFile - a string that is the name of the file from which to copy
insertStmt - a string that contains an SQL statement that has a single question-mark parameter. The datatype of that parameter must be either TEXT or java.lang.String.
server - identifies the server in which to execute the statement
Throws:
java.lang.Exception - Thrown by java.sql methods
See Also:
ExecSql.connectTo(java.lang.String)

getStream

public static void getStream(java.lang.String outFile,
                             java.lang.String query,
                             java.lang.String server)
                      throws java.lang.Exception
Streams a TEXT or String column in the SQL server to a client operating system file .

This method can be invoked directly, or from the main method command line.

Assume a file named "emps.xml", and the following table:

     create table stringtable 
         (id varchar(50), textcol text, stringcol java.lang.String)  
  

Example Java code:

   String getStreamVar 
       = "select textcol from stringtable where id='putStreamId'";
   jcs.util.FileUtil.getStream("emps.getStream", getStreamVar, server);       
  
Parameters:
outFile - a string that is the name of the file to store into
query - a string that contains an SQL query that returns a result set with one row and one column. The datatype of that column must be either TEXT or java.lang.String.
server - a string that identifies the server in which to execute the statement
Throws:
java.lang.Exception - Thrown by java.sql methods
See Also:
ExecSql.connectTo(java.lang.String)

file2String

public static java.lang.String file2String(java.lang.String fileName)
                                    throws java.lang.Exception
Copies a client operating system file to a Java String in a Client variable.

Example Java code:

  String stringFromFile=jcs.util.FileUtil.file2String("my-file.txt");
  
Parameters:
fileName - a string that is the name of the file from which to copy
Throws:
java.lang.Exception - Thrown by java.io methods
See Also:
ExecSql.connectTo(java.lang.String)

string2File

public static void string2File(java.lang.String fileName,
                               java.lang.String source)
                        throws java.lang.Exception
Copies a Java String in a Client variable to a client operating system file.

Example Java code:

  jcs.util.FileUtil.file2String("my-file.txt", string-variable);
  
Parameters:
fileName - a string that is the name of the file to copy into
source - the string to copy into the file
Throws:
java.lang.Exception - Thrown by java.io methods
See Also:
ExecSql.connectTo(java.lang.String)