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());
}
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;
}
}
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();
}
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);
}
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);
}
}
Aggregations