Search in sources :

Example 1 with MCRByteArrayOutputStream

use of org.mycore.common.content.streams.MCRByteArrayOutputStream in project mycore by MyCoRe-Org.

the class MCRXSLTransformer method getTransformedContent.

protected MCRContent getTransformedContent(MCRContent source, XMLReader reader, TransformerHandler transformerHandler) throws IOException, SAXException {
    MCRByteArrayOutputStream baos = new MCRByteArrayOutputStream(INITIAL_BUFFER_SIZE);
    StreamResult serializer = new StreamResult(baos);
    transformerHandler.setResult(serializer);
    // Parse the source XML, and send the parse events to the
    // TransformerHandler.
    LOGGER.info("Start transforming: {}", source.getSystemId() == null ? source.getName() : source.getSystemId());
    reader.parse(source.getInputSource());
    return new MCRByteContent(baos.getBuffer(), 0, baos.size());
}
Also used : MCRByteArrayOutputStream(org.mycore.common.content.streams.MCRByteArrayOutputStream) StreamResult(javax.xml.transform.stream.StreamResult) MCRByteContent(org.mycore.common.content.MCRByteContent)

Example 2 with MCRByteArrayOutputStream

use of org.mycore.common.content.streams.MCRByteArrayOutputStream in project mycore by MyCoRe-Org.

the class MCRPNGTools method toPNGContent.

public MCRContent toPNGContent(BufferedImage thumbnail) throws IOException {
    if (thumbnail != null) {
        ImageWriter imageWriter = getImageWriter();
        try (MCRByteArrayOutputStream bout = new MCRByteArrayOutputStream(maxPngSize.get());
            ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(bout)) {
            imageWriter.setOutput(imageOutputStream);
            IIOImage iioImage = new IIOImage(thumbnail, null, null);
            imageWriter.write(null, iioImage, imageWriteParam);
            int contentLength = bout.size();
            maxPngSize.set(Math.max(maxPngSize.get(), contentLength));
            MCRByteContent imageContent = new MCRByteContent(bout.getBuffer(), 0, bout.size());
            imageContent.setMimeType("image/png");
            return imageContent;
        } finally {
            imageWriter.reset();
            imageWriters.add(imageWriter);
        }
    } else {
        return null;
    }
}
Also used : MCRByteArrayOutputStream(org.mycore.common.content.streams.MCRByteArrayOutputStream) ImageWriter(javax.imageio.ImageWriter) MCRByteContent(org.mycore.common.content.MCRByteContent) ImageOutputStream(javax.imageio.stream.ImageOutputStream) IIOImage(javax.imageio.IIOImage)

Example 3 with MCRByteArrayOutputStream

use of org.mycore.common.content.streams.MCRByteArrayOutputStream in project mycore by MyCoRe-Org.

the class MCRXMLHelper method canonicalElement.

private static Element canonicalElement(Parent e) throws IOException, SAXParseException {
    XMLOutputter xout = new XMLOutputter(Format.getCompactFormat());
    MCRByteArrayOutputStream bout = new MCRByteArrayOutputStream();
    if (e instanceof Element) {
        xout.output((Element) e, bout);
    } else {
        xout.output((Document) e, bout);
    }
    Document xml = MCRXMLParserFactory.getNonValidatingParser().parseXML(new MCRByteContent(bout.getBuffer(), 0, bout.size()));
    return xml.getRootElement();
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) MCRByteArrayOutputStream(org.mycore.common.content.streams.MCRByteArrayOutputStream) JsonElement(com.google.gson.JsonElement) Element(org.jdom2.Element) MCRByteContent(org.mycore.common.content.MCRByteContent) Document(org.jdom2.Document)

Example 4 with MCRByteArrayOutputStream

use of org.mycore.common.content.streams.MCRByteArrayOutputStream in project mycore by MyCoRe-Org.

the class MCRVersionedMetadata method update.

/**
 * Updates the version stored in the local filesystem to the latest version
 * from Subversion repository HEAD.
 */
public void update() throws Exception {
    SVNRepository repository = getStore().getRepository();
    MCRByteArrayOutputStream baos = new MCRByteArrayOutputStream();
    long rev = repository.getFile(getFilePath(), -1, null, baos);
    revision = () -> Optional.of(rev);
    baos.close();
    new MCRByteContent(baos.getBuffer(), 0, baos.size(), this.getLastModified().getTime()).sendTo(fo);
}
Also used : MCRByteArrayOutputStream(org.mycore.common.content.streams.MCRByteArrayOutputStream) MCRByteContent(org.mycore.common.content.MCRByteContent) SVNRepository(org.tmatesoft.svn.core.io.SVNRepository)

Example 5 with MCRByteArrayOutputStream

use of org.mycore.common.content.streams.MCRByteArrayOutputStream in project mycore by MyCoRe-Org.

the class MCRMetadataVersion method retrieve.

/**
 * Retrieves this version of the metadata
 *
 * @return the metadata document as it was in this version
 * @throws MCRUsageException
 *             if this is a deleted version, which can not be retrieved
 */
public MCRContent retrieve() throws IOException {
    if (type == DELETED) {
        String msg = "You can not retrieve a deleted version, retrieve a previous version instead";
        throw new MCRUsageException(msg);
    }
    try {
        SVNRepository repository = vm.getStore().getRepository();
        MCRByteArrayOutputStream baos = new MCRByteArrayOutputStream();
        repository.getFile(vm.getStore().getSlotPath(vm.getID()), revision, null, baos);
        baos.close();
        return new MCRByteContent(baos.getBuffer(), 0, baos.size(), getDate().getTime());
    } catch (SVNException e) {
        throw new IOException(e);
    }
}
Also used : MCRUsageException(org.mycore.common.MCRUsageException) MCRByteArrayOutputStream(org.mycore.common.content.streams.MCRByteArrayOutputStream) MCRByteContent(org.mycore.common.content.MCRByteContent) SVNRepository(org.tmatesoft.svn.core.io.SVNRepository) SVNException(org.tmatesoft.svn.core.SVNException) IOException(java.io.IOException)

Aggregations

MCRByteContent (org.mycore.common.content.MCRByteContent)5 MCRByteArrayOutputStream (org.mycore.common.content.streams.MCRByteArrayOutputStream)5 SVNRepository (org.tmatesoft.svn.core.io.SVNRepository)2 JsonElement (com.google.gson.JsonElement)1 IOException (java.io.IOException)1 IIOImage (javax.imageio.IIOImage)1 ImageWriter (javax.imageio.ImageWriter)1 ImageOutputStream (javax.imageio.stream.ImageOutputStream)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Document (org.jdom2.Document)1 Element (org.jdom2.Element)1 XMLOutputter (org.jdom2.output.XMLOutputter)1 MCRUsageException (org.mycore.common.MCRUsageException)1 SVNException (org.tmatesoft.svn.core.SVNException)1