org.das2.util.filesystem
Class FileObject

java.lang.Object
  extended by org.das2.util.filesystem.FileObject
Direct Known Subclasses:
LocalFileObject, WebFileObject

public abstract class FileObject
extends java.lang.Object

Class for describing and accessing files in file systems. This is similar to java.io.File, except that it can describe files on remote file systems like an ftp site.

Note: this is modelled after the NetBeans fileSystem FileObject, with the thought that we might use it later.


Constructor Summary
FileObject()
           
 
Method Summary
abstract  boolean canRead()
          returns true if the file can be read by the client.
abstract  boolean exists()
          returns true if the file exists.
 java.nio.channels.ReadableByteChannel getChannel()
          opens a Channel, but without a monitor.
abstract  java.nio.channels.ReadableByteChannel getChannel(ProgressMonitor monitor)
          opens a Channel, perhaps transferring the file to a local cache first.
abstract  FileObject[] getChildren()
          returns objects within a folder.
 java.io.File getFile()
          gets a File object that can be opened by the client.
abstract  java.io.File getFile(ProgressMonitor monitor)
          gets a File object that can be opened by the client.
 java.io.InputStream getInputStream()
          opens an inputStream, perhaps transferring the file to a cache first.
abstract  java.io.InputStream getInputStream(ProgressMonitor monitor)
          opens an inputStream, perhaps transferring the file to a cache first.
abstract  java.lang.String getNameExt()
          returns the canonical name of the file within the filesystem.
abstract  FileObject getParent()
          returns the parent FileObject (a folder).
abstract  long getSize()
          returns the size of the file.
abstract  boolean isData()
          returns true if the file is a data file that to be used reading or writing data.
abstract  boolean isFolder()
          indicates the type of FileObject
abstract  boolean isLocal()
          returns true if the file is locally available, meaning clients can call getFile() and the readble File reference will be available in interactive time.
abstract  boolean isReadOnly()
          true is the file is read-only.
abstract  boolean isRoot()
          returns true if this is the root of the filesystem it came from.
abstract  java.util.Date lastModified()
          returns the Date when the file was last modified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileObject

public FileObject()
Method Detail

canRead

public abstract boolean canRead()
returns true if the file can be read by the client.

Returns:
true if the file can be read (see getInputStream)

getChildren

public abstract FileObject[] getChildren()
                                  throws java.io.IOException
returns objects within a folder.

Returns:
an array of all FileObjects with the folder.
Throws:
java.io.IOException

getInputStream

public abstract java.io.InputStream getInputStream(ProgressMonitor monitor)
                                            throws java.io.FileNotFoundException,
                                                   java.io.IOException
opens an inputStream, perhaps transferring the file to a cache first.

Parameters:
monitor - for monitoring the download. The monitor won't be used when the access is immediate, for example with local FileObjects.
Returns:
an InputStream
Throws:
java.io.FileNotFoundException - if the file doesn't exist.
java.io.IOException

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.FileNotFoundException,
                                          java.io.IOException
opens an inputStream, perhaps transferring the file to a cache first. Note no monitor is used but this may block at sub-interactive time until the file is downloaded.

Returns:
an InputStream
Throws:
java.io.FileNotFoundException - if the file doesn't exist.
java.io.IOException

getChannel

public abstract java.nio.channels.ReadableByteChannel getChannel(ProgressMonitor monitor)
                                                          throws java.io.FileNotFoundException,
                                                                 java.io.IOException
opens a Channel, perhaps transferring the file to a local cache first. monitor is used to monitor the download.

Parameters:
monitor - for monitoring the download. The monitor won't be used when the access is immediate, for example with local FileObjects.
Returns:
a java.nio.channels.Channel for fast IO reads.
Throws:
java.io.FileNotFoundException - if the file doesn't exist.
java.io.IOException

getChannel

public java.nio.channels.ReadableByteChannel getChannel()
                                                 throws java.io.FileNotFoundException,
                                                        java.io.IOException
opens a Channel, but without a monitor. Note this may block at sub-interactive time if the FileObject needs to be downloaded before access.

Returns:
a java.nio.channels.Channel for fast IO reads.
Throws:
java.io.FileNotFoundException - if the file doesn't exist.
java.io.IOException

getFile

public abstract java.io.File getFile(ProgressMonitor monitor)
                              throws java.io.FileNotFoundException,
                                     java.io.IOException
gets a File object that can be opened by the client. This may download a remote file, so a progress monitor can be used to monitor the download.

Parameters:
monitor - for monitoring the download. The monitor won't be used when the access is immediate, for example with local FileObjects.
Returns:
a reference to a File that can be opened.
Throws:
java.io.FileNotFoundException - if the file doesn't exist.
java.io.IOException - if the file cannot be made local
java.lang.NullPointerException - if the monitor is null.

getFile

public java.io.File getFile()
                     throws java.io.FileNotFoundException,
                            java.io.IOException
gets a File object that can be opened by the client. Note this may block at sub-interactive time if the remote file needs to be downloaded before access.

Returns:
a reference to a File that can be opened.
Throws:
java.io.FileNotFoundException - if the file doesn't exist.
java.io.IOException

getParent

public abstract FileObject getParent()
returns the parent FileObject (a folder).

Returns:
the parent folder of this object.

getSize

public abstract long getSize()
returns the size of the file.

Returns:
the size in bytes of the file, and -1 if the size is unknown.

isData

public abstract boolean isData()
returns true if the file is a data file that to be used reading or writing data. (And not a folder.)

Returns:
true if the file is a data file

isFolder

public abstract boolean isFolder()
indicates the type of FileObject

Returns:
true if the object is a folder (directory).

isReadOnly

public abstract boolean isReadOnly()
true is the file is read-only.

Returns:
true if the file is read-only

isRoot

public abstract boolean isRoot()
returns true if this is the root of the filesystem it came from.

Returns:
true if this is the root of the filesystem it came from.

isLocal

public abstract boolean isLocal()
returns true if the file is locally available, meaning clients can call getFile() and the readble File reference will be available in interactive time. Note that isLocal does not imply exists(). Also, This may result in side effects such as a website hit.


exists

public abstract boolean exists()
returns true if the file exists. This may have the side effect of downloading the file.

Returns:
true if the file exists

getNameExt

public abstract java.lang.String getNameExt()
returns the canonical name of the file within the filesystem. For example, in the local filesystem /mnt/data/steven/, /mnt/data/steven/jan/01.dat would be /jan/01.dat. For example, /a/b/c.dat.

Returns:
the name of the file within the FileSystem.

lastModified

public abstract java.util.Date lastModified()
returns the Date when the file was last modified. or new Date(0L) if the date is not available.

Returns:
the last modified Date, or new Date(0) if it is not available.