Package org.restlet.engine.local
Class FileClientHelper
- java.lang.Object
-
public class FileClientHelper extends EntityClientHelper
Connector to the file resources accessible. Here is the list of parameters that are supported. They should be set in the Client's context before it is started:Parameter name Value type Default value Description temporaryExtension String tmp The name of the extension to use to store the temporary content while uploading content via the PUT method. resumeUpload boolean false Indicates if a failed upload can be resumed. This will prevent the deletion of the temporary file created.
-
-
Constructor Summary
Constructors Constructor Description FileClientHelper(Client client)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleancheckExtensionsConsistency(java.io.File file)Check that all extensions of the file correspond to a known metadata.private booleancheckMetadataConsistency(java.lang.String fileName, Representation representation)Checks that the URI and the representation are compatible.private voidcleanTemporaryFileIfUploadNotResumed(java.io.File tmp)private StatuscreateFile(Request request, java.io.File file)private StatuscreateFileWithPartialContent(Request request, java.io.File file, Range range)private StatusdoHandleFilePut(Request request, java.lang.String path, java.io.File file)EntitygetEntity(java.lang.String decodedPath)Returns a local entity for the given path.private static java.io.FilegetFileWithLocalizedPath(java.lang.String path)Returns a newFileinstance for the given path name.
It ensures to translate the "/" to the local supported file separator (mainly useful for Windows OS).java.lang.StringgetTemporaryExtension()Returns the name of the extension to use to store the temporary content while uploading content via the PUT method.protected voidhandleFile(Request request, Response response, java.lang.String decodedPath)protected voidhandleFileDelete(Response response, java.io.File file)Handles a DELETE call for the FILE protocol.protected voidhandleFilePut(Request request, Response response, java.lang.String path, java.io.File file)Handles a PUT call for the FILE protocol.protected voidhandleLocal(Request request, Response response, java.lang.String decodedPath)Handles a local call.private static booleanisFileInDirectory(Directory directory, java.io.File file)Indicates whether the given file is located inside the root directory.booleanisResumeUpload()Indicates if a failed upload can be resumed.private StatusreplaceFile(Request request, java.io.File file)private StatusreplaceFileByTemporaryFile(Request request, java.io.File file, java.io.File tmp)private voidupdateFileExtension(java.lang.StringBuilder fileName, Metadata metadata)Complete the given file name with the extension corresponding to the given metadata.private StatusupdateFileWithPartialContent(Request request, java.io.File file, Range range)-
Methods inherited from class org.restlet.engine.local.EntityClientHelper
createReference, getReencodedVariantEntityName, handleEntityGet
-
Methods inherited from class org.restlet.engine.local.LocalClientHelper
getDefaultLanguage, getTimeToLive, handle
-
Methods inherited from class org.restlet.engine.connector.ConnectorHelper
getConnectorService, getContext, getProtocols, start, stop, update
-
Methods inherited from class org.restlet.engine.RestletHelper
getAttributes, getHelped, getHelpedParameters, getLogger, getMetadataService, setHelped
-
-
-
-
Constructor Detail
-
FileClientHelper
public FileClientHelper(Client client)
Constructor.- Parameters:
client- The client to help.
-
-
Method Detail
-
checkExtensionsConsistency
protected boolean checkExtensionsConsistency(java.io.File file)
Check that all extensions of the file correspond to a known metadata.- Parameters:
file- The file whose extensions are checked.- Returns:
- True if all extensions of the file are known by the metadata service.
-
checkMetadataConsistency
private boolean checkMetadataConsistency(java.lang.String fileName, Representation representation)Checks that the URI and the representation are compatible. The whole set of metadata of the representation must be included in the set of those of the URI- Parameters:
fileName- The name of the resourcerepresentation- The provided representation.- Returns:
- True if the metadata of the representation are compatible with the metadata extracted from the filename
-
getEntity
public Entity getEntity(java.lang.String decodedPath)
Description copied from class:EntityClientHelperReturns a local entity for the given path.- Specified by:
getEntityin classEntityClientHelper- Parameters:
decodedPath- The path of the entity.- Returns:
- A local entity for the given path.
-
getFileWithLocalizedPath
private static java.io.File getFileWithLocalizedPath(java.lang.String path)
Returns a newFileinstance for the given path name.
It ensures to translate the "/" to the local supported file separator (mainly useful for Windows OS).- Parameters:
path- The Path of the file- Returns:
- a new
Fileinstance for the given path name.
-
getTemporaryExtension
public java.lang.String getTemporaryExtension()
Returns the name of the extension to use to store the temporary content while uploading content via the PUT method. Defaults to "tmp".- Returns:
- The name of the extension to use to store the temporary content.
-
handleLocal
protected void handleLocal(Request request, Response response, java.lang.String decodedPath)
Description copied from class:LocalClientHelperHandles a local call.- Overrides:
handleLocalin classEntityClientHelper- Parameters:
request- The request to handle.response- The response to update.decodedPath- The decoded local path.
-
handleFile
protected void handleFile(Request request, Response response, java.lang.String decodedPath)
-
isFileInDirectory
private static boolean isFileInDirectory(Directory directory, java.io.File file)
Indicates whether the given file is located inside the root directory.- Parameters:
directory- The root directoryfile- The file.- Returns:
- True if the path is located under the root directory, false otherwise.
-
handleFileDelete
protected void handleFileDelete(Response response, java.io.File file)
Handles a DELETE call for the FILE protocol.- Parameters:
response- The response to update.file- The file or directory to delete.
-
handleFilePut
protected void handleFilePut(Request request, Response response, java.lang.String path, java.io.File file)
Handles a PUT call for the FILE protocol.- Parameters:
request- The request to update.response- The response to update.path- The encoded path of the requested file or directory.file- The requested file or directory.
-
doHandleFilePut
private Status doHandleFilePut(Request request, java.lang.String path, java.io.File file)
-
updateFileWithPartialContent
private Status updateFileWithPartialContent(Request request, java.io.File file, Range range)
-
replaceFileByTemporaryFile
private Status replaceFileByTemporaryFile(Request request, java.io.File file, java.io.File tmp)
-
createFileWithPartialContent
private Status createFileWithPartialContent(Request request, java.io.File file, Range range)
-
cleanTemporaryFileIfUploadNotResumed
private void cleanTemporaryFileIfUploadNotResumed(java.io.File tmp)
-
isResumeUpload
public boolean isResumeUpload()
Indicates if a failed upload can be resumed. This will prevent the deletion of the temporary file created. Defaults to "false".- Returns:
- True if a failed upload can be resumed, false otherwise.
-
updateFileExtension
private void updateFileExtension(java.lang.StringBuilder fileName, Metadata metadata)Complete the given file name with the extension corresponding to the given metadata.- Parameters:
fileName- The file name to complete.metadata- The metadata.
-
-