public Bitstream getBitstream(Context context, String location) throws DSpaceSwordException, SwordError { try { String baseUrl = this.getSwordBaseUrl(); String emBaseUrl = baseUrl + "/edit-media/bitstream/"; if (!location.startsWith(emBaseUrl)) { throw new SwordError(DSpaceUriRegistry.BAD_URL, "The bitstream URL is invalid"); } String bitstreamParts = location.substring(emBaseUrl.length()); // the bitstream id is the part up to the first "/" int firstSlash = bitstreamParts.indexOf("/"); String bid = bitstreamParts.substring(0, firstSlash); Bitstream bitstream = bitstreamService.findByIdOrLegacyId(context, bid); return bitstream; } catch (SQLException e) { // log.error("Caught exception:", e); throw new DSpaceSwordException( "There was a problem resolving the collection", e); } }
public InputStream getInputStream() throws SQLException, IOException, AuthorizeException { return getBitstreamService().retrieve(context, bitstream); }
/** * This helper method takes some bytes and stores them as a bitstream for an * item, under the CC bundle, with the given bitstream name * * Note: This helper method assumes that the CC * bitstreams are short and easily expressed as byte arrays in RAM * * @param context The relevant DSpace Context. * @param item parent item * @param bundle parent bundle * @param bitstream_name bitstream name to set * @param format bitstream format * @param bytes bitstream data * @throws IOException A general class of exceptions produced by failed or interrupted I/O operations. * @throws SQLException An exception that provides information on a database access error or other errors. * @throws AuthorizeException Exception indicating the current user of the context does not have permission * to perform a particular action. */ protected void setBitstreamFromBytes(Context context, Item item, Bundle bundle, String bitstream_name, BitstreamFormat format, byte[] bytes) throws SQLException, IOException, AuthorizeException { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); Bitstream bs = bitstreamService.create(context, bundle, bais); bs.setName(context, bitstream_name); bs.setSource(context, CC_BS_SOURCE); bs.setFormat(context, format); // commit everything bitstreamService.update(context, bs); }
/** * @param context The relevant DSpace Context. * @param bitstream the bitstream to be cloned * @return id of the clone bitstream. * A general class of exceptions produced by failed or interrupted I/O operations. * @throws SQLException An exception that provides information on a database access error or other errors. * @throws AuthorizeException Exception indicating the current user of the context does not have permission * to perform a particular action. */ @Override public Bitstream clone(Context context, Bitstream bitstream) throws SQLException, IOException, AuthorizeException { Bitstream clonedBitstream = bitstreamService.clone(context, bitstream); clonedBitstream.setStoreNumber(bitstream.getStoreNumber()); List<MetadataValue> metadataValues = bitstreamService .getMetadata(bitstream, Item.ANY, Item.ANY, Item.ANY, Item.ANY); for (MetadataValue metadataValue : metadataValues) { bitstreamService.addMetadata(context, clonedBitstream, metadataValue.getMetadataField(), metadataValue.getLanguage(), metadataValue.getValue(), metadataValue.getAuthority(), metadataValue.getConfidence()); } bitstreamService.update(context, clonedBitstream); return clonedBitstream; }
try { fileStream = new FileInputStream(pkgFile); bs = bitstreamService.create(context, original, fileStream); } finally { if (fileStream != null) { bitstreamService.update(context, bs); if (log.isDebugEnabled()) { log.debug("Created bitstream ID=" + String.valueOf(bs.getID()) + ", parsing..."); crosswalkPDF(context, myitem, bitstreamService.retrieve(context, bs));
+ bitstreamName); bs.setDescription(c, thisDescription); bitstreamService.update(c, bs);
} else { log.trace("Getting bundle from item."); dspaceBitstream = bitstreamService.create(context, bundle, inputStream); dspaceBitstream.setFormat(context, bitstreamFormatService.findUnknown(context)); } else { bitstreamService.setFormat(context, dspaceBitstream, bitstreamFormatService .findByMIMEType(context, BitstreamResource.getMimeType(name))); bitstreamService.updateLastModified(context, dspaceBitstream); dspaceBitstream = bitstreamService.find(context, dspaceBitstream.getID()); bitstream = new Bitstream(dspaceBitstream, servletContext, "", context);
org.dspace.content.Bitstream bitstream = null; try { bitstream = bitstreamService.findByIdOrLegacyId(context, id); if ((bitstream == null) || (bitstreamService.getParentObject(context, bitstream) == null)) { context.abort(); log.warn("Bitstream(id=" + id + ") was not found!");
if (getMimeType(bitstream.getName()) == null) { BitstreamFormat unknownFormat = bitstreamFormatService.findUnknown(context); bitstreamService.setFormat(context, dspaceBitstream, unknownFormat); } else { BitstreamFormat guessedFormat = bitstreamFormatService .findByMIMEType(context, getMimeType(bitstream.getName())); bitstreamService.setFormat(context, dspaceBitstream, guessedFormat); bitstreamService.update(context, dspaceBitstream);
bundleService.removeBitstream(context, dBundle, displayMap.get(bitstream.getName())); Bitstream citedBitstream = bitstreamService.create(context, dBundle, citedDoc); bitstreamService.setFormat(context, citedBitstream, bitstream.getFormat(Curator.curationContext())); citedBitstream.setDescription(context, bitstream.getDescription());
@Override public Pair<InputStream, Long> makeCitedDocument(Context context, Bitstream bitstream) throws IOException, SQLException, AuthorizeException { PDDocument document = new PDDocument(); PDDocument sourceDocument = new PDDocument(); try { Item item = (Item) bitstreamService.getParentObject(context, bitstream); sourceDocument = sourceDocument.load(bitstreamService.retrieve(context, bitstream)); PDPage coverPage = new PDPage(citationPageFormat); generateCoverPage(context, document, coverPage, item); addCoverPageToDocument(document, sourceDocument, coverPage); //We already have the full PDF in memory, so keep it there try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { document.save(out); byte[] data = out.toByteArray(); return Pair.of((InputStream) new ByteArrayInputStream(data), new Long(data.length)); } } finally { sourceDocument.close(); document.close(); } }
org.dspace.content.Item item = findItem(context, itemId, org.dspace.core.Constants.WRITE); org.dspace.content.Bitstream bitstream = bitstreamService.findByIdOrLegacyId(context, bitstreamId); if (bitstream == null) { context.abort(); bitstreamService.delete(context, bitstream);
if (bitstreamService.getParentObject(context, bitstream).getType() == Constants.ITEM) { bundleName = bitstream.getBundles().get(0).getName(); format = bitstreamService.getFormatDescription(context, bitstream); sizeBytes = bitstream.getSizeBytes(); String path = new DSpace().getRequestService().getCurrentRequest().getHttpServletRequest().getContextPath(); retrieveLink = path + "/bitstreams/" + bitstream.getID() + "/retrieve"; mimeType = bitstreamService.getFormat(context, bitstream).getMIMEType(); sequenceId = bitstream.getSequenceID(); CheckSum checkSum = new CheckSum(); parentObject = new DSpaceObject(bitstreamService.getParentObject(context, bitstream), servletContext); } else { this.addExpand("parent");
/** * Consume an event * * @param ctx the execution context object * @param event the content event * @throws Exception if error */ @Override public void consume(Context ctx, Event event) throws Exception { if (event.getEventType() == Event.DELETE) { Bitstream bitstream = bitstreamService.find(ctx, event.getSubjectID()); log.debug("Attempting to remove Checker Info"); checksumHistoryService.deleteByBitstream(ctx, bitstream); log.debug("Completed removing Checker Info"); } }
InputStream is = bitstreamService.retrieve(c, bitstream); FileOutputStream fos = new FileOutputStream(fout); Utils.bufferedCopy(is, fos); if (bitstreamService.isRegisteredBitstream(bitstream)) { out.println("-r -s " + bitstream.getStoreNumber() + " -f " + myName +