Code example for RandomAccessFile

Methods: read, readByte, readFully, readInt, seek, skipBytes

0
        return canHandle;
    } 
 
    @Override 
    public String rename(RandomAccessFile raf, File file) throws IOException {
        raf.seek(0);
        return readAtom(raf) + ".MOV";
    } 
 
    private String readAtom(RandomAccessFile dis) throws IOException {
        int len = dis.readInt();
        byte[] blen = new byte[4];
        dis.readFully(blen);
        String type = new String(blen);
        int atomType = getAtomType(type);
        if (atomType == ATOM_UNKNOWN) {
            dis.skipBytes(len - 8);
        } else if (atomType == ATOM_CONTAINER) {
        } else if (atomType == ATOM_LEAF) {
            if (type.equals("mvhd")) {
                dis.readByte(); // Version
                byte[] fbytes = new byte[3];
                dis.read(fbytes); // Flags
                long creationtime = (long) dis.readInt() & 0xFFFFFFFFL;
                int creationHalfTime = (int) (creationtime >> 1); // work around
                                                                  // signed 
                                                                  // integer 
                                                                  // issue 
                Calendar cal = Calendar.getInstance();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
                cal.set(1904, Calendar.JANUARY, 1, 0, 0, 0);
                cal.add(Calendar.SECOND, creationHalfTime);
                cal.add(Calendar.SECOND, creationHalfTime);
                return sdf.format(cal.getTime());
            } else { 
                dis.skipBytes(len - 8);
            } 
        } 
        return readAtom(dis);
    }