use of org.mycore.common.content.MCRByteContent in project mycore by MyCoRe-Org.
the class MCRFileTest method getMD5.
@Test
public void getMD5() throws Exception {
MCRFile file = col.createFile("foo.txt");
assertEquals(MCRFile.MD5_OF_EMPTY_FILE, file.getMD5());
byte[] content = "Hello World".getBytes("UTF-8");
file.setContent(new MCRByteContent(content, System.currentTimeMillis()));
assertFalse(MCRFile.MD5_OF_EMPTY_FILE.equals(file.getMD5()));
MCRFileCollection col2 = getStore().retrieve(col.getID());
MCRFile child = (MCRFile) col2.getChild("foo.txt");
assertEquals(file.getMD5(), child.getMD5());
}
use of org.mycore.common.content.MCRByteContent in project mycore by MyCoRe-Org.
the class MCRBase method setFromXML.
/**
* This method read the XML input stream from a byte array to build up the
* MyCoRe-Object.
*
* @param xml
* a XML string
* @exception MCRException
* general Exception of MyCoRe
*/
protected final void setFromXML(byte[] xml, boolean valid) throws MCRException, SAXParseException {
Document jdom = MCRXMLParserFactory.getParser(valid).parseXML(new MCRByteContent(xml));
setFromJDOM(jdom);
}
use of org.mycore.common.content.MCRByteContent 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.MCRByteContent 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.MCRByteContent 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