Pull request #427: RED-4686: Stream objects to storage
Merge in RED/redaction-service from RED-4686-backport to release/3.107.x * commit 'bb433a09974d048291a362d7fb9f6e3cf431543d': RED-4686: Stream objects to storage
This commit is contained in:
commit
17783c7e1d
@ -32,7 +32,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.iqser.red</groupId>
|
<groupId>com.iqser.red</groupId>
|
||||||
<artifactId>platform-commons-dependency</artifactId>
|
<artifactId>platform-commons-dependency</artifactId>
|
||||||
<version>1.11.0</version>
|
<version>1.15.0</version>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.storage;
|
package com.iqser.red.service.redaction.v1.server.storage;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
@ -41,7 +42,10 @@ public class RedactionStorageService {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void storeObject(String dossierId, String fileId, FileType fileType, Object any) {
|
public void storeObject(String dossierId, String fileId, FileType fileType, Object any) {
|
||||||
|
|
||||||
storageService.storeObject(StorageIdUtils.getStorageId(dossierId, fileId, fileType), objectMapper.writeValueAsBytes(any));
|
try (var baos = new ByteArrayOutputStream()){
|
||||||
|
objectMapper.writeValue(baos, any);
|
||||||
|
storageService.storeObject(StorageIdUtils.getStorageId(dossierId, fileId, fileType), baos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,18 +7,20 @@ import lombok.SneakyThrows;
|
|||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.util.HashMap;
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
public class FileSystemBackedStorageService extends S3StorageService {
|
public class FileSystemBackedStorageService implements StorageService{
|
||||||
|
|
||||||
private final Map<String, File> dataMap = new HashMap<>();
|
private final Map<String, File> dataMap = new HashMap<>();
|
||||||
|
|
||||||
public FileSystemBackedStorageService() {
|
public FileSystemBackedStorageService() {
|
||||||
super(null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@ -33,16 +35,69 @@ public class FileSystemBackedStorageService extends S3StorageService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteObject(String objectId) {
|
||||||
|
dataMap.remove(objectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean objectExists(String objectId) {
|
||||||
|
return dataMap.containsKey(objectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> listPaths(){
|
||||||
|
return new ArrayList<>(dataMap.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<String> listFilePaths(){
|
||||||
|
return dataMap.values().stream().map(File::getAbsolutePath).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public void storeObject(String objectId, byte[] data) {
|
public void storeObject(String objectId, byte[] data) {
|
||||||
File tempFile = File.createTempFile("test", ".tmp");
|
File tempFile = File.createTempFile("storage", objectId.replace("/","-"));
|
||||||
|
|
||||||
IOUtils.write(data, new FileOutputStream(tempFile));
|
try(var fileOutputStream = new FileOutputStream(tempFile)) {
|
||||||
|
IOUtils.write(data, fileOutputStream);
|
||||||
|
}
|
||||||
|
|
||||||
dataMap.put(objectId, tempFile);
|
dataMap.put(objectId, tempFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public void storeObject(String objectId, InputStream stream) {
|
||||||
|
File tempFile = File.createTempFile("test", ".tmp");
|
||||||
|
|
||||||
|
try(var fileOutputStream = new FileOutputStream(tempFile)) {
|
||||||
|
IOUtils.copy(stream, fileOutputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
dataMap.put(objectId, tempFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public void storeObject(String objectId, ByteArrayOutputStream stream) {
|
||||||
|
|
||||||
|
File tempFile = File.createTempFile("test", ".tmp");
|
||||||
|
try(var fileOutputStream = new FileOutputStream(tempFile)){
|
||||||
|
stream.writeTo(fileOutputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
dataMap.put(objectId, tempFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void clearStorage() {
|
public void clearStorage() {
|
||||||
this.dataMap.forEach((k, v) -> {
|
this.dataMap.forEach((k, v) -> {
|
||||||
v.delete();
|
v.delete();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user