j2ee.io
Class FileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FileOutputStream
          extended by j2ee.io.FileOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class FileOutputStream
extends java.io.FileOutputStream

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

By instantiating a FileOutputStream 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  boolean overWrite
           
private  java.lang.String password
           
private  java.lang.String username
           
 
Constructor Summary
FileOutputStream(File file)
          Standard constructor that creates the FileOutputStream from the input file
FileOutputStream(File file, boolean append)
          Constructs a FileOutputStream object given a File object.
FileOutputStream(java.lang.String name)
          Constructs a FileOtputStream object given a file name.
FileOutputStream(java.lang.String name, 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.FileOutputStream
close, finalize, getChannel, getFD, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

private java.io.File file

overWrite

private boolean overWrite

location

private java.lang.String location

username

private java.lang.String username

password

private java.lang.String password

hrl

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

FileOutputStream

public FileOutputStream(File file)
                 throws java.io.FileNotFoundException

Standard constructor that creates the FileOutputStream from the input file

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

FileOutputStream

public FileOutputStream(File file,
                        boolean append)
                 throws java.io.FileNotFoundException

Constructs a FileOutputStream 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.FileNotFoundException

FileOutputStream

public FileOutputStream(java.lang.String name)
                 throws java.io.FileNotFoundException

Constructs a FileOtputStream object given a file name.

Parameters:
name - - The filename to write to
Throws:
java.io.FileNotFoundException

FileOutputStream

public FileOutputStream(java.lang.String name,
                        boolean append)
                 throws java.io.FileNotFoundException

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

Parameters:
name - - 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.FileNotFoundException
Method Detail

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.OutputStream
Throws:
java.io.IOException

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

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

save

private void save()

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