public class ContentUtils extends Object
Utility class for content based operations.
Modifier and Type | Field and Description |
---|---|
static Type |
CONTENT_INFO_PROPERTIES_TYPE_TOKEN
The
Type used for the de-/serialization of the ContentInfo.getProperties() map. |
Modifier and Type | Method and Description |
---|---|
static void |
deleteRecursively(Path directory)
Deletes the given path (mostly a directory) recursively.
|
static <T> T |
deserialize(String json,
Type type)
Deserialize the given JSON string to the respective object.
|
static ContentMetadata |
deserializeContentMetadata(String jsonContentMetadata)
Deserialize the given JSON string to a
ContentMetadata . |
static ContentReference |
deserializeContentReference(String jsonContentReference)
Deserialize the given JSON string to a
ContentReference . |
static void |
lockAndProcessFile(Path fileToLock,
com.google.common.base.Function<byte[],Optional<byte[]>> processingFunction)
Opens the specified
Path with create, sync, read and write mode (see StandardOpenOption s), tries to fully lock and then process it with the given function. |
static String |
serialize(Object object,
Type type)
Serialize the given
ContentMetadata to a JSON string. |
static String |
serializeContentMetadata(ContentMetadata contentMetadata)
Serialize the given
ContentMetadata to a JSON string. |
static String |
serializeContentReference(ContentReference contentReference)
Serialize the given
ContentReference to a JSON string. |
public static final Type CONTENT_INFO_PROPERTIES_TYPE_TOKEN
The Type
used for the de-/serialization of the ContentInfo.getProperties()
map.
public static void deleteRecursively(Path directory)
Deletes the given path (mostly a directory) recursively. This means that all files inside the directory will be deleted.
directory
- the path to delete recursivelyContentException
- if there is an error while deleting the pathpublic static String serializeContentReference(ContentReference contentReference)
Serialize the given ContentReference
to a JSON string.
contentReference
- the content reference to serializepublic static ContentReference deserializeContentReference(String jsonContentReference)
Deserialize the given JSON string to a ContentReference
. It will return an instance of ContentReference
.
jsonContentReference
- the JSON representation of a content referencepublic static String serializeContentMetadata(ContentMetadata contentMetadata)
Serialize the given ContentMetadata
to a JSON string.
contentMetadata
- the content metadata to serializepublic static ContentMetadata deserializeContentMetadata(String jsonContentMetadata)
Deserialize the given JSON string to a ContentMetadata
. It will return an instance of DefaultContentMetadata
.
jsonContentMetadata
- the JSON representation of a content metadatapublic static String serialize(Object object, Type type)
Serialize the given ContentMetadata
to a JSON string.
object
- the object to serializetype
- the type of the object to serializepublic static <T> T deserialize(String json, Type type)
Deserialize the given JSON string to the respective object.
json
- the JSON representation of a content metadatapublic static void lockAndProcessFile(Path fileToLock, com.google.common.base.Function<byte[],Optional<byte[]>> processingFunction)
Opens the specified Path
with create, sync, read and write mode (see StandardOpenOption
s), tries to fully lock and then process it with the given function.
When the processing inside the function is finished, its optional output will be written back to the file if present.
fileToLock
- the path of the file to lockprocessingFunction
- the function to process the content of the file.ContentException
- if there is an IO errorOverlappingFileLockException
- if the file to lock is already locked by this JVM. See FileChannel.lock()
for more information.Copyright © 2010 - 2019 edorasware ag. All Rights Reserved.