Search in sources :

Example 1 with AbstractStudyFile

use of com.odysseusinc.arachne.portal.model.AbstractStudyFile in project ArachneCentralAPI by OHDSI.

the class StudyFileServiceImpl method archiveFiles.

@Override
public void archiveFiles(OutputStream os, Path filePath, List<? extends AbstractStudyFile> files) throws IOException {
    ZipOutputStream zos = new ZipOutputStream(os);
    for (AbstractStudyFile studyFile : files) {
        ZipEntry entry = new ZipEntry(studyFile.getRealName());
        Path file = filePath.resolve(studyFile.getUuid());
        entry.setSize(file.toFile().length());
        zos.putNextEntry(entry);
        zos.write(Files.readAllBytes(file));
        zos.closeEntry();
    }
    zos.flush();
    zos.close();
}
Also used : Path(java.nio.file.Path) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) AbstractStudyFile(com.odysseusinc.arachne.portal.model.AbstractStudyFile)

Example 2 with AbstractStudyFile

use of com.odysseusinc.arachne.portal.model.AbstractStudyFile in project ArachneCentralAPI by OHDSI.

the class StudyFileServiceImpl method getFileInputStream.

@Override
public InputStream getFileInputStream(AbstractStudyFile studyFile) throws FileNotFoundException {
    Objects.requireNonNull(studyFile, "File must not be null");
    final File file = getPathToFile(studyFile).toFile();
    if (!file.exists()) {
        if (!StringUtils.isEmpty(studyFile.getLink())) {
            InputStream response = getInputStream(studyFile);
            if (response != null) {
                return response;
            }
        }
        throw new FileNotFoundException();
    }
    return new FileInputStream(file);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) StudyFile(com.odysseusinc.arachne.portal.model.StudyFile) AbstractPaperFile(com.odysseusinc.arachne.portal.model.AbstractPaperFile) File(java.io.File) AbstractStudyFile(com.odysseusinc.arachne.portal.model.AbstractStudyFile) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream)

Aggregations

AbstractStudyFile (com.odysseusinc.arachne.portal.model.AbstractStudyFile)2 AbstractPaperFile (com.odysseusinc.arachne.portal.model.AbstractPaperFile)1 StudyFile (com.odysseusinc.arachne.portal.model.StudyFile)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1