Package org.ametys.core.util.path
Class PathSource
- java.lang.Object
-
- org.ametys.core.util.path.PathSource
-
- All Implemented Interfaces:
ModifiableSource,ModifiableTraversableSource,MoveableSource,Source,TraversableSource
- Direct Known Subclasses:
SkinSource
public class PathSource extends Object implements ModifiableTraversableSource, MoveableSource
AModifiableTraversableSourcefor path objects.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPathSource()Empty constructorPathSource(String uri)Builds a PathSource given an URI, which doesn't necessarily have to start with "file:"PathSource(String scheme, String uri, Path path)Builds a PathSource, given an URI scheme, URI and a Path.PathSource(String scheme, Path path)Builds a PathSource, given an URI scheme and a Path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanCancel(OutputStream stream)Can the data sent to anOutputStreamreturned bygetOutputStream()be cancelled ?voidcancel(OutputStream stream)Cancel the data sent to anOutputStreamreturned bygetOutputStream().voidcopyTo(Source destination)voiddelete()Delete the source.booleanexists()SourcegetChild(String name)CollectiongetChildren()longgetContentLength()PathgetFile()Get the associated fileInputStreamgetInputStream()longgetLastModified()StringgetMimeType()StringgetName()OutputStreamgetOutputStream()Get anInputStreamwhere raw bytes can be written to.SourcegetParent()StringgetScheme()StringgetURI()SourceValiditygetValidity()booleanisCollection()voidmakeCollection()voidmoveTo(Source destination)voidrefresh()
-
-
-
Constructor Detail
-
PathSource
protected PathSource()
Empty constructor
-
PathSource
public PathSource(String uri) throws SourceException, MalformedURLException
Builds a PathSource given an URI, which doesn't necessarily have to start with "file:"- Parameters:
uri- The filURI- Throws:
SourceException- If URL cannot be createdMalformedURLException- If URL is malformed
-
PathSource
public PathSource(String scheme, Path path) throws SourceException
Builds a PathSource, given an URI scheme and a Path.- Parameters:
scheme- The schemepath- The file- Throws:
SourceException- If url cannot be created
-
PathSource
public PathSource(String scheme, String uri, Path path)
Builds a PathSource, given an URI scheme, URI and a Path.- Parameters:
scheme- The schemeuri- the URIpath- The file
-
-
Method Detail
-
getContentLength
public long getContentLength()
- Specified by:
getContentLengthin interfaceSource
-
getInputStream
public InputStream getInputStream() throws IOException, SourceNotFoundException
- Specified by:
getInputStreamin interfaceSource- Throws:
IOExceptionSourceNotFoundException
-
getLastModified
public long getLastModified()
- Specified by:
getLastModifiedin interfaceSource
-
getMimeType
public String getMimeType()
- Specified by:
getMimeTypein interfaceSource
-
getValidity
public SourceValidity getValidity()
- Specified by:
getValidityin interfaceSource
-
getChild
public Source getChild(String name) throws SourceException
- Specified by:
getChildin interfaceTraversableSource- Throws:
SourceException
-
getChildren
public Collection getChildren() throws SourceException
- Specified by:
getChildrenin interfaceTraversableSource- Throws:
SourceException
-
getName
public String getName()
- Specified by:
getNamein interfaceTraversableSource
-
getParent
public Source getParent() throws SourceException
- Specified by:
getParentin interfaceTraversableSource- Throws:
SourceException
-
isCollection
public boolean isCollection()
- Specified by:
isCollectionin interfaceTraversableSource
-
getOutputStream
public OutputStream getOutputStream() throws IOException
Get anInputStreamwhere 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.- Specified by:
getOutputStreamin interfaceModifiableSource- Returns:
- a stream to write to
- Throws:
ConcurrentModificationException- if another thread is currently writing to this file.IOException
-
canCancel
public boolean canCancel(OutputStream stream)
Can the data sent to anOutputStreamreturned bygetOutputStream()be cancelled ?- Specified by:
canCancelin interfaceModifiableSource- Returns:
- true if the stream can be cancelled
-
cancel
public void cancel(OutputStream stream) throws SourceException
Cancel the data sent to anOutputStreamreturned bygetOutputStream().After cancel, the stream should no more be used.
- Specified by:
cancelin interfaceModifiableSource- Throws:
SourceException
-
delete
public void delete() throws SourceException
Delete the source.- Specified by:
deletein interfaceModifiableSource- Throws:
SourceException
-
makeCollection
public void makeCollection() throws SourceException
- Specified by:
makeCollectionin interfaceModifiableTraversableSource- Throws:
SourceException
-
copyTo
public void copyTo(Source destination) throws SourceException
- Specified by:
copyToin interfaceMoveableSource- Throws:
SourceException
-
moveTo
public void moveTo(Source destination) throws SourceException
- Specified by:
moveToin interfaceMoveableSource- Throws:
SourceException
-
-