Код: Выделить всё
java.io.IOException: Stream Closed
at java.base/java.io.FileInputStream.readBytes(Native Method)
at java.base/java.io.FileInputStream.read(FileInputStream.java:279)
at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:90)
at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107)
at com.comsurf.services.export.ExportServiceImpl.lambda$exportDocumentsFicheToZip$26(ExportServiceImplementation.java:795)
Код: Выделить всё
//the map is fullfilled with the name of the objects/documents and the content of the documents recovered from s3 (Map s3ObjectInputStream)
Map s3ObjectInputStreamMap...
s3ObjectInputStreamMap.keySet().forEach(key -> {
var zipEntry = new ZipEntry(key);
try {
zipOutputStream.putNextEntry(zipEntry);
var objectContent = s3ObjectInputStreamList.get(key);
var bytes = new byte[1024];
int length;
while ((length = objectContent.read(bytes)) >= 0) {
zipOutputStream.write(bytes, 0, length);
}
objectContent.close();
zipEntry.clone();
} catch (IOException e) {
e.printStackTrace();
}
});
Я создал следующий метод для создания объектов, возвращаемых из S3Service (имитируемый сервис) в тесте:
Код: Выделить всё
private static S3Object getS3Object(String fileName) throws FileNotFoundException {
S3Object s3Object = new S3Object();
s3Object.setKey(fileName);
File initialFile = new File(FILE_ADRESS+ "/" + fileName);
InputStream targetStream = new FileInputStream(initialFile);
s3Object.setObjectContent(targetStream);
return s3Object;
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... in-my-test