Removed SharedFileChannel transferTo and corresponding methods

* Removed from SharedFileChannel and Test
* Refactored Copier#copy(File,File) to sequence of truncated, followed
by looping read and write till EOF
* Changed tests accordingly
* Implemented CryptoWritableFile#truncate to make things work
This commit is contained in:
Markus Kreusch
2016-01-24 22:14:06 +01:00
parent e241c5ba05
commit f081e7d3ea
24 changed files with 231 additions and 260 deletions
@@ -14,7 +14,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.function.Supplier;
import org.cryptomator.filesystem.ReadableFile;
import org.cryptomator.filesystem.WritableFile;
import org.cryptomator.io.ByteBuffers;
class InMemoryReadableFile implements ReadableFile {
@@ -34,14 +33,6 @@ class InMemoryReadableFile implements ReadableFile {
return open;
}
@Override
public void copyTo(WritableFile other) throws UncheckedIOException {
ByteBuffer source = contentGetter.get().asReadOnlyBuffer();
source.position(0);
other.truncate();
this.position += other.write(source);
}
@Override
public int read(ByteBuffer destination) throws UncheckedIOException {
ByteBuffer source = contentGetter.get().asReadOnlyBuffer();
@@ -110,11 +110,7 @@ public class InMemoryFileSystemTest {
// copy foo to bar
File barFile = fs.file("bar.txt");
try (WritableFile writable = barFile.openWritable()) {
try (ReadableFile readable = fooFile.openReadable()) {
readable.copyTo(writable);
}
}
fooFile.copyTo(barFile);
Assert.assertTrue(fooFile.exists());
Assert.assertTrue(barFile.exists());