goldengate.common.file.passthrough
Class PassthroughBasedFileImpl

java.lang.Object
  extended by goldengate.common.file.passthrough.PassthroughBasedFileImpl
All Implemented Interfaces:
FileInterface

public abstract class PassthroughBasedFileImpl
extends Object
implements FileInterface

File implementation for Passthrough Based. It is just an empty shell since in pass through mode, no directories or files really exist. If one wants to implement special actions, he/she just has to extend this class and override the default empty implementation.

Author:
Frederic Bregier

Field Summary
protected  String currentFile
          Current file if any
static PassthroughFileFactory factory
          Factory for PassthroughFile
protected  boolean isAppend
          Is this file in append mode
protected  boolean isReady
          Is this Document ready to be accessed
protected  PassthroughFile pfile
          Passthrough object
protected  SessionInterface session
          SessionInterface
 
Constructor Summary
PassthroughBasedFileImpl(SessionInterface session, PassthroughBasedDirImpl dir, String path, boolean append)
           
 
Method Summary
 boolean abortFile()
          Try to abort the current transfer if any
 boolean canRead()
           
 boolean canWrite()
           
 void checkIdentify()
          Check if the authentication is correct
 void clear()
          Set empty this FtpFile, mark it unReady.
 boolean closeFile()
          Close the current FileInterface
 boolean delete()
          Delete the current FileInterface.
 boolean exists()
           
 void flush()
          Try to flush written data if possible
protected  boolean get(FileChannel fileChannelOut)
          Write the FileInterface to the fileChannelOut, thus bypassing the limitation of the file size to 2^32 bytes.
 DirInterface getDir()
           
 String getFile()
           
protected  File getFileFromPath(String path)
          Get the File from this path, checking first its validity
 DataBlock getMarker()
          Create a restart from context for the current FileInterface
 long getPosition()
          Return the current position in the FileInterface.
protected  String getRelativePath(File file)
          Get the relative path (without mount point)
 SessionInterface getSession()
           
 boolean isDirectory()
          Is the current FileInterface a directory and exists
 boolean isFile()
          Is the current FileInterface a file and exists
 boolean isInReading()
           
 boolean isInWriting()
           
 long length()
           
 DataBlock readDataBlock()
          Read a new block for FileInterface
 boolean renameTo(String path)
          Rename the current FileInterface into a new filename from argument
 boolean restartMarker(Restart restart)
          Restart from a Marker for the current FileInterface if any.
 boolean retrieve()
          Ask to retrieve the current FileInterface.
 void setPosition(long position)
          Change the position in the file.
 boolean store()
          Ask to store the current FileInterface.
 void writeDataBlock(DataBlock dataBlock)
          Function called by the DataNetworkHandler when it receives one DataBlock (Store like command)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

protected final SessionInterface session
SessionInterface


currentFile

protected String currentFile
Current file if any


isReady

protected boolean isReady
Is this Document ready to be accessed


isAppend

protected boolean isAppend
Is this file in append mode


pfile

protected PassthroughFile pfile
Passthrough object


factory

public static PassthroughFileFactory factory
Factory for PassthroughFile

Constructor Detail

PassthroughBasedFileImpl

public PassthroughBasedFileImpl(SessionInterface session,
                                PassthroughBasedDirImpl dir,
                                String path,
                                boolean append)
                         throws CommandAbstractException
Parameters:
session -
dir - It is not necessary the directory that owns this file.
path -
append -
Throws:
CommandAbstractException
PassthroughException
Method Detail

clear

public void clear()
           throws CommandAbstractException
Description copied from interface: FileInterface
Set empty this FtpFile, mark it unReady.

Specified by:
clear in interface FileInterface
Throws:
CommandAbstractException

checkIdentify

public void checkIdentify()
                   throws Reply530Exception
Description copied from interface: FileInterface
Check if the authentication is correct

Specified by:
checkIdentify in interface FileInterface
Throws:
Reply530Exception

getSession

public SessionInterface getSession()
Specified by:
getSession in interface FileInterface
Returns:
the FtpSession

getDir

public DirInterface getDir()
Specified by:
getDir in interface FileInterface
Returns:
the FtpDir associated at creation with this file

getFileFromPath

protected File getFileFromPath(String path)
                        throws CommandAbstractException
Get the File from this path, checking first its validity

Parameters:
path -
Returns:
the FileInterface
Throws:
CommandAbstractException

getRelativePath

protected String getRelativePath(File file)
Get the relative path (without mount point)

Parameters:
file -
Returns:
the relative path

isDirectory

public boolean isDirectory()
                    throws CommandAbstractException
Description copied from interface: FileInterface
Is the current FileInterface a directory and exists

Specified by:
isDirectory in interface FileInterface
Returns:
True if it is a directory and it exists
Throws:
CommandAbstractException

isFile

public boolean isFile()
               throws CommandAbstractException
Description copied from interface: FileInterface
Is the current FileInterface a file and exists

Specified by:
isFile in interface FileInterface
Returns:
True if it is a file and it exists
Throws:
CommandAbstractException

getFile

public String getFile()
               throws CommandAbstractException
Specified by:
getFile in interface FileInterface
Returns:
the path of the current FileInterface (without mount point if any)
Throws:
CommandAbstractException

closeFile

public boolean closeFile()
                  throws CommandAbstractException
Description copied from interface: FileInterface
Close the current FileInterface

Specified by:
closeFile in interface FileInterface
Returns:
True if correctly closed
Throws:
CommandAbstractException

abortFile

public boolean abortFile()
                  throws CommandAbstractException
Description copied from interface: FileInterface
Try to abort the current transfer if any

Specified by:
abortFile in interface FileInterface
Returns:
True if everything is ok
Throws:
CommandAbstractException

length

public long length()
            throws CommandAbstractException
Specified by:
length in interface FileInterface
Returns:
the length of the current FileInterface
Throws:
CommandAbstractException

isInReading

public boolean isInReading()
                    throws CommandAbstractException
Specified by:
isInReading in interface FileInterface
Returns:
True if the current FileInterface is in Reading process
Throws:
CommandAbstractException

isInWriting

public boolean isInWriting()
                    throws CommandAbstractException
Specified by:
isInWriting in interface FileInterface
Returns:
True if the current FileInterface is in Writing process
Throws:
CommandAbstractException

canRead

public boolean canRead()
                throws CommandAbstractException
Specified by:
canRead in interface FileInterface
Returns:
True if the current FileInterface is ready for reading
Throws:
CommandAbstractException

canWrite

public boolean canWrite()
                 throws CommandAbstractException
Specified by:
canWrite in interface FileInterface
Returns:
True if the current FileInterface is ready for writing
Throws:
CommandAbstractException

exists

public boolean exists()
               throws CommandAbstractException
Specified by:
exists in interface FileInterface
Returns:
True if the current FileInterface exists
Throws:
CommandAbstractException

delete

public boolean delete()
               throws CommandAbstractException
Description copied from interface: FileInterface
Delete the current FileInterface.

Specified by:
delete in interface FileInterface
Returns:
True if OK, else False if not (or if the file never exists).
Throws:
CommandAbstractException

renameTo

public boolean renameTo(String path)
                 throws CommandAbstractException
Description copied from interface: FileInterface
Rename the current FileInterface into a new filename from argument

Specified by:
renameTo in interface FileInterface
Parameters:
path - the new filename (path could be relative or absolute - without mount point)
Returns:
True if the operation is done successfully
Throws:
CommandAbstractException

getMarker

public DataBlock getMarker()
                    throws CommandAbstractException
Description copied from interface: FileInterface
Create a restart from context for the current FileInterface

Specified by:
getMarker in interface FileInterface
Returns:
the dataBlock to send to the client
Throws:
CommandAbstractException

restartMarker

public boolean restartMarker(Restart restart)
                      throws CommandAbstractException
Description copied from interface: FileInterface
Restart from a Marker for the current FileInterface if any. This function is to be called at the beginning of every transfer so in store and retrieve method.

Specified by:
restartMarker in interface FileInterface
Returns:
True if the Marker is OK
Throws:
CommandAbstractException

retrieve

public boolean retrieve()
                 throws CommandAbstractException
Description copied from interface: FileInterface
Ask to retrieve the current FileInterface. This command returns quickly since it does not retrieve really. It prepares the object.

Specified by:
retrieve in interface FileInterface
Returns:
True if everything is ready
Throws:
CommandAbstractException

store

public boolean store()
              throws CommandAbstractException
Description copied from interface: FileInterface
Ask to store the current FileInterface. This command returns quickly since it does not store really. It prepares the object.

Specified by:
store in interface FileInterface
Returns:
True if everything is ready
Throws:
CommandAbstractException

readDataBlock

public DataBlock readDataBlock()
                        throws FileTransferException,
                               FileEndOfTransferException
Description copied from interface: FileInterface
Read a new block for FileInterface

Specified by:
readDataBlock in interface FileInterface
Returns:
dataBlock
Throws:
FileTransferException
FileEndOfTransferException

writeDataBlock

public void writeDataBlock(DataBlock dataBlock)
                    throws FileTransferException
Description copied from interface: FileInterface
Function called by the DataNetworkHandler when it receives one DataBlock (Store like command)

Specified by:
writeDataBlock in interface FileInterface
Throws:
FileTransferException

getPosition

public long getPosition()
Return the current position in the FileInterface. In write mode, it is the current file length.

Returns:
the position

setPosition

public void setPosition(long position)
                 throws IOException
Change the position in the file.

Parameters:
position - the position to set
Throws:
IOException

flush

public void flush()
Try to flush written data if possible


get

protected boolean get(FileChannel fileChannelOut)
Write the FileInterface to the fileChannelOut, thus bypassing the limitation of the file size to 2^32 bytes. This call closes the fileChannelOut with fileChannelOut.close() if the operation is in success.

Parameters:
fileChannelOut -
Returns:
True if OK, False in error.


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.