Search in sources :

Example 1 with RandomAccessContent

use of org.apache.commons.vfs2.RandomAccessContent 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();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MCRByteContent(org.mycore.common.content.MCRByteContent) RandomAccessContent(org.apache.commons.vfs2.RandomAccessContent) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 RandomAccessContent (org.apache.commons.vfs2.RandomAccessContent)1 Test (org.junit.Test)1 MCRByteContent (org.mycore.common.content.MCRByteContent)1