private MediaResource getBitstreamResource(Context context, Bitstream bitstream) throws SwordServerException, SwordAuthException { try { InputStream stream = bitstreamService.retrieve(context, bitstream); MediaResource mr = new MediaResource(stream, bitstream.getFormat(context).getMIMEType(), null, true); mr.setContentMD5(bitstream.getChecksum()); mr.setLastModified(this.getLastModified(context, bitstream)); return mr; } catch (IOException | SQLException e) { throw new SwordServerException(e); } catch (AuthorizeException e) { throw new SwordAuthException(e); } }
return new MediaResource(stream, disseminator.getContentType(), disseminator.getPackaging());
public static MediaResource getZippedDerivateMediaResource(String object) { final Path tempFile; try { tempFile = Files.createTempFile("swordv2_", ".temp.zip"); } catch (IOException e) { throw new MCRException("Could not create temp file!", e); } try (final OutputStream tempFileStream = Files.newOutputStream(tempFile)) { final ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(tempFileStream); zipOutputStream.setLevel(Deflater.BEST_COMPRESSION); final MCRPath root = MCRPath.getPath(object, "/"); addDirectoryToZip(zipOutputStream, root); zipOutputStream.close(); } catch (IOException e) { throw new MCRException(e); } MediaResource resultRessource; InputStream is; try { is = new MCRDeleteFileOnCloseFilterInputStream(Files.newInputStream(tempFile), tempFile); resultRessource = new MediaResource(is, MCRSwordConstants.MIME_TYPE_APPLICATION_ZIP, UriRegistry.PACKAGE_SIMPLE_ZIP); } catch (IOException e) { throw new MCRException("could not read from temp file!", e); } return resultRessource; }
resultRessource = new MediaResource(is, Files.probeContentType(path), UriRegistry.PACKAGE_BINARY); } catch (IOException e) { LOGGER.error("Error while opening File: {}", path, e);
String packaging = UriRegistry.PACKAGE_SIMPLE_ZIP; boolean isPackaged = true; MediaResource mediaResource = new MediaResource(fixmeInputStream, contentType, packaging, isPackaged); return mediaResource; } else {