org.jclouds.filesystem.strategy.internal
Class FilesystemStorageStrategyImpl

java.lang.Object
  extended by org.jclouds.filesystem.strategy.internal.FilesystemStorageStrategyImpl
All Implemented Interfaces:
LocalStorageStrategy

public class FilesystemStorageStrategyImpl
extends Object
implements LocalStorageStrategy

Author:
Alfredo "Rainbowbreeze" Morresi

Field Summary
protected  String baseDirectory
           
protected  javax.inject.Provider<BlobBuilder> blobBuilders
           
protected  FilesystemBlobKeyValidator filesystemBlobKeyValidator
           
protected  FilesystemContainerNameValidator filesystemContainerNameValidator
           
protected  Logger logger
           
 
Constructor Summary
protected FilesystemStorageStrategyImpl(javax.inject.Provider<BlobBuilder> blobBuilders, String baseDir, FilesystemContainerNameValidator filesystemContainerNameValidator, FilesystemBlobKeyValidator filesystemBlobKeyValidator, Crypto crypto)
           
 
Method Summary
 boolean blobExists(String container, String key)
          Return true if a blob named by key exists
protected  String buildPathStartingFromBaseDir(String... pathTokens)
          Facility method used to concatenate path tokens normalizing separators
 void clearContainer(String container)
          Empty the directory of its content (files and subdirectories)
 void clearContainer(String container, ListContainerOptions options)
          Like LocalStorageStrategy.clearContainer(String) except you can use options to do things like recursive deletes, or clear at a different path than root.
 boolean containerExists(String container)
          Checks if a container exists
 long countBlobs(String container, ListContainerOptions options)
           
 boolean createContainer(String container)
           
 boolean createContainerInLocation(String container, Location location)
          Creates a new container
 void createDirectory(String container, String directory)
           
protected  boolean createDirectoryWithResult(String container, String directory)
          Creates a directory and returns the result
 void deleteContainer(String container)
          Deletes a container and all its content
 void deleteDirectory(String container, String directory)
           
 boolean directoryExists(String container, String directory)
           
 Iterable<String> getAllContainerNames()
          Return an iterator that reports all the containers under base path
 Blob getBlob(String container, String key)
          Load the blob with the given key belonging to the container with the given name.
 Iterable<String> getBlobKeysInsideContainer(String container)
          Returns all the blobs key inside a container
 File getFileForBlobKey(String container, String blobKey)
          Returns a File object that links to the blob
 Location getLocation(String containerName)
           
 String getSeparator()
           
 Blob newBlob(String name)
           
 String putBlob(String containerName, Blob blob)
          Write a Blob into a file
 void removeBlob(String container, String blobKey)
          Remove blob named by the given key
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected Logger logger

blobBuilders

protected final javax.inject.Provider<BlobBuilder> blobBuilders

baseDirectory

protected final String baseDirectory

filesystemContainerNameValidator

protected final FilesystemContainerNameValidator filesystemContainerNameValidator

filesystemBlobKeyValidator

protected final FilesystemBlobKeyValidator filesystemBlobKeyValidator
Constructor Detail

FilesystemStorageStrategyImpl

@Inject
protected FilesystemStorageStrategyImpl(javax.inject.Provider<BlobBuilder> blobBuilders,
                                               @Named(value="jclouds.filesystem.basedir")
                                               String baseDir,
                                               FilesystemContainerNameValidator filesystemContainerNameValidator,
                                               FilesystemBlobKeyValidator filesystemBlobKeyValidator,
                                               Crypto crypto)
Method Detail

containerExists

public boolean containerExists(String container)
Description copied from interface: LocalStorageStrategy
Checks if a container exists

Specified by:
containerExists in interface LocalStorageStrategy
Returns:

blobExists

public boolean blobExists(String container,
                          String key)
Description copied from interface: LocalStorageStrategy
Return true if a blob named by key exists

Specified by:
blobExists in interface LocalStorageStrategy
Returns:

getBlob

public Blob getBlob(String container,
                    String key)
Description copied from interface: LocalStorageStrategy
Load the blob with the given key belonging to the container with the given name. There must exist a resource on the file system whose complete name is given concatenating the container name and the key

Specified by:
getBlob in interface LocalStorageStrategy
Returns:
the blob belonging to the given container with the given key

createContainer

public boolean createContainer(String container)

createContainerInLocation

public boolean createContainerInLocation(String container,
                                         Location location)
Description copied from interface: LocalStorageStrategy
Creates a new container

Specified by:
createContainerInLocation in interface LocalStorageStrategy
Returns:

deleteContainer

public void deleteContainer(String container)
Description copied from interface: LocalStorageStrategy
Deletes a container and all its content

Specified by:
deleteContainer in interface LocalStorageStrategy

clearContainer

public void clearContainer(String container)
Empty the directory of its content (files and subdirectories)

Specified by:
clearContainer in interface LocalStorageStrategy
Parameters:
container -

clearContainer

public void clearContainer(String container,
                           ListContainerOptions options)
Description copied from interface: LocalStorageStrategy
Like LocalStorageStrategy.clearContainer(String) except you can use options to do things like recursive deletes, or clear at a different path than root.

Specified by:
clearContainer in interface LocalStorageStrategy
Parameters:
container - what to clear
options - recursion and path to clear

newBlob

public Blob newBlob(String name)

removeBlob

public void removeBlob(String container,
                       String blobKey)
Description copied from interface: LocalStorageStrategy
Remove blob named by the given key

Specified by:
removeBlob in interface LocalStorageStrategy

getAllContainerNames

public Iterable<String> getAllContainerNames()
Return an iterator that reports all the containers under base path

Specified by:
getAllContainerNames in interface LocalStorageStrategy
Returns:

getFileForBlobKey

public File getFileForBlobKey(String container,
                              String blobKey)
Returns a File object that links to the blob

Parameters:
container -
blobKey -
Returns:

putBlob

public String putBlob(String containerName,
                      Blob blob)
               throws IOException
Description copied from interface: LocalStorageStrategy
Write a Blob into a file

Specified by:
putBlob in interface LocalStorageStrategy
Returns:
etag of blob
Throws:
IOException

getBlobKeysInsideContainer

public Iterable<String> getBlobKeysInsideContainer(String container)
                                            throws IOException
Returns all the blobs key inside a container

Specified by:
getBlobKeysInsideContainer in interface LocalStorageStrategy
Parameters:
container -
Returns:
Throws:
IOException

getLocation

public Location getLocation(String containerName)
Specified by:
getLocation in interface LocalStorageStrategy
Parameters:
containerName - name of container
Returns:
Location of container or null

getSeparator

public String getSeparator()
Specified by:
getSeparator in interface LocalStorageStrategy
Returns:
path separator, either / or \

directoryExists

public boolean directoryExists(String container,
                               String directory)

createDirectory

public void createDirectory(String container,
                            String directory)

deleteDirectory

public void deleteDirectory(String container,
                            String directory)

countBlobs

public long countBlobs(String container,
                       ListContainerOptions options)

buildPathStartingFromBaseDir

protected String buildPathStartingFromBaseDir(String... pathTokens)
Facility method used to concatenate path tokens normalizing separators

Parameters:
pathTokens - all the string in the proper order that must be concatenated in order to obtain the filename
Returns:
the resulting string

createDirectoryWithResult

protected boolean createDirectoryWithResult(String container,
                                            String directory)
Creates a directory and returns the result

Parameters:
container -
directory -
Returns:
true if the directory was created, otherwise false


Copyright © 2009-2012 jclouds. All Rights Reserved.