Package com.logicaldoc.core.store
Class FSStorer
- java.lang.Object
-
- com.logicaldoc.core.store.AbstractStorer
-
- com.logicaldoc.core.store.FSStorer
-
- All Implemented Interfaces:
Storer,Comparable<Storer>
- Direct Known Subclasses:
MockStorer
public class FSStorer extends AbstractStorer
This class is an implementation of the Storer interface to persist documents in the filesystem. From the root of the documents storage, this implementation saves all document's files into a defined directory using the following logic. The document's id is tokenized by three chars tokens, than the doc/ dir is appended, so if the docId=12345, the document's path will be:123/45/doc.- Since:
- 4.5
- Author:
- Marco Meschieri - LogicalDOC
-
-
Constructor Summary
Constructors Constructor Description FSStorer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete(long docId)Deletes all resources of a document from the storage.voiddelete(long docId, String resource)Deletes a specific resource of a document from the storage.booleanexists(long docId, String resource)Checks if the passed resource exists in the document's containerbyte[]getBytes(long docId, String resource, long start, long length)Obtains the document's raw bytes for the specified resourceFilegetContainer(long docId)Finds the container where all document's files are storedList<String>getParameterNames()Implementations should return the list of the required parameters.FilegetRoot()InputStreamgetStream(long docId, String resource)Obtains the document's content for the specified resourcelonggetTotalSize()Computes the total size of the documents repository(in bytes)List<String>listResources(long docId, String fileVersion)Lists all resources in the document's containerintmoveResourcesToStore(long docId, int targetStorageId)Moves all the resources of a document from it's original location to a different storagelongsize(long docId, String resource)Computed the size of a specific resource.voidstore(File file, long docId, String resource)Stores a filevoidstore(InputStream stream, long docId, String resource)This method has to store a resource in the document's container.voidwriteToFile(long docId, String resource, File out)Writes the specified resource in a file-
Methods inherited from class com.logicaldoc.core.store.AbstractStorer
compareTo, destroy, equals, getBytes, getConfig, getId, getParameters, getResourceName, getResourceName, getString, hashCode, init, isEnabled, setConfig, setId, setManager, test, toString, writeToStream, writeToStream
-
-
-
-
Method Detail
-
delete
public void delete(long docId)
Description copied from interface:StorerDeletes all resources of a document from the storage.- Parameters:
docId- The document identifier
-
delete
public void delete(long docId, String resource)Description copied from interface:StorerDeletes a specific resource of a document from the storage.- Parameters:
docId- The document identifierresource- Name of the resource to be deleted
-
getContainer
public File getContainer(long docId)
Finds the container where all document's files are stored- Parameters:
docId- The document identifier- Returns:
- The document's container
-
getRoot
public File getRoot()
-
store
public void store(File file, long docId, String resource) throws IOException
Description copied from interface:StorerStores a file- Specified by:
storein interfaceStorer- Overrides:
storein classAbstractStorer- Parameters:
file- the file to storedocId- identifier of the documentresource- name of the resource- Throws:
IOException- the content cannot be stored- See Also:
Storer.store(java.io.InputStream,long,java.lang.String)
-
store
public void store(InputStream stream, long docId, String resource) throws IOException
Description copied from interface:StorerThis method has to store a resource in the document's container. The location where (DBMS, Filesystem, other) the document should be stored is defined by the concrete implementation. It is possible to store a new document or a new version of an existing document.- Parameters:
stream- Document as InputStreamdocId- The document identifierresource- Name of the resource to be stored- Throws:
IOException- the content cannot be stored
-
writeToFile
public void writeToFile(long docId, String resource, File out) throws IOExceptionDescription copied from interface:StorerWrites the specified resource in a file- Specified by:
writeToFilein interfaceStorer- Overrides:
writeToFilein classAbstractStorer- Parameters:
docId- The document identifierresource- Name of the resourceout- File that will receive the resource's content- Throws:
IOException- error writing the file or reading the resource
-
getStream
public InputStream getStream(long docId, String resource) throws IOException
Description copied from interface:StorerObtains the document's content for the specified resource- Parameters:
docId- The document's identifierresource- Name of the resource- Returns:
- The document file's content
- Throws:
IOException- cannot open the stream
-
getTotalSize
public long getTotalSize()
Description copied from interface:StorerComputes the total size of the documents repository(in bytes)- Returns:
- sum of the sizes of all the documents expressed in bytes
-
getBytes
public byte[] getBytes(long docId, String resource, long start, long length) throws IOExceptionDescription copied from interface:StorerObtains the document's raw bytes for the specified resource- Parameters:
docId- The document's identifierresource- Name of the resourcestart- Index of the starting bytelength- Total packet length- Returns:
- The document file's bytes
- Throws:
IOException- cannot open the resource to get the bytes
-
listResources
public List<String> listResources(long docId, String fileVersion)
Description copied from interface:StorerLists all resources in the document's container- Parameters:
docId- The document's identifierfileVersion- If specified, lists the resources for that specific file version only- Returns:
- list of resource names
-
size
public long size(long docId, String resource)Description copied from interface:StorerComputed the size of a specific resource.- Parameters:
docId- The document's identifierresource- The resource- Returns:
- the size in bytes
-
exists
public boolean exists(long docId, String resource)Description copied from interface:StorerChecks if the passed resource exists in the document's container- Parameters:
docId- ID of the documentresource- Name of the resource- Returns:
- true only if the resource already exists
-
getParameterNames
public List<String> getParameterNames()
Description copied from interface:StorerImplementations should return the list of the required parameters. A parameter is stored in the context as storer.id.parameter = value- Returns:
- list of parameter names
-
moveResourcesToStore
public int moveResourcesToStore(long docId, int targetStorageId) throws IOExceptionDescription copied from interface:StorerMoves all the resources of a document from it's original location to a different storage- Parameters:
docId- identifier of the document to processtargetStorageId- identifier of the storage that will receive the files- Returns:
- number of moved resources
- Throws:
IOException- In case of error during the process
-
-