mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-24 21:51:27 +00:00
using Guavas ByteStreams.copy where possible
This commit is contained in:
@@ -20,6 +20,12 @@
|
||||
<artifactId>commons</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Guava -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- apache commons -->
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
|
||||
@@ -8,14 +8,13 @@
|
||||
*******************************************************************************/
|
||||
package org.cryptomator.filesystem;
|
||||
|
||||
import static org.cryptomator.filesystem.File.EOF;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
class Copier {
|
||||
|
||||
private static final int COPY_BUFFER_SIZE = 128 * 1024;
|
||||
|
||||
public static void copy(Folder source, Folder destination) {
|
||||
assertFoldersAreNotNested(source, destination);
|
||||
|
||||
@@ -37,13 +36,10 @@ class Copier {
|
||||
try (OpenFiles openFiles = DeadlockSafeFileOpener.withReadable(source).andWritable(destination).open()) {
|
||||
ReadableFile readable = openFiles.readable(source);
|
||||
WritableFile writable = openFiles.writable(destination);
|
||||
ByteBuffer buffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
|
||||
writable.truncate();
|
||||
while (readable.read(buffer) != EOF) {
|
||||
buffer.flip();
|
||||
writable.write(buffer);
|
||||
buffer.clear();
|
||||
}
|
||||
ByteStreams.copy(readable, writable);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,12 @@
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Guava -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Commons -->
|
||||
<dependency>
|
||||
|
||||
@@ -108,6 +108,7 @@ public class WebDavServer implements FrontendFactory {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
final ServletContextHandler handler = addServlet(root, uri);
|
||||
LOG.info("Servlet available under " + uri);
|
||||
return new WebDavFrontend(webdavMounterProvider, handler, uri);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
package org.cryptomator.webdav.jackrabbitservlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.time.Instant;
|
||||
@@ -28,9 +27,9 @@ import org.cryptomator.filesystem.ReadableFile;
|
||||
import org.cryptomator.filesystem.WritableFile;
|
||||
import org.cryptomator.filesystem.jackrabbit.FileLocator;
|
||||
|
||||
class DavFile extends DavNode<FileLocator> {
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
private static final int BUFFER_SIZE = 32 * 1024;
|
||||
class DavFile extends DavNode<FileLocator> {
|
||||
|
||||
public DavFile(FilesystemResourceFactory factory, LockManager lockManager, DavSession session, FileLocator node) {
|
||||
super(factory, lockManager, session, node);
|
||||
@@ -49,12 +48,7 @@ class DavFile extends DavNode<FileLocator> {
|
||||
}
|
||||
try (ReadableFile src = node.openReadable(); WritableByteChannel dst = Channels.newChannel(outputContext.getOutputStream())) {
|
||||
outputContext.setContentLength(src.size());
|
||||
ByteBuffer buf = ByteBuffer.allocate(BUFFER_SIZE);
|
||||
do {
|
||||
buf.clear();
|
||||
src.read(buf);
|
||||
buf.flip();
|
||||
} while (dst.write(buf) > 0);
|
||||
ByteStreams.copy(src, dst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ package org.cryptomator.webdav.jackrabbitservlet;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.time.Instant;
|
||||
@@ -37,9 +36,9 @@ import org.cryptomator.filesystem.WritableFile;
|
||||
import org.cryptomator.filesystem.jackrabbit.FileLocator;
|
||||
import org.cryptomator.filesystem.jackrabbit.FolderLocator;
|
||||
|
||||
class DavFolder extends DavNode<FolderLocator> {
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
private static final int BUFFER_SIZE = 32 * 1024;
|
||||
class DavFolder extends DavNode<FolderLocator> {
|
||||
|
||||
public DavFolder(FilesystemResourceFactory factory, LockManager lockManager, DavSession session, FolderLocator folder) {
|
||||
super(factory, lockManager, session, folder);
|
||||
@@ -74,12 +73,7 @@ class DavFolder extends DavNode<FolderLocator> {
|
||||
|
||||
private void addMemberFile(DavFile memberFile, InputStream inputStream) {
|
||||
try (ReadableByteChannel src = Channels.newChannel(inputStream); WritableFile dst = node.file(memberFile.getDisplayName()).openWritable()) {
|
||||
ByteBuffer buf = ByteBuffer.allocate(BUFFER_SIZE);
|
||||
while (src.read(buf) != -1) {
|
||||
buf.flip();
|
||||
dst.write(buf);
|
||||
buf.clear();
|
||||
}
|
||||
ByteStreams.copy(src, dst);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,6 @@ abstract class DavNode<T extends FileSystemResourceLocator> implements DavResour
|
||||
if (node.exists()) {
|
||||
Temporal lastModifiedDate = OffsetDateTime.ofInstant(node.lastModified(), ZoneOffset.UTC);
|
||||
String lastModifiedDateStr = DateTimeFormatter.RFC_1123_DATE_TIME.format(lastModifiedDate);
|
||||
System.err.println(lastModifiedDateStr);
|
||||
DavProperty<String> lastModifiedDateProp = new DefaultDavProperty<>(DavPropertyName.GETLASTMODIFIED, lastModifiedDateStr);
|
||||
properties.add(lastModifiedDateProp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user