use of org.mycore.common.content.MCRByteContent in project mycore by MyCoRe-Org.
the class MCRXMLMetadataManagerTest method retrieve.
@Test
public void retrieve() throws JDOMException, IOException, SAXException {
assertEquals("Stored document ID do not match:", MyCoRe_document_00000001.id.toString(), SAX_BUILDER.build(new ByteArrayInputStream(MyCoRe_document_00000001.blob)).getRootElement().getAttributeValue("id"));
getStore().create(MyCoRe_document_00000001.id, new MCRByteContent(MyCoRe_document_00000001.blob, MCR_document_00000001.lastModified.getTime()), MyCoRe_document_00000001.lastModified);
MCRVersionedMetadata data = getStore().getVersionedMetaData(MyCoRe_document_00000001.id);
assertFalse(data.isDeleted());
assertFalse(data.isDeletedInRepository());
Document doc = getStore().retrieveXML(MyCoRe_document_00000001.id);
assertEquals("Stored document ID do not match:", MyCoRe_document_00000001.id.toString(), doc.getRootElement().getAttributeValue("id"));
try {
doc = getStore().retrieveXML(MCR_document_00000001.id);
if (doc != null) {
fail("Requested " + MCR_document_00000001.id + ", retrieved wrong document:\n" + new XMLOutputter(Format.getPrettyFormat()).outputString(doc));
}
} catch (Exception e) {
// this is ok
}
}
use of org.mycore.common.content.MCRByteContent in project mycore by MyCoRe-Org.
the class MCRFileStoreTest method basicFunctionality.
@Test
public void basicFunctionality() throws Exception {
Date first = new Date();
synchronized (this) {
wait(1000);
}
MCRFileCollection col = getStore().create();
assertNotNull(col);
assertTrue(col.getID() > 0);
Date created = col.getLastModified();
assertFalse(first.after(created));
bzzz();
MCRFile build = col.createFile("build.xml");
assertNotNull(build);
Date modified = col.getLastModified();
assertTrue(modified.after(created));
assertEquals(1, col.getNumChildren());
assertEquals(1, col.getChildren().size());
assertEquals(0, build.getSize());
assertTrue(created.before(build.getLastModified()));
build.setContent(new MCRJDOMContent(new Element("project")));
assertTrue(build.getSize() > 0);
assertNotNull(build.getContent().asByteArray());
bzzz();
MCRDirectory dir = col.createDir("documentation");
assertEquals(2, col.getNumChildren());
assertTrue(modified.before(col.getLastModified()));
byte[] content = "Hello World!".getBytes("UTF-8");
dir.createFile("readme.txt").setContent(new MCRByteContent(content, System.currentTimeMillis()));
MCRFile child = (MCRFile) dir.getChild("readme.txt");
assertNotNull(child);
assertEquals(content.length, child.getSize());
}
use of org.mycore.common.content.MCRByteContent in project mycore by MyCoRe-Org.
the class MCRFileTest method randomAccessContent.
@Test
public void randomAccessContent() throws Exception {
MCRFile file = col.createFile("foo.txt");
byte[] content = "Hello World".getBytes("UTF-8");
file.setContent(new MCRByteContent(content, System.currentTimeMillis()));
RandomAccessContent rac = file.getRandomAccessContent();
rac.skipBytes(6);
InputStream in = rac.getInputStream();
char c = (char) in.read();
assertEquals('W', c);
in.close();
rac.close();
}
use of org.mycore.common.content.MCRByteContent 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.MCRByteContent 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;
}
}
Aggregations