Package nl.knaw.dans.layerstore
Interface Layer
public interface Layer
This interface represents a layer in the layered item store. A layer can be in the following states:
# | open/closed | archived | staged? | when? |
---|---|---|---|---|
1 | open | niet archived | ja | beginsituatie van elke top layer |
2 | closed | niet archived | ja (met .closed suffix) | op het moment voordat de top layer gearchiveerd wordt |
3 | closed | archived | nee | archivering gelukt |
4 | open | archived | ja | reopened |
5 | closed | archived | ja (met .closed suffix) | close van een heropende layer |
-
Method Summary
Modifier and TypeMethodDescriptionvoid
archive()
Turns the layer into an archive file.void
close()
Changes the state of the layer to 'closed'.void
createDirectory
(String path) Creates a directory at the given path.void
deleteDirectory
(String path) Deletes the directory at the given path, including all its contents.void
deleteFiles
(List<String> paths) Deletes the files pointed to bypaths
.boolean
fileExists
(String path) Returns whether a file exists at the given path in this layer.long
getId()
Returns the id of the layer.long
Returns the size of the layer in bytes.boolean
Returns whether the layer is archived.boolean
isOpen()
Returns whether the layer is open.Lists the items in this layer.void
moveDirectoryInternal
(String source, String destination) Moves the directory atsource
todestination
, where both paths are relative to the root of the layer.void
moveDirectoryInto
(Path source, String destination) Moves the directory atsource
into the directory atdestination
.Reads the file at the given path.void
reopen()
Changes the state of the layer to open.void
writeFile
(String filePath, InputStream content) Writes the content of the given input stream to the file at the given path.
-
Method Details
-
getId
long getId()Returns the id of the layer.- Returns:
- the id of the layer
-
close
void close()Changes the state of the layer to 'closed'.- Throws:
IllegalStateException
- if the layer is already closed
-
reopen
Changes the state of the layer to open. It also stages the archive file in the staging directory. This operation is not allowed when the layer is not closed or not yet archived.- Throws:
IOException
-
isOpen
boolean isOpen()Returns whether the layer is open.- Returns:
- whether the layer is open
-
archive
void archive()Turns the layer into an archive file. -
isArchived
boolean isArchived()Returns whether the layer is archived.- Returns:
- whether the layer is archived
-
createDirectory
Creates a directory at the given path. Not allowed when the layer is closed.- Parameters:
path
- the path of the directory relative to the storage root- Throws:
IOException
- if the directory cannot be created
-
deleteDirectory
Deletes the directory at the given path, including all its contents. Not allowed when the layer is closed.- Parameters:
path
- the path of the directory relative to the storage root- Throws:
IOException
- if the directory cannot be deleted
-
fileExists
Returns whether a file exists at the given path in this layer.- Parameters:
path
- the path of the file relative to the storage root- Returns:
- whether the file exists
- Throws:
IOException
- if the existence of the file cannot be determined
-
readFile
Reads the file at the given path. Note, that this may take a long time if the layer is archived, especially when the archive is stored on tape.- Parameters:
path
- the path of the file relative to the storage root- Returns:
- an input stream for reading the file; the caller is responsible for closing the stream
- Throws:
IOException
- if the file cannot be read
-
writeFile
Writes the content of the given input stream to the file at the given path. Not allowed when the layer is closed. If the file already exists, it is overwritten.- Parameters:
filePath
- the path of the file relative to the storage rootcontent
- the content of the file- Throws:
IOException
- if the file cannot be written
-
deleteFiles
Deletes the files pointed to bypaths
. Not allowed when the layer is closed.- Parameters:
paths
- the paths of the files to be deleted- Throws:
IOException
- if the files cannot be deleted
-
moveDirectoryInto
Moves the directory atsource
into the directory atdestination
. Not allowed when the layer is closed.- Parameters:
source
- the path of the directory to be moved; must be an existing directorydestination
- the path of the directory to move into; the directory is created if it does not exist yet- Throws:
IOException
- if the directory cannot be moved
-
moveDirectoryInternal
Moves the directory atsource
todestination
, where both paths are relative to the root of the layer.- Parameters:
source
- the path of the directory to be moved; must be an existing directorydestination
- the path of the destination directory; must not exist yet- Throws:
IOException
- if the directory cannot be moved
-
getSizeInBytes
Returns the size of the layer in bytes. If the layer is archived, this may take a long time, especially when the archive is stored on tape.- Returns:
- the size of the layer in bytes
- Throws:
IOException
- if the size cannot be determined
-
listAllItems
Lists the items in this layer.- Returns:
- the items in this layer
- Throws:
IOException
- if the items cannot be listed
-