org.netbeans.lib.cvsclient.file
Class DefaultFileHandler

java.lang.Object
  extended by org.netbeans.lib.cvsclient.file.DefaultFileHandler
All Implemented Interfaces:
FileHandler
Direct Known Subclasses:
GzippedFileHandler

public class DefaultFileHandler
extends java.lang.Object
implements FileHandler

Provides a basic implementation of FileHandler, and does much of the handling of reading and writing files and performing CRLF conversions.


Constructor Summary
DefaultFileHandler()
          Creates a DefaultFileHandler.
 
Method Summary
protected  boolean createNewFile(java.io.File file)
          Extension point allowing subclasses to change file creation logic.
protected  java.io.OutputStream createOutputStream(java.io.File file)
          Extension point allowing subclasses to change file write logic.
 Request[] getInitialisationRequests()
          Get any requests that must be sent before commands are sent, to init this file handler.
protected  java.lang.String getLengthString(long length)
          Get the string to transmit containing the file transmission length.
protected  java.io.InputStream getProcessedInputStream(java.io.File file)
           
protected  java.io.Reader getProcessedReader(java.io.File f)
           
 TransmitTextFilePreprocessor getTransmitTextFilePreprocessor()
          Returns the preprocessor for transmitting text files.
 WriteTextFilePreprocessor getWriteRcsDiffFilePreprocessor()
          Gets the preprocessor for merging text files after getting (and un-gzipping) the diff received from server.
 WriteTextFilePreprocessor getWriteTextFilePreprocessor()
          Gets the preprocessor for writing text files after getting (and un-gzipping) from server.
 void removeLocalFile(java.lang.String pathname)
          Remove the specified file from the local disk.
 void renameLocalFile(java.lang.String pathname, java.lang.String newName)
          Rename the local file.
 void setGlobalOptions(GlobalOptions globalOptions)
          Sets the global options.
 void setNextFileDate(java.util.Date modifiedDate)
          Set the modified date of the next file to be written.
 void setTransmitTextFilePreprocessor(TransmitTextFilePreprocessor transmitTextFilePreprocessor)
          Sets the preprocessor for transmitting text files.
 void setWriteRcsDiffFilePreprocessor(WriteTextFilePreprocessor writeRcsDiffFilePreprocessor)
          Sets the preprocessor for merging text files after getting (and un-gzipping) the diff received from server.
 void setWriteTextFilePreprocessor(WriteTextFilePreprocessor writeTextFilePreprocessor)
          Sets the preprocessor for writing text files after getting (and un-gzipping) from server.
 void transmitBinaryFile(java.io.File file, LoggedDataOutputStream dos)
          Transmit a binary file to the server, using the standard CVS protocol conventions.
 void transmitTextFile(java.io.File file, LoggedDataOutputStream dos)
          Transmit a text file to the server, using the standard CVS protocol conventions.
 void writeBinaryFile(java.lang.String path, java.lang.String mode, LoggedDataInputStream dis, int length)
          Write (either create or replace) a binary file on the local machine with one read from the server.
 void writeRcsDiffFile(java.lang.String path, java.lang.String mode, LoggedDataInputStream dis, int length)
          Merge a text file on the local machine with the diff from the server.
 void writeTextFile(java.lang.String path, java.lang.String mode, LoggedDataInputStream dis, int length)
          Write (either create or replace) a file on the local machine with one read from the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFileHandler

public DefaultFileHandler()
Creates a DefaultFileHandler.

Method Detail

getTransmitTextFilePreprocessor

public TransmitTextFilePreprocessor getTransmitTextFilePreprocessor()
Returns the preprocessor for transmitting text files.


setTransmitTextFilePreprocessor

public void setTransmitTextFilePreprocessor(TransmitTextFilePreprocessor transmitTextFilePreprocessor)
Sets the preprocessor for transmitting text files. The default one changes all line endings to Unix-lineendings (cvs default).


getWriteTextFilePreprocessor

public WriteTextFilePreprocessor getWriteTextFilePreprocessor()
Gets the preprocessor for writing text files after getting (and un-gzipping) from server.


setWriteTextFilePreprocessor

public void setWriteTextFilePreprocessor(WriteTextFilePreprocessor writeTextFilePreprocessor)
Sets the preprocessor for writing text files after getting (and un-gzipping) from server.


getWriteRcsDiffFilePreprocessor

public WriteTextFilePreprocessor getWriteRcsDiffFilePreprocessor()
Gets the preprocessor for merging text files after getting (and un-gzipping) the diff received from server.


setWriteRcsDiffFilePreprocessor

public void setWriteRcsDiffFilePreprocessor(WriteTextFilePreprocessor writeRcsDiffFilePreprocessor)
Sets the preprocessor for merging text files after getting (and un-gzipping) the diff received from server.


getLengthString

protected java.lang.String getLengthString(long length)
Get the string to transmit containing the file transmission length.

Parameters:
length - the amount of data that will be sent
Returns:
a String to transmit to the server (including carriage return)

getProcessedReader

protected java.io.Reader getProcessedReader(java.io.File f)
                                     throws java.io.IOException
Throws:
java.io.IOException

getProcessedInputStream

protected java.io.InputStream getProcessedInputStream(java.io.File file)
                                               throws java.io.IOException
Throws:
java.io.IOException

getInitialisationRequests

public Request[] getInitialisationRequests()
Get any requests that must be sent before commands are sent, to init this file handler.

Specified by:
getInitialisationRequests in interface FileHandler
Returns:
an array of Requests that must be sent

transmitTextFile

public void transmitTextFile(java.io.File file,
                             LoggedDataOutputStream dos)
                      throws java.io.IOException
Transmit a text file to the server, using the standard CVS protocol conventions. CR/LFs are converted to the Unix format.

Specified by:
transmitTextFile in interface FileHandler
Parameters:
file - the file to transmit
dos - the data outputstream on which to transmit the file
Throws:
java.io.IOException

transmitBinaryFile

public void transmitBinaryFile(java.io.File file,
                               LoggedDataOutputStream dos)
                        throws java.io.IOException
Transmit a binary file to the server, using the standard CVS protocol conventions.

Specified by:
transmitBinaryFile in interface FileHandler
Parameters:
file - the file to transmit
dos - the data outputstream on which to transmit the file
Throws:
java.io.IOException

writeTextFile

public void writeTextFile(java.lang.String path,
                          java.lang.String mode,
                          LoggedDataInputStream dis,
                          int length)
                   throws java.io.IOException
Write (either create or replace) a file on the local machine with one read from the server.

Specified by:
writeTextFile in interface FileHandler
Parameters:
path - the absolute path of the file, (including the file name).
mode - the mode of the file
dis - the stream to read the file from, as bytes
length - the number of bytes to read
Throws:
java.io.IOException

writeRcsDiffFile

public void writeRcsDiffFile(java.lang.String path,
                             java.lang.String mode,
                             LoggedDataInputStream dis,
                             int length)
                      throws java.io.IOException
Merge a text file on the local machine with the diff from the server. (it uses the RcsDiff response format - see cvsclient.ps for details)

Specified by:
writeRcsDiffFile in interface FileHandler
Parameters:
path - the absolute path of the file, (including the file name).
mode - the mode of the file
dis - the stream to read the file from, as bytes
length - the number of bytes to read
Throws:
java.io.IOException

writeBinaryFile

public void writeBinaryFile(java.lang.String path,
                            java.lang.String mode,
                            LoggedDataInputStream dis,
                            int length)
                     throws java.io.IOException
Write (either create or replace) a binary file on the local machine with one read from the server.

Specified by:
writeBinaryFile in interface FileHandler
Parameters:
path - the absolute path of the file, (including the file name).
mode - the mode of the file
dis - the stream to read the file from, as bytes
length - the number of bytes to read
Throws:
java.io.IOException

createNewFile

protected boolean createNewFile(java.io.File file)
                         throws java.io.IOException
Extension point allowing subclasses to change file creation logic.

Throws:
java.io.IOException

createOutputStream

protected java.io.OutputStream createOutputStream(java.io.File file)
                                           throws java.io.IOException
Extension point allowing subclasses to change file write logic. The stream is close()d after usage.

Throws:
java.io.IOException

removeLocalFile

public void removeLocalFile(java.lang.String pathname)
                     throws java.io.IOException
Remove the specified file from the local disk.

Specified by:
removeLocalFile in interface FileHandler
Parameters:
pathname - the full path to the file to remove
Throws:
java.io.IOException - if an IO error occurs while removing the file

renameLocalFile

public void renameLocalFile(java.lang.String pathname,
                            java.lang.String newName)
                     throws java.io.IOException
Rename the local file. If the destination file exists, the operation does nothing.

Specified by:
renameLocalFile in interface FileHandler
Parameters:
pathname - the full path to the file to rename
newName - the new name of the file (not the full path)
Throws:
java.io.IOException - if an IO error occurs while renaming the file

setNextFileDate

public void setNextFileDate(java.util.Date modifiedDate)
Set the modified date of the next file to be written. The next call to writeFile will use this date.

Specified by:
setNextFileDate in interface FileHandler
Parameters:
modifiedDate - the date the file should be marked as modified

setGlobalOptions

public void setGlobalOptions(GlobalOptions globalOptions)
Sets the global options. This can be useful to detect, whether local files should be made read-only.

Specified by:
setGlobalOptions in interface FileHandler

 

Built on August 7 2008.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.