Package org.trellisldp.file
Class FileUtils
- java.lang.Object
-
- org.trellisldp.file.FileUtils
-
public final class FileUtils extends Object
File-based utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_FILE_DIGEST_ALGORITHM
The configuration key controlling the digest algorithm in use.static String
CONFIG_FILE_LDP_TYPE
The configuration key for controlling LDP type triples.static int
LENGTH
The length of the CRC directory partition.static int
MAX
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
filterServerManagedQuads(Quad quad)
Filter any server-managed triples from the resource stream.static InputStream
getBoundedStream(InputStream stream, int from, int to)
Get a bounded inputstream.static File
getNquadsFile(File dir, Instant time)
Get the nquads file for a given moment in time.static File
getResourceDirectory(File baseDirectory, IRI identifier)
Get a directory for a given resource identifier.static Stream<Quad>
parseQuad(String line)
Parse a string into a stream of Quads.static String
serializeQuad(Quad quad)
Serialize an RDF Quad.static boolean
uncheckedDeleteIfExists(Path path)
Try to delete a file if it exists or throw an unchecked exception.static Stream<Path>
uncheckedList(Path path)
Fetch a stream of files in the provided directory path.static void
writeMemento(File resourceDir, Resource resource, Instant time)
Write a Memento to a particular resource directory.
-
-
-
Field Detail
-
CONFIG_FILE_LDP_TYPE
public static final String CONFIG_FILE_LDP_TYPE
The configuration key for controlling LDP type triples.- See Also:
- Constant Field Values
-
CONFIG_FILE_DIGEST_ALGORITHM
public static final String CONFIG_FILE_DIGEST_ALGORITHM
The configuration key controlling the digest algorithm in use.- See Also:
- Constant Field Values
-
LENGTH
public static final int LENGTH
The length of the CRC directory partition.- See Also:
- Constant Field Values
-
MAX
public static final int MAX
- See Also:
- Constant Field Values
-
-
Method Detail
-
getResourceDirectory
public static File getResourceDirectory(File baseDirectory, IRI identifier)
Get a directory for a given resource identifier.- Parameters:
baseDirectory
- the base directoryidentifier
- a resource identifier- Returns:
- a directory
-
parseQuad
public static Stream<Quad> parseQuad(String line)
Parse a string into a stream of Quads.- Parameters:
line
- the line of text- Returns:
- the Quad
-
filterServerManagedQuads
public static boolean filterServerManagedQuads(Quad quad)
Filter any server-managed triples from the resource stream.- Parameters:
quad
- the quad- Returns:
- true if the quad should be kept, false otherwise
-
uncheckedDeleteIfExists
public static boolean uncheckedDeleteIfExists(Path path)
Try to delete a file if it exists or throw an unchecked exception.- Parameters:
path
- the file path- Returns:
- true if the file existed and was deleted; false otherwise
-
uncheckedList
public static Stream<Path> uncheckedList(Path path)
Fetch a stream of files in the provided directory path.- Parameters:
path
- the directory path- Returns:
- a stream of filenames
-
writeMemento
public static void writeMemento(File resourceDir, Resource resource, Instant time)
Write a Memento to a particular resource directory.- Parameters:
resourceDir
- the resource directoryresource
- the resourcetime
- the time for the memento
-
getBoundedStream
public static InputStream getBoundedStream(InputStream stream, int from, int to) throws IOException
Get a bounded inputstream.- Parameters:
stream
- the input streamfrom
- the byte from which to startto
- the byte to which to read- Returns:
- the bounded inputstream
- Throws:
IOException
- if an error occurs when skipping forward
-
serializeQuad
public static String serializeQuad(Quad quad)
Serialize an RDF Quad.- Parameters:
quad
- the quad- Returns:
- a serialization of the quad
-
-