public synchronized DatasetObject getObject(int id) throws Exception{

       if(offsetFile==null || databaseFile==null)
            openFiles(indexDirectory);

      //With persistent offsets
       long position=id*8;
       long l=offsetFile.length();
       if(position>=offsetFile.length())
           throw new Exception("Object with internal identifier "+id+" does not exist!");

        offsetFile.seek(position);

        long startOffset=offsetFile.readLong();
        long endOffset;
        if(position+8!=offsetFile.length())
            endOffset=offsetFile.readLong();
        else
            endOffset=databaseFile.length();/**/

       //With in memory offsets;
/*       if(offsets==null){
           offsets=new long[(int)(offsetFile.length()/8)];
           for(int i=0;i<offsetFile.length();i+=8)
               offsets[i/8]=offsetFile.readLong();
       }
       if(id>=offsets.length)
           throw new Exception("Object with internal identifier "+id+" does not exist!");

        long startOffset=offsets[id];
        long endOffset;
        if(id+1!=offsets.length)
            endOffset=offsets[id+1];
        else
            endOffset=databaseFile.length(); /**/

        //With persistent database
        //System.out.println(startOffset+" "+endOffset);
        byte[] buff=new byte[(int)(endOffset-startOffset)];
        databaseFile.seek(startOffset);
        databaseFile.read(buff);/**/


        ByteArrayInputStream bais=new ByteArrayInputStream(buff);
        GZIPInputStream gz=new GZIPInputStream(bais);
        ObjectInputStream baiso=new ObjectInputStream(gz);
        DatasetObject obj=(DatasetObject)baiso.readObject();

        return obj;

    }