Search in sources :

Example 6 with MCRByteContent

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());
}
Also used : MCRByteContent(org.mycore.common.content.MCRByteContent) Test(org.junit.Test)

Example 7 with MCRByteContent

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);
}
Also used : MCRByteContent(org.mycore.common.content.MCRByteContent) Document(org.jdom2.Document)

Example 8 with MCRByteContent

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();
}
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 9 with MCRByteContent

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);
}
Also used : MCRByteArrayOutputStream(org.mycore.common.content.streams.MCRByteArrayOutputStream) MCRByteContent(org.mycore.common.content.MCRByteContent) SVNRepository(org.tmatesoft.svn.core.io.SVNRepository)

Example 10 with MCRByteContent

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);
    }
}
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)10 MCRByteArrayOutputStream (org.mycore.common.content.streams.MCRByteArrayOutputStream)5 Test (org.junit.Test)4 Document (org.jdom2.Document)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Element (org.jdom2.Element)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 SVNRepository (org.tmatesoft.svn.core.io.SVNRepository)2 JsonElement (com.google.gson.JsonElement)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 IIOImage (javax.imageio.IIOImage)1 ImageWriter (javax.imageio.ImageWriter)1 ImageOutputStream (javax.imageio.stream.ImageOutputStream)1 StreamResult (javax.xml.transform.stream.StreamResult)1 RandomAccessContent (org.apache.commons.vfs2.RandomAccessContent)1 JDOMException (org.jdom2.JDOMException)1 MCRUsageException (org.mycore.common.MCRUsageException)1 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)1