List of usage examples for org.apache.commons.vfs2 RandomAccessContent readFully
void readFully(byte b[]) 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 {/* w w w .j a v a 2 s . c om*/ 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; }