Search in sources :

Example 6 with DeletionSelector

use of org.opencastproject.assetmanager.impl.storage.DeletionSelector in project opencast by opencast.

the class TestTasksEndpoint method mkAssetStore.

AssetStore mkAssetStore(final Workspace workspace) {
    return new AssetStore() {

        @Override
        public Option<Long> getUsedSpace() {
            return Option.none();
        }

        @Override
        public Option<Long> getUsableSpace() {
            return Option.none();
        }

        @Override
        public Option<Long> getTotalSpace() {
            return Option.none();
        }

        @Override
        public void put(StoragePath path, Source source) throws AssetStoreException {
            File destFile = new File(baseDir, UrlSupport.concat(path.getMediaPackageId(), path.getMediaPackageElementId(), path.getVersion().toString()));
            try {
                FileUtils.copyFile(workspace.get(source.getUri()), destFile);
            } catch (IOException e) {
                throw new RuntimeException(e);
            } catch (NotFoundException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public Opt<InputStream> get(StoragePath path) throws AssetStoreException {
            File file = new File(baseDir, UrlSupport.concat(path.getMediaPackageId(), path.getMediaPackageElementId(), path.getVersion().toString()));
            InputStream inputStream;
            try {
                inputStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(file));
                return Opt.some(inputStream);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public boolean delete(DeletionSelector sel) throws AssetStoreException {
            return false;
        }

        @Override
        public boolean copy(StoragePath from, StoragePath to) throws AssetStoreException {
            File file = new File(baseDir, UrlSupport.concat(from.getMediaPackageId(), from.getMediaPackageElementId(), from.getVersion().toString()));
            File destFile = new File(baseDir, UrlSupport.concat(to.getMediaPackageId(), to.getMediaPackageElementId(), to.getVersion().toString()));
            try {
                FileUtils.copyFile(file, destFile);
                return true;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public boolean contains(StoragePath path) throws AssetStoreException {
            return false;
        }
    };
}
Also used : DeletionSelector(org.opencastproject.assetmanager.impl.storage.DeletionSelector) StoragePath(org.opencastproject.assetmanager.impl.storage.StoragePath) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) AssetStore(org.opencastproject.assetmanager.impl.storage.AssetStore) IOException(java.io.IOException) File(java.io.File) Source(org.opencastproject.assetmanager.impl.storage.Source)

Aggregations

DeletionSelector (org.opencastproject.assetmanager.impl.storage.DeletionSelector)6 File (java.io.File)4 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 AssetStore (org.opencastproject.assetmanager.impl.storage.AssetStore)3 Source (org.opencastproject.assetmanager.impl.storage.Source)3 StoragePath (org.opencastproject.assetmanager.impl.storage.StoragePath)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 NotFoundException (org.opencastproject.util.NotFoundException)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1