j2ee.io
Class FileWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.OutputStreamWriter
          extended by java.io.FileWriter
              extended by j2ee.io.FileWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable

public class FileWriter
extends java.io.FileWriter

Extention of the java.io.FileWriter that enables users of the J2EEPS to write their files to their user area at the DFS filesystem at CERN.

By instantiating a FileWriter with a j2ee.io.File, writing to the file and eventually calling the flush method of this class, the file will be saved back to DFS if there is valid location information available as described for the j2ee.io.File class

It is worth noting that this class will overwrite already existing files at DFS if the normal constructor is used, so be careful if you don't want to delete your data unintentially


Field Summary
private  java.io.File file
           
private  org.apache.commons.httpclient.HttpsURL hrl
           
private  java.lang.String location
           
private  java.lang.String password
           
private  java.lang.String username
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
FileWriter(File file)
          Standard constructor that creates the FileWriter from the input file
FileWriter(File file, boolean append)
          Constructs a FileWriter object given a File object.
FileWriter(java.lang.String fileName)
          Constructs a FileWriter object given a file name.
FileWriter(java.lang.String fileName, boolean append)
          Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.
 
Method Summary
 void flush()
          This method flushes the data written to the file first locally, and then, if DFS location information is available and valid, it saves the data to DFS
private  boolean getLocationInfo()
          Checks if it can find a dfs.properties file in the user's directory.
private  java.lang.String parseLocation(java.lang.String s)
          Helper method that ensures that the input does not start or end with a "/".
private  void save()
          Method that actually saves the file to the location at DFS.
 boolean setDFSConnection(java.lang.String location)
          This method sets the DFS connection according to the specified input.
 
Methods inherited from class java.io.OutputStreamWriter
close, getEncoding, write, write, write
 
Methods inherited from class java.io.Writer
append, append, append, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

location

private java.lang.String location

username

private java.lang.String username

password

private java.lang.String password

file

private java.io.File file

hrl

private org.apache.commons.httpclient.HttpsURL hrl
Constructor Detail

FileWriter

public FileWriter(File file)
           throws java.io.IOException

Standard constructor that creates the FileWriter from the input file

Parameters:
file - - The file to be written to
Throws:
java.io.IOException

FileWriter

public FileWriter(File file,
                  boolean append)
           throws java.io.IOException

Constructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.

Parameters:
file - - The file to be written to
append - - if true, the bytes will be written to the end of the file rather than the beginning
Throws:
java.io.IOException

FileWriter

public FileWriter(java.lang.String fileName)
           throws java.io.IOException

Constructs a FileWriter object given a file name.

param fileName - The filename to write to

Throws:
java.io.IOException

FileWriter

public FileWriter(java.lang.String fileName,
                  boolean append)
           throws java.io.IOException

Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.

Parameters:
fileName - - The filename to write to
append - - f true, then data will be written to the end of the file rather than the beginning.
Throws:
java.io.IOException
Method Detail

save

private void save()

Method that actually saves the file to the location at DFS. It is used by the flush method


flush

public void flush()
           throws java.io.IOException

This method flushes the data written to the file first locally, and then, if DFS location information is available and valid, it saves the data to DFS

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStreamWriter
Throws:
java.io.IOException

setDFSConnection

public boolean setDFSConnection(java.lang.String location)

This method sets the DFS connection according to the specified input. It does not check if this is a valid location, that has to be done after by trying to create the WebdavResource connection

Parameters:
location - - the DFS location
Returns:
true if the connection is okay, false otherwise

parseLocation

private java.lang.String parseLocation(java.lang.String s)

Helper method that ensures that the input does not start or end with a "/". Is used to ensure conformity when treating location strings in the class

Parameters:
s - - The string to be checked for starting or ending "/"'s
Returns:
- The parsed string

getLocationInfo

private boolean getLocationInfo()

Checks if it can find a dfs.properties file in the user's directory.

Returns:
true if a connection is possible to DFS, false otherwise