List of usage examples for org.apache.commons.vfs2 RandomAccessContent close
void close() throws IOException;
From source file:org.freedesktop.mime.MagicEntry.java
public boolean match(FileObject file) throws IOException { RandomAccessContent s = file.getContent().getRandomAccessContent(RandomAccessMode.READ); try {//from ww w .j a v a 2 s . c o m for (Pattern p : this) { byte[] val = p.getValue(); byte[] mask = p.getMask(); // Read in portion of file ByteBuffer buf = ByteBuffer.allocate(p.getRangeLength() + val.length); s.seek(p.getOffset()); byte[] bufArr = buf.array(); s.readFully(bufArr); int valIdx = 0; for (int i = 0; i < bufArr.length; i++) { if ((bufArr[i] & mask[valIdx]) == (val[valIdx] & mask[valIdx])) { valIdx++; if (valIdx == val.length) { return true; } } else { valIdx = 0; } } } } finally { s.close(); } return false; }
From source file:org.mycore.datamodel.ifs2.MCRFileTest.java
@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);//from w w w .j a va 2s.com InputStream in = rac.getInputStream(); char c = (char) in.read(); assertEquals('W', c); in.close(); rac.close(); }