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
AModifiableTraversableSource
for path objects.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PathSource()
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 boolean
canCancel(OutputStream stream)
Can the data sent to anOutputStream
returned bygetOutputStream()
be cancelled ?void
cancel(OutputStream stream)
Cancel the data sent to anOutputStream
returned bygetOutputStream()
.void
copyTo(Source destination)
void
delete()
Delete the source.boolean
exists()
Source
getChild(String name)
Collection
getChildren()
long
getContentLength()
Path
getFile()
Get the associated fileInputStream
getInputStream()
long
getLastModified()
String
getMimeType()
String
getName()
OutputStream
getOutputStream()
Get anInputStream
where raw bytes can be written to.Source
getParent()
String
getScheme()
String
getURI()
SourceValidity
getValidity()
boolean
isCollection()
void
makeCollection()
void
moveTo(Source destination)
void
refresh()
-
-
-
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:
getContentLength
in interfaceSource
-
getInputStream
public InputStream getInputStream() throws IOException, SourceNotFoundException
- Specified by:
getInputStream
in interfaceSource
- Throws:
IOException
SourceNotFoundException
-
getLastModified
public long getLastModified()
- Specified by:
getLastModified
in interfaceSource
-
getMimeType
public String getMimeType()
- Specified by:
getMimeType
in interfaceSource
-
getValidity
public SourceValidity getValidity()
- Specified by:
getValidity
in interfaceSource
-
getChild
public Source getChild(String name) throws SourceException
- Specified by:
getChild
in interfaceTraversableSource
- Throws:
SourceException
-
getChildren
public Collection getChildren() throws SourceException
- Specified by:
getChildren
in interfaceTraversableSource
- Throws:
SourceException
-
getName
public String getName()
- Specified by:
getName
in interfaceTraversableSource
-
getParent
public Source getParent() throws SourceException
- Specified by:
getParent
in interfaceTraversableSource
- Throws:
SourceException
-
isCollection
public boolean isCollection()
- Specified by:
isCollection
in interfaceTraversableSource
-
getOutputStream
public OutputStream getOutputStream() throws IOException
Get anInputStream
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.- Specified by:
getOutputStream
in 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 anOutputStream
returned bygetOutputStream()
be cancelled ?- Specified by:
canCancel
in interfaceModifiableSource
- Returns:
- true if the stream can be cancelled
-
cancel
public void cancel(OutputStream stream) throws SourceException
Cancel the data sent to anOutputStream
returned bygetOutputStream()
.After cancel, the stream should no more be used.
- Specified by:
cancel
in interfaceModifiableSource
- Throws:
SourceException
-
delete
public void delete() throws SourceException
Delete the source.- Specified by:
delete
in interfaceModifiableSource
- Throws:
SourceException
-
makeCollection
public void makeCollection() throws SourceException
- Specified by:
makeCollection
in interfaceModifiableTraversableSource
- Throws:
SourceException
-
copyTo
public void copyTo(Source destination) throws SourceException
- Specified by:
copyTo
in interfaceMoveableSource
- Throws:
SourceException
-
moveTo
public void moveTo(Source destination) throws SourceException
- Specified by:
moveTo
in interfaceMoveableSource
- Throws:
SourceException
-
-