Package com.logicaldoc.core.store

# Class FSStore

java.lang.Object
com.logicaldoc.core.store.AbstractStore
com.logicaldoc.core.store.FSStore

All Implemented Interfaces:
  `Store`, `Comparable<Store>`

Direct Known Subclasses:
  `MockStore`

public class FSStore extends AbstractStore
This class is an implementation of the Store interface to persist documents in the filesystem. From the root of the documents store, 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
`FSStore()`

## Method Summary

Modifier and Type
Method
Description
`void`
`delete(long docId)`
Deletes all resources of a document from the store.
`void`
`delete(StoreResource resource)`
Deletes a specific resource of a document from the store.
`boolean`
`exists(StoreResource resource)`
Checks if the passed resource exists in the document's container
`byte[]`
`getBytes(StoreResource resource, long start, long length)`
Obtains the document's raw bytes for the specified resource
`File`
`getContainer(long docId)`
Finds the container where all document's files are stored
`List<String>`
`getParameterNames()`
Implementations should return the list of the required parameters.
`File`
`getRoot()`
`InputStream`
`getStream(StoreResource resource)`
Obtains the document's content for the specified resource
`long`
`getTotalSize()`
Computes the total size of the documents repository(in bytes)
`List<StoreResource>`
`listResources(long docId, String fileVersion)`
Lists all resources in the document's container
`int`
`moveResourcesToStore(long docId, int targetStoreId)`
Moves all the resources of a document from it's original location to a different store
`long`
`size(StoreResource resource)`
Computed the size of a specific resource.
`void`
`store(File file, StoreResource resource)`
Stores a file
`void`
`store(InputStream stream, StoreResource resource)`
This method has to store a resource in the document's container.
`void`
`writeToFile(StoreResource resource, File out)`
Writes the specified resource in a file

### Methods inherited from class com.logicaldoc.core.store.AbstractStore

`compareTo, destroy, equals, getBytes, getConfig, getId, getParameters, getStoreDefinitions, getString, hashCode, init, isEnabled, newStore, setConfig, setId, test, toString, writeToStream, writeToStream`

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`

## Constructor Details

### FSStore

public FSStore()

## Method Details

### delete

public void delete(long docId)
Description copied from interface: `Store`
Deletes all resources of a document from the store.

Parameters:
  `docId` - The document identifier

### delete

public void delete(StoreResource resource)
Description copied from interface: `Store`
Deletes a specific resource of a document from the store.

Parameters:
  `resource` - 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, StoreResource resource) throws IOException
Description copied from interface: `Store`
Stores a file

Specified by:
  `store` in interface `Store`
Overrides:
  `store` in class `AbstractStore`
Parameters:
  `file` - the file to store
  `resource` - Resource to be stored, make sure to provide the right document's ID
Throws:
  `IOException` - the content cannot be stored

### store

public void store(InputStream stream, StoreResource resource) throws IOException
Description copied from interface: `Store`
This 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 InputStream
  `resource` - Resource to be stored, make sure to provide the right document's ID
Throws:
  `IOException` - the content cannot be stored

### writeToFile

public void writeToFile(StoreResource resource, File out) throws IOException
Description copied from interface: `Store`
Writes the specified resource in a file

Specified by:
  `writeToFile` in interface `Store`
Overrides:
  `writeToFile` in class `AbstractStore`
Parameters:
  `resource` - The resource
  `out` - File that will receive the resource's content
Throws:
  `IOException` - error writing the file or reading the resource

### getStream

public InputStream getStream(StoreResource resource) throws IOException
Description copied from interface: `Store`
Obtains the document's content for the specified resource

Parameters:
  `resource` - The resource
Returns:
  The document file's content
Throws:
  `IOException` - cannot open the stream

### getTotalSize

public long getTotalSize()
Description copied from interface: `Store`
Computes 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(StoreResource resource, long start, long length) throws IOException
Description copied from interface: `Store`
Obtains the document's raw bytes for the specified resource

Parameters:
  `resource` - The resource
  `start` - Index of the starting byte
  `length` - Total packet length
Returns:
  The document file's bytes
Throws:
  `IOException` - cannot open the resource to get the bytes

### listResources

public List<StoreResource> listResources(long docId, String fileVersion)
Description copied from interface: `Store`
Lists all resources in the document's container

Parameters:
  `docId` - The document's identifier
  `fileVersion` - If specified, lists the resources for that specific file version only
Returns:
  list of resources

### size

public long size(StoreResource resource)
Description copied from interface: `Store`
Computed the size of a specific resource.

Parameters:
  `resource` - The resource
Returns:
  the size in bytes

### exists

public boolean exists(StoreResource resource)
Description copied from interface: `Store`
Checks if the passed resource exists in the document's container

Parameters:
  `resource` - The resource
Returns:
  true only if the resource already exists

### getParameterNames

public List<String> getParameterNames()
Description copied from interface: `Store`
Implementations should return the list of the required parameters. A parameter is stored in the context as store.id.parameter = value

Returns:
  list of parameter names

### moveResourcesToStore

public int moveResourcesToStore(long docId, int targetStoreId) throws IOException
Description copied from interface: `Store`
Moves all the resources of a document from it's original location to a different store

Parameters:
  `docId` - identifier of the document to process
  `targetStoreId` - identifier of the store that will receive the files
Returns:
  number of moved resources
Throws:
  `IOException` - In case of error during the process