public synchronized void processCas(CAS aCAS) throws ResourceProcessException {
    JCas jcas;
    try {
      jcas = aCAS.getJCas();
    } catch (CASException e) {
      throw new ResourceProcessException(e);
    }

    String context=jcas.getDocumentText();
    Iterator geneIterator = jcas.getAnnotationIndex(Gene.type).iterator();
    while (geneIterator.hasNext()) {
      Gene geneAnnotation = (Gene)geneIterator.next();
      int beginOffset=0;
      int endOffset=0;
      for(int i=geneAnnotation.getSentenceStart();i<geneAnnotation.getBegin();i++){
        if(context.charAt(i)==' '){
          beginOffset++;
        }
      }
      for(int i=geneAnnotation.getSentenceStart();i<geneAnnotation.getEnd();i++){
        if(context.charAt(i)==' '){
          endOffset++;
        }
      }
      try{
        fileWriter.write(geneAnnotation.getId()+"|"
                +(geneAnnotation.getBegin()-geneAnnotation.getSentenceStart()-beginOffset)
                +" "+(geneAnnotation.getEnd()-geneAnnotation.getSentenceStart()-endOffset)+"|"
                +" "+context.substring(geneAnnotation.getBegin(), geneAnnotation.getEnd())+"\n");
        fileWriter.flush();
      } catch (IOException e) {
        throw new ResourceProcessException(e);
      }
    }
  }