| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.filesystem.util.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import javax.inject.Provider; |
| 24 | |
| 25 | import org.jclouds.blobstore.AsyncBlobStore; |
| 26 | import org.jclouds.blobstore.domain.Blob; |
| 27 | import org.jclouds.blobstore.domain.BlobBuilder; |
| 28 | import org.jclouds.blobstore.options.ListContainerOptions; |
| 29 | import org.jclouds.blobstore.util.BlobUtils; |
| 30 | import org.jclouds.filesystem.strategy.FilesystemStorageStrategy; |
| 31 | |
| 32 | import com.google.inject.Inject; |
| 33 | |
| 34 | /** |
| 35 | * Implements the {@link BlobUtils} interfaced and act as a bridge to |
| 36 | * {@link FilesystemStorageStrategy} when used inside {@link AsyncBlobStore} |
| 37 | * |
| 38 | * @author Alfredo "Rainbowbreeze" Morresi |
| 39 | */ |
| 40 | public class FileSystemBlobUtilsImpl implements BlobUtils { |
| 41 | |
| 42 | protected final FilesystemStorageStrategy storageStrategy; |
| 43 | protected final Provider<BlobBuilder> blobBuilders; |
| 44 | |
| 45 | @Inject |
| 46 | public FileSystemBlobUtilsImpl(FilesystemStorageStrategy storageStrategy, Provider<BlobBuilder> blobBuilders) { |
| 47 | this.storageStrategy = checkNotNull(storageStrategy, "Filesystem Storage Strategy"); |
| 48 | this.blobBuilders = checkNotNull(blobBuilders, "Filesystem blobBuilders"); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public Blob newBlob(String name) { |
| 53 | return blobBuilder().name(name).build(); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public BlobBuilder blobBuilder() { |
| 58 | return blobBuilders.get(); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean directoryExists(String containerName, String directory) { |
| 63 | return storageStrategy.directoryExists(containerName, directory); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void createDirectory(String containerName, String directory) { |
| 68 | storageStrategy.createDirectory(containerName, directory); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public long countBlobs(String container, ListContainerOptions options) { |
| 73 | return storageStrategy.countBlobs(container, options); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void clearContainer(String container, ListContainerOptions options) { |
| 78 | storageStrategy.clearContainer(container, options); |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void deleteDirectory(String container, String directory) { |
| 83 | storageStrategy.deleteDirectory(container, directory); |
| 84 | } |
| 85 | |
| 86 | } |