@Test public void copyAsset() throws IOException { Path newFile=null; Path newDir=null; try { Assert.assertTrue(Files.exists(file1)); try (OutputStream os = Files.newOutputStream(file1)) { IOUtils.write("testakdkkdkdkdk", os, "ASCII"); } long fileSize = Files.size(file1); fsStorage.copyAsset(file1Asset, "/dir2/testfile2.dat", StandardCopyOption.REPLACE_EXISTING); Assert.assertTrue(Files.exists(file1)); Assert.assertEquals(fileSize, Files.size(file1)); newFile = baseDir.resolve("dir2/testfile2.dat"); Assert.assertTrue(Files.exists(newFile)); Assert.assertEquals(fileSize, Files.size(newFile)); try { fsStorage.copyAsset(file1Asset, "/dir2/testfile2.dat"); Assert.assertTrue("IOException should be thrown (File exists)", false); } catch (IOException ex) { Assert.assertTrue("Exception must contain 'file exists'", ex.getMessage().contains("file exists")); } Assert.assertTrue(Files.exists(dir1)); newDir = baseDir.resolve("dir2/testdir2"); fsStorage.copyAsset(dir1Asset, "dir2/testdir2"); Assert.assertTrue(Files.exists(dir1)); Assert.assertTrue(Files.exists(newDir)); } finally { if (newFile!=null) Files.deleteIfExists(newFile); if (newDir!=null) FileUtils.deleteQuietly(newDir.toFile()); } }
@Override public StorageAsset copyAsset( StorageAsset origin, String destination, CopyOption... copyOptions ) throws IOException { boolean container = origin.isContainer(); FilesystemAsset newAsset = new FilesystemAsset(this, destination, getAssetPath(destination), basePath, container ); copyAsset( origin, newAsset, copyOptions ); return newAsset; }
FilesystemStorage implements RepositoryStorage { @Override public StorageAsset copyAsset( StorageAsset origin, String destination, CopyOption... copyOptions ) throws IOException { boolean container = origin.isContainer(); FilesystemAsset newAsset = new FilesystemAsset(this, destination, getAssetPath(destination), basePath, container ); copyAsset( origin, newAsset, copyOptions ); return newAsset; } }
FilesystemStorage implements RepositoryStorage { @Override public StorageAsset copyAsset( StorageAsset origin, String destination, CopyOption... copyOptions ) throws IOException { boolean container = origin.isContainer(); FilesystemAsset newAsset = new FilesystemAsset(this, destination, getAssetPath(destination), basePath, container ); copyAsset( origin, newAsset, copyOptions ); return newAsset; } FilesystemStorage(Path basePath, FileLockManager fileLockManager); }
FilesystemStorage implements RepositoryStorage { @Override public StorageAsset copyAsset( StorageAsset origin, String destination, CopyOption... copyOptions ) throws IOException { boolean container = origin.isContainer(); FilesystemAsset newAsset = new FilesystemAsset(this, destination, getAssetPath(destination), basePath, container ); copyAsset( origin, newAsset, copyOptions ); return newAsset; } FilesystemStorage(Path basePath, FileLockManager fileLockManager); @Override void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ); @Override void consumeDataFromChannel( StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock ); @Override void writeData( StorageAsset asset, Consumer<OutputStream> consumerFunction, boolean writeLock ); @Override void writeDataToChannel( StorageAsset asset, Consumer<WritableByteChannel> consumerFunction, boolean writeLock ); @Override URI getLocation(); @Override void updateLocation(URI newLocation); @Override StorageAsset getAsset( String path ); @Override StorageAsset getRoot( ); @Override StorageAsset addAsset( String path, boolean container ); @Override void removeAsset( StorageAsset asset ); @Override StorageAsset moveAsset( StorageAsset origin, String destination, CopyOption... copyOptions ); @Override void moveAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions ); @Override StorageAsset copyAsset( StorageAsset origin, String destination, CopyOption... copyOptions ); @Override void copyAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions ); FileLockManager getFileLockManager(); }
FilesystemStorage implements RepositoryStorage { @Override public StorageAsset copyAsset( StorageAsset origin, String destination, CopyOption... copyOptions ) throws IOException { boolean container = origin.isContainer(); FilesystemAsset newAsset = new FilesystemAsset(this, destination, getAssetPath(destination), basePath, container ); copyAsset( origin, newAsset, copyOptions ); return newAsset; } FilesystemStorage(Path basePath, FileLockManager fileLockManager); @Override void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ); @Override void consumeDataFromChannel( StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock ); @Override void writeData( StorageAsset asset, Consumer<OutputStream> consumerFunction, boolean writeLock ); @Override void writeDataToChannel( StorageAsset asset, Consumer<WritableByteChannel> consumerFunction, boolean writeLock ); @Override URI getLocation(); @Override void updateLocation(URI newLocation); @Override StorageAsset getAsset( String path ); @Override StorageAsset getRoot( ); @Override StorageAsset addAsset( String path, boolean container ); @Override void removeAsset( StorageAsset asset ); @Override StorageAsset moveAsset( StorageAsset origin, String destination, CopyOption... copyOptions ); @Override void moveAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions ); @Override StorageAsset copyAsset( StorageAsset origin, String destination, CopyOption... copyOptions ); @Override void copyAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions ); FileLockManager getFileLockManager();  }