public class FileSource extends java.lang.Object implements ModifiableTraversableSource, MoveableSource
ModifiableTraversableSource for filesystem objects.| Modifier and Type | Class and Description |
|---|---|
private static class |
FileSource.FileSourceOutputStream
A file outputStream that will rename the temp file to the destination file upon close()
and discard the temp file upon cancel().
|
| Modifier and Type | Field and Description |
|---|---|
private java.io.File |
m_file
The file
|
private java.lang.String |
m_scheme
The scheme
|
private java.lang.String |
m_uri
The URI of this source
|
| Constructor and Description |
|---|
FileSource(java.lang.String uri)
Builds a FileSource given an URI, which doesn't necessarily have to start with "file:"
|
FileSource(java.lang.String scheme,
java.io.File file)
Builds a FileSource, given an URI scheme and a File.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canCancel(java.io.OutputStream stream)
Can the data sent to an
OutputStream returned by
getOutputStream() be cancelled ? |
void |
cancel(java.io.OutputStream stream)
Cancel the data sent to an
OutputStream returned by
getOutputStream(). |
void |
copyTo(Source destination)
Copy the current source to a specified destination.
|
void |
delete()
Delete the source.
|
boolean |
exists()
Does this source actually exist ?
|
Source |
getChild(java.lang.String name)
Get a child of this source, given its name.
|
java.util.Collection |
getChildren()
Get the children of this source if this source is traversable.
|
long |
getContentLength()
Get the content length of this source's content or -1 if the length is
unknown.
|
java.io.File |
getFile()
Get the associated file
|
java.io.InputStream |
getInputStream()
Return an
InputStream to read from the source. |
long |
getLastModified()
Get the last modification date of this source.
|
java.lang.String |
getMimeType()
Get the mime-type of the content described by this object.
|
java.lang.String |
getName()
Return the name of this source relative to its parent.
|
java.io.OutputStream |
getOutputStream()
Get an
InputStream where raw bytes can be written to. |
Source |
getParent()
Get the parent of this source as a
Source object. |
java.lang.String |
getScheme()
Return the URI scheme identifier, i.e.
|
java.lang.String |
getURI()
Get the absolute URI for this source.
|
SourceValidity |
getValidity()
Return a validity object based on the file's modification date.
|
private void |
init(java.lang.String scheme,
java.io.File file) |
boolean |
isCollection()
Is this source a collection, i.e.
|
void |
makeCollection()
If it doesn't already exist, ensure this source is traversable
(equivalent to
File.mkdirs()) |
void |
moveTo(Source destination)
Move the current source to a specified destination.
|
void |
refresh()
Refresh the content of this object after the underlying data content has changed.
|
private java.io.File m_file
private java.lang.String m_scheme
private java.lang.String m_uri
public FileSource(java.lang.String uri)
throws SourceException,
java.net.MalformedURLException
uri - SourceExceptionjava.net.MalformedURLExceptionpublic FileSource(java.lang.String scheme,
java.io.File file)
throws SourceException
scheme - file - SourceExceptionprivate void init(java.lang.String scheme,
java.io.File file)
throws SourceException
SourceExceptionpublic java.io.File getFile()
public long getContentLength()
SourcegetContentLength in interface SourceSource.getContentLength()public java.io.InputStream getInputStream()
throws java.io.IOException,
SourceNotFoundException
SourceInputStream to read from the source.
This is the data at the point of invocation of this method,
so if this is Modifiable, you might get different content
from two different invocations.
The returned stream must be closed by the calling code.getInputStream in interface SourceInputStream to read data from (never null).java.io.IOException - if some I/O problem occurs.SourceNotFoundException - if the source doesn't exist.Source.getInputStream()public long getLastModified()
Source0 if it's unknown.getLastModified in interface Source0.Source.getLastModified()public java.lang.String getMimeType()
Sourcenull.getMimeType in interface Sourcenull.Source.getMimeType()public java.lang.String getScheme()
Source
This scheme can be used to get the SourceFactory responsible for this object.
public java.lang.String getURI()
Sourcepublic SourceValidity getValidity()
getValidity in interface Sourcenull.Source.getValidity()public void refresh()
SourceSome implementations may cache some values to speedup sucessive calls. Refreshing ensures you get the latest information.
refresh in interface SourceSource.refresh()public boolean exists()
public Source getChild(java.lang.String name) throws SourceException
TraversableSourceSource.exists().getChild in interface TraversableSourcename - the child name.SourceException - if this source is not traversable or if some other
error occurs.TraversableSource.getChild(java.lang.String)public java.util.Collection getChildren()
throws SourceException
TraversableSource
Note: only those sources actually fetched from the
collection need to be released using the SourceResolver.
getChildren in interface TraversableSourceSources (actually most probably TraversableSources).SourceException - this source is not traversable, or if some problem occurs.TraversableSource.getChildren()public java.lang.String getName()
TraversableSourcegetName in interface TraversableSourceTraversableSource.getName()public Source getParent() throws SourceException
TraversableSourceSource object.getParent in interface TraversableSourcenull if this source has no parent.SourceException - if some problem occurs.TraversableSource.getParent()public boolean isCollection()
TraversableSourceisCollection in interface TraversableSourceTraversableSource.isCollection()public java.io.OutputStream getOutputStream()
throws java.io.IOException
InputStream where raw bytes can be written to.
The signification of these bytes is implementation-dependent and
is not restricted to a serialized XML document.
The output stream returned actually writes to a temp file that replaces
the real one on close. This temp file is used as lock to forbid multiple
simultaneous writes. The real file is updated atomically when the output
stream is closed.
The returned stream must be closed or cancelled by the calling code.getOutputStream in interface ModifiableSourcejava.util.ConcurrentModificationException - if another thread is currently
writing to this file.java.io.IOExceptionpublic boolean canCancel(java.io.OutputStream stream)
OutputStream returned by
getOutputStream() be cancelled ?canCancel in interface ModifiableSourcepublic void cancel(java.io.OutputStream stream)
throws SourceException
OutputStream returned by
getOutputStream().
After cancel, the stream should no more be used.
cancel in interface ModifiableSourceSourceExceptionpublic void delete()
throws SourceException
delete in interface ModifiableSourceSourceExceptionpublic void makeCollection()
throws SourceException
ModifiableTraversableSourceFile.mkdirs())
If the source already exists, this method does nothing if it's already traversable, and fails otherwise.
makeCollection in interface ModifiableTraversableSourceSourceExceptionModifiableTraversableSource.makeCollection()public void copyTo(Source destination) throws SourceException
MoveableSourcecopyTo in interface MoveableSourcedestination - Destination of the source.SourceException - If an exception occurs during
the copy.MoveableSource.copyTo(org.apache.excalibur.source.Source)public void moveTo(Source destination) throws SourceException
MoveableSourcemoveTo in interface MoveableSourcedestination - Destination of the source.SourceException - If an exception occurs during
the move.MoveableSource.moveTo(org.apache.excalibur.source.Source)