X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Facr%2Ffs%2FFsContent.java;h=77c2f7a7585fe778834ec9735635b749905581d1;hb=c0342975a37c70895c2e8f6b341d790700168d7f;hp=76dc9da71d65bf95053679e2d99cf6e969623f69;hpb=5dd5ad8acfa6f78f98b8d8f082f0c1647d02ff2a;p=lgpl%2Fargeo-commons.git
diff --git a/org.argeo.cms/src/org/argeo/cms/acr/fs/FsContent.java b/org.argeo.cms/src/org/argeo/cms/acr/fs/FsContent.java
index 76dc9da71..77c2f7a75 100644
--- a/org.argeo.cms/src/org/argeo/cms/acr/fs/FsContent.java
+++ b/org.argeo.cms/src/org/argeo/cms/acr/fs/FsContent.java
@@ -8,6 +8,7 @@ import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileTime;
import java.nio.file.attribute.UserDefinedFileAttributeView;
import java.time.Instant;
@@ -20,6 +21,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.concurrent.CompletableFuture;
import javax.xml.namespace.QName;
@@ -322,4 +324,24 @@ public class FsContent extends AbstractContent implements ProvidedContent {
return provider;
}
+ /*
+ * READ / WRITE
+ */
+ public CompletableFuture write(Class clss) {
+ if (isContentClass(CrName.collection.qName())) {
+ throw new IllegalStateException("Cannot directly write to a collection");
+ }
+ if (InputStream.class.isAssignableFrom(clss)) {
+ CompletableFuture res = new CompletableFuture<>();
+ res.thenAccept((in) -> {
+ try {
+ Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot write to " + path, e);
+ }
+ });
+ return (CompletableFuture) res;
+ }
+ return super.write(clss);
+ }
}