Class SilverpeasFile
- java.lang.Object
-
- java.io.File
-
- org.silverpeas.core.io.file.SilverpeasFile
-
- All Implemented Interfaces:
Serializable
,Comparable<File>
- Direct Known Subclasses:
DragAndDropWebEditorStore.File
public class SilverpeasFile extends File
A representation of a File in Silverpeas. This class abstracts the way the files are managed in Silverpeas by extending the original JDK file with additional features. A file in Silverpeas belongs always to a component instance and is qualified by its MIME type.Such file can be either a document referred by a publication's attachment or an image from a form.
- Author:
- mmoquillon
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static SilverpeasFile
NO_FILE
A SilverpeasFile representing a non existent file.-
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SilverpeasFile(String componentId, String path)
Creates a new Silverpeas file belonging to the specified component instance and located at the specified path in the Silverpeas filesystem.protected
SilverpeasFile(String componentId, String path, String mimeType)
Creates a new Silverpeas file belonging to the specified component instance and located at the specified path in the Silverpeas filesystem.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SilverpeasFile
copyInto(String directoryPath)
Copies this file into the specified directory.boolean
delete()
boolean
equals(Object o)
boolean
exists()
String
getComponentInstanceId()
String
getMimeType()
int
hashCode()
InputStream
inputStream()
Opens and returns an input stream to this file.boolean
isArchive()
Indicates if the current silverpeas file is of type archive.boolean
isImage()
Indicates if the current file is of type image.boolean
isMail()
Indicates if the current file is of type mail.boolean
isOpenOfficeCompatible()
Indicates if the current file is of type OpenOffice compatible.boolean
isPdf()
Indicates if the current file is of type PDF.SilverpeasFile
moveInto(String directoryPath)
Moves this file into the specified directory.void
writeFrom(InputStream stream)
Writes the content of the specified input stream into this file.-
Methods inherited from class java.io.File
canExecute, canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, deleteOnExit, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getFreeSpace, getName, getParent, getParentFile, getPath, getTotalSpace, getUsableSpace, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setExecutable, setExecutable, setLastModified, setReadable, setReadable, setReadOnly, setWritable, setWritable, toPath, toString, toURI, toURL
-
-
-
-
Field Detail
-
NO_FILE
public static final SilverpeasFile NO_FILE
A SilverpeasFile representing a non existent file. It is better to work with it than taking into account a FileNotFoundException exception raising.
-
-
Constructor Detail
-
SilverpeasFile
protected SilverpeasFile(String componentId, String path)
Creates a new Silverpeas file belonging to the specified component instance and located at the specified path in the Silverpeas filesystem. The MIME type of the file is detected.- Parameters:
componentId
- the unique identifier of the component instance.path
- the absolute path of the file.
-
SilverpeasFile
protected SilverpeasFile(String componentId, String path, String mimeType)
Creates a new Silverpeas file belonging to the specified component instance and located at the specified path in the Silverpeas filesystem. The exact MIME type of the file is also specified.- Parameters:
componentId
- the unique identifier of the component instance.path
- the absolute path of the file.mimeType
- the MIME type of the file.
-
-
Method Detail
-
getMimeType
public String getMimeType()
-
getComponentInstanceId
public String getComponentInstanceId()
-
delete
public boolean delete()
- Overrides:
delete
in classFile
- Returns:
- true if the deletion succeed, false otherwise.
- See Also:
A chain of post-processors will be ran once this file deleted to perform possible additional treatments.
-
inputStream
public InputStream inputStream() throws IOException
Opens and returns an input stream to this file.- Returns:
- a buffered input stream to this file.
- Throws:
IOException
- if an error occurs while opening the input stream.
-
writeFrom
public void writeFrom(InputStream stream) throws IOException
Writes the content of the specified input stream into this file. If this file doesn't aleady exists, then it is created.A chain of post-processors will be ran once the content written in this file to perform possible additional treatments.
- Parameters:
stream
- the input stream from which the content to write is fetched.- Throws:
IOException
- if an error occurs while writing the content from the specified input stream into this file.
-
moveInto
public SilverpeasFile moveInto(String directoryPath) throws IOException
Moves this file into the specified directory. If the directory doesn't exist, it is then created before. Once the file is moved, it is not more existing. If the file doesn't exist, then nothing is done andNO_FILE
is returned.A chain of post-processors will be ran once this file is moved to the directory to perform possible additional treatments on the the moved file.
The moving operation will create a new file in the specified directory with the content of this file and then delete this file. Consequently, a chain of post-processors will be ran against the deleted file to perform additional treatments at file deletion.
- Parameters:
directoryPath
- the absolute path of the directory into which this file has to be moved.- Returns:
- the SilverpeasFile located at the specified directory.
- Throws:
IOException
- if an error occurs while moving this file into the specified directory
-
copyInto
public SilverpeasFile copyInto(String directoryPath) throws IOException
Copies this file into the specified directory. If the directory doesn't exist, it is then created before.A chain of post-processors will be ran once this file is copied to the directory to perform possible additional treatments on the copied file.
- Parameters:
directoryPath
- the absolute path of the directory into which this file has to be moved.- Throws:
IOException
- if an error occurs while copying this file into the specified directory
-
isArchive
public boolean isArchive()
Indicates if the current silverpeas file is of type archive.- Returns:
- true if it is an archive file, false otherwise.
-
isImage
public boolean isImage()
Indicates if the current file is of type image.- Returns:
- true if it is an image file, false otherwise.
-
isMail
public boolean isMail()
Indicates if the current file is of type mail.- Returns:
- true if it is a mail file, false otherwise.
-
isPdf
public boolean isPdf()
Indicates if the current file is of type PDF.- Returns:
- true if it is a PDF file, false otherwise.
-
isOpenOfficeCompatible
public boolean isOpenOfficeCompatible()
Indicates if the current file is of type OpenOffice compatible.- Returns:
- true if it is a OpenOffice compatible file, false otherwise.
-
-