private boolean openSeekable() {
   final Info initialInfo = new Info();
   final Comment initialComment = new Comment();
   this.m_chunkSize = Math.min(8500, (int) length(this.m_vorbisStream));
   final Page page = new Page();
   final int[] testSerialno = {0};
   final int ret = this.fetchHeaders(initialInfo, initialComment, testSerialno, null);
   final int serialno = testSerialno[0];
   final int dataOffset = (int) this.m_offset;
   this.m_oggStreamState.clear();
   if (ret < 0) {
     return false;
   }
   seek(this.m_vorbisStream, 0L, 1);
   this.m_offset = tell(this.m_vorbisStream);
   final long end = this.getPreviousPage(page);
   if (page.serialno() != serialno) {
     if (this.bisectForwardSerialno(0L, 0L, end + 1L, serialno, 0) < 0) {
       return false;
     }
   } else if (this.bisectForwardSerialno(0L, end, end + 1L, serialno, 0) < 0) {
     return false;
   }
   this.prefetchAllHeaders(initialInfo, initialComment, dataOffset);
   this.rawSeek(this.m_dataOffsets[0]);
   return true;
 }
 private int processPacket(final boolean readPage) {
   while (true) {
     if (this.m_decodeReady) {
       final int result = this.m_oggStreamState.packetout(this.m_oggPacket);
       if (result > 0) {
         long granulepos = this.m_oggPacket.granulepos;
         if (this.m_block.synthesis(this.m_oggPacket) == 0) {
           this.m_dspState.synthesis_blockin(this.m_block);
           if (granulepos != -1L) {
             final int link = this.m_vorbisStream.isSeekable() ? this.m_currentLink : 0;
             final int samples = this.m_dspState.synthesis_pcmout(null, null);
             granulepos = Math.max(0L, granulepos - samples);
             for (int i = 0; i < link; ++i) {
               granulepos += this.m_pcmLengths[i];
             }
             this.m_pcmOffset = granulepos;
           }
           return 1;
         }
       }
     }
     if (!readPage) {
       return 0;
     }
     if (this.getNextPage(this.m_oggPage, -1L) < 0) {
       return 0;
     }
     if (this.m_decodeReady && this.m_currentSerialno != this.m_oggPage.serialno()) {
       this.decodeClear();
     }
     if (!this.m_decodeReady) {
       if (this.m_vorbisStream.isSeekable()) {
         this.m_currentSerialno = this.m_oggPage.serialno();
         int j;
         for (j = 0; j < this.m_links && this.m_serialnos[j] != this.m_currentSerialno; ++j) {}
         if (j == this.m_links) {
           return -1;
         }
         this.m_currentLink = j;
         this.m_oggStreamState.init(this.m_currentSerialno);
         this.m_oggStreamState.reset();
       } else {
         final int[] serialnos = {0};
         final int ret =
             this.fetchHeaders(this.m_info[0], this.m_comments[0], serialnos, this.m_oggPage);
         this.m_currentSerialno = serialnos[0];
         if (ret != 0) {
           return ret;
         }
         ++this.m_currentLink;
       }
       this.makeDecodeReady();
     }
     this.m_oggStreamState.pagein(this.m_oggPage);
   }
 }
  /**
   * Builds a SgrScoreCalculator object
   *
   * @param data - name of file containing sgr data
   * @param winSize - size of display window
   * @throws IOException - if the file cannot be accessed
   */
  public SgrScoreCalculator(String data, int winSize, CurationSet curation) throws IOException {
    super(winSize);
    BufferedReader br = new BufferedReader(new FileReader(data));
    String line;
    double minAbsScore = Double.POSITIVE_INFINITY;
    Set<String> unmatchedIds = new HashSet<String>();
    while ((line = br.readLine()) != null) {
      String[] tokens = line.split("\t");
      String refId = curation.getRefSequence().getName();
      if (!tokens[0].equals(refId)) {
        if (!unmatchedIds.contains(tokens[0])) {
          logger.warn(
              "Score id "
                  + tokens[0]
                  + " does not match main sequence id "
                  + refId
                  + ". Skipping score.");
          unmatchedIds.add(tokens[0]);
        }
        continue;
      }
      Double score = new Double(Double.parseDouble(tokens[2]));
      // chuck out scores outside of the given range
      int pos = Integer.parseInt(tokens[1]);
      if (pos >= curation.getLow() && pos <= curation.getHigh()) {
        scoreMap.put(pos, score);
      }

      if (Math.abs(score) < minAbsScore) {
        minAbsScore = Math.abs(score);
      }
      if (score.doubleValue() < minScore) {
        minScore = score;
      }
      if (score.doubleValue() > maxScore) {
        maxScore = score;
      }
    }
    while (minAbsScore * factor < 1) {
      factor *= 10;
    }
  }
 @Override
 public int getVisibilityData(
     final int x, final int y, final CellVisibilityData[] cellVisibilityData, final int index) {
   assert this.checkGetVisibilityData(x, y, cellVisibilityData);
   int numZ = 1;
   final CellVisibilityData data = cellVisibilityData[index];
   data.m_x = x;
   data.m_y = y;
   data.m_z = this.getZ(x, y);
   data.m_height = (byte) Math.max(0, data.m_z);
   data.m_hollow = false;
   if (this.m_attachedBuilding.length != 0) {
     for (final AbstractBuildingStruct building : this.m_attachedBuilding) {
       final int result = building.getVisibilityData(x, y, cellVisibilityData, index + numZ);
       if (result != -1) {
         numZ += mergeSameAltitude(cellVisibilityData, index, index + numZ, result);
       }
     }
   }
   return numZ;
 }
 @Override
 public final int getPathData(
     final int x, final int y, final CellPathData[] cellPathData, final int index) {
   assert this.checkGetPathData(x, y, cellPathData);
   int numZ = 1;
   final CellPathData data = cellPathData[index];
   data.m_x = x;
   data.m_y = y;
   data.m_z = this.getZ(x, y);
   data.m_height = (byte) Math.max(0, data.m_z);
   data.m_cost = (byte) (super.isCellBlocked(x, y) ? -1 : 7);
   data.m_hollow = false;
   data.m_murfinInfo = (byte) this.getMurFinInfo(x, y);
   data.m_miscProperties = (byte) this.getMiscProperties(x, y);
   if (this.m_attachedBuilding.length != 0) {
     for (final AbstractBuildingStruct building : this.m_attachedBuilding) {
       final int result = building.getPathData(x, y, cellPathData, index + numZ);
       if (result != -1) {
         numZ += mergeSameAltitude(cellPathData, index, index + numZ, result);
       }
     }
   }
   return numZ;
 }
 @Override
 public int read(final ByteBuffer bb, final int pos) {
   this.m_isReset = false;
   bb.position(pos);
   while (bb.remaining() > 0) {
     boolean needToProcessPacket = true;
     if (this.m_decodeReady) {
       final Info info = this.m_info[this.m_currentLink];
       final int totalSamples = this.m_dspState.synthesis_pcmout(this.m_pcmf_buffer, this._index);
       final float[][] pcm = this.m_pcmf_buffer[0];
       if (totalSamples > 0) {
         final int channelsCount = info.channelsCount;
         final int bytesPerSample = channelsCount * 2;
         int samples = Math.min(totalSamples, bb.remaining() / bytesPerSample);
         samples = Math.min(samples, 8192 / bytesPerSample);
         needToProcessPacket = (samples == totalSamples);
         for (int i = 0; i < channelsCount; ++i) {
           int ptr = i * 2;
           final int mono = this._index[i];
           for (int j = 0; j < samples; ++j) {
             int val = (int) (pcm[i][mono + j] * 32767.0f);
             if (val > 32767) {
               val = 32767;
             }
             if (val < -32768) {
               val = -32768;
             }
             if (val < 0) {
               val |= 0x8000;
             }
             if (JOrbisStream.m_bigEndian) {
               this.m_conversionBuffer[ptr] = (byte) (val >>> 8 & 0xFF);
               this.m_conversionBuffer[ptr + 1] = (byte) (val & 0xFF);
             } else {
               this.m_conversionBuffer[ptr] = (byte) (val & 0xFF);
               this.m_conversionBuffer[ptr + 1] = (byte) (val >>> 8 & 0xFF);
             }
             ptr += 2 * channelsCount;
           }
         }
         final int writtenBytesLength = samples * bytesPerSample;
         bb.put(this.m_conversionBuffer, 0, writtenBytesLength);
         this.m_dspState.synthesis_read(samples);
         this.m_pcmOffset += samples;
       }
     }
     if (needToProcessPacket) {
       switch (this.processPacket(true)) {
         case 0:
           {
             return -(bb.position() - pos);
           }
         case -1:
           {
             return -(bb.position() - pos);
           }
         default:
           {
             continue;
           }
       }
     }
   }
   return bb.position() - pos;
 }
  // public List getUserStoryList(String sessionId,String iterationId,ServletOutputStream out) {
  public List getUserStoryList(String sessionId, String iterationId, PrintWriter out) {

    List<Map> list = new ArrayList<Map>();

    statusMap.put(sessionId, "0");

    try {

      String apiURL =
          rallyApiHost
              + "/hierarchicalrequirement?"
              + "query=(Iteration%20=%20"
              + rallyApiHost
              + "/iteration/"
              + iterationId
              + ")&fetch=true&start=1&pagesize=100";

      log.info("getUserStoryList apiURL=" + apiURL);

      String responseXML = getRallyXML(apiURL);

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Object");
      List xlist = xpath.selectNodes(root);

      int totalSteps = xlist.size() + 1;
      int currentStep = 0;

      List taskRefLink = new ArrayList();

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {
        double totalTimeSpent = 0.0D;

        Map map = new HashMap();

        Element item = (Element) iter.next();
        String objId = item.getChildText("ObjectID");
        String name = item.getChildText("Name");
        String planEstimate = item.getChildText("PlanEstimate");
        String formattedId = item.getChildText("FormattedID");

        String taskActualTotal = item.getChildText("TaskActualTotal");
        String taskEstimateTotal = item.getChildText("TaskEstimateTotal");
        String taskRemainingTotal = item.getChildText("TaskRemainingTotal");
        String scheduleState = item.getChildText("ScheduleState");

        Element ownerElement = item.getChild("Owner");

        String owner = "";
        String ownerRef = "";

        if (ownerElement != null) {
          owner = ownerElement.getAttributeValue("refObjectName");
        }

        Element taskElements = item.getChild("Tasks");
        // List taskElementList=taskElements.getContent();
        List taskElementList = taskElements.getChildren();

        List taskList = new ArrayList();

        log.info("taskElements.getChildren=" + taskElements);
        log.info("taskList=" + taskElementList);

        for (int i = 0; i < taskElementList.size(); i++) {
          Element taskElement = (Element) taskElementList.get(i);

          String taskRef = taskElement.getAttributeValue("ref");

          String[] objectIdArr = taskRef.split("/");
          String objectId = objectIdArr[objectIdArr.length - 1];

          log.info("objectId=" + objectId);

          // Map taskMap=getTaskMap(taskRef);
          Map taskMap = getTaskMapBatch(objectId);

          double taskTimeSpentTotal =
              Double.parseDouble((String) taskMap.get("taskTimeSpentTotal"));
          totalTimeSpent += taskTimeSpentTotal;
          taskList.add(taskMap);
        }

        map.put("type", "userstory");
        map.put("formattedId", formattedId);
        map.put("name", name);
        map.put("taskStatus", scheduleState);
        map.put("owner", owner);
        map.put("planEstimate", planEstimate);
        map.put("taskEstimateTotal", taskEstimateTotal);
        map.put("taskRemainingTotal", taskRemainingTotal);
        map.put("taskTimeSpentTotal", "" + totalTimeSpent);

        list.add(map);
        list.addAll(taskList);

        ++currentStep;
        double percentage = 100.0D * currentStep / totalSteps;
        String status = "" + Math.round(percentage);
        statusMap.put(sessionId, status);

        out.println("<script>parent.updateProcessStatus('" + status + "%')</script>" + status);
        out.flush();
        log.info("out.flush..." + status);

        // log.info("status="+status+" sessionId="+sessionId);
        // log.info("L1 statusMap="+statusMap+" "+statusMap.hashCode());

      }

      double planEstimate = 0.0D;
      double taskEstimateTotal = 0.0D;
      double taskRemainingTotal = 0.0D;
      double taskTimeSpentTotal = 0.0D;
      Map iterationMap = new HashMap();
      for (Map map : list) {
        String type = (String) map.get("type");

        String planEstimateStr = (String) map.get("planEstimate");

        log.info("planEstimateStr=" + planEstimateStr);

        if ("userstory".equals(type)) {

          if (planEstimateStr != null) {
            planEstimate += Double.parseDouble(planEstimateStr);
          }
          taskEstimateTotal += Double.parseDouble((String) map.get("taskEstimateTotal"));
          taskRemainingTotal += Double.parseDouble((String) map.get("taskRemainingTotal"));
          taskTimeSpentTotal += Double.parseDouble((String) map.get("taskTimeSpentTotal"));
        }
      }

      apiURL = rallyApiHost + "/iteration/" + iterationId + "?fetch=true";
      log.info("iteration apiURL=" + apiURL);
      responseXML = getRallyXML(apiURL);

      bSAX = new org.jdom.input.SAXBuilder();
      doc = bSAX.build(new StringReader(responseXML));
      root = doc.getRootElement();

      xpath = XPath.newInstance("//Iteration");
      xlist = xpath.selectNodes(root);

      String projName = "";
      String iterName = "";
      String iterState = "";

      iter = xlist.iterator();
      while (iter.hasNext()) {
        Element item = (Element) iter.next();

        iterName = item.getChildText("Name");
        iterState = item.getChildText("State");
        Element projElement = item.getChild("Project");
        projName = projElement.getAttributeValue("refObjectName");
      }

      iterationMap.put("type", "iteration");
      iterationMap.put("formattedId", "");
      iterationMap.put("name", projName + " - " + iterName);
      iterationMap.put("taskStatus", iterState);
      iterationMap.put("owner", "");

      iterationMap.put("planEstimate", "" + planEstimate);
      iterationMap.put("taskEstimateTotal", "" + taskEstimateTotal);
      iterationMap.put("taskRemainingTotal", "" + taskRemainingTotal);
      iterationMap.put("taskTimeSpentTotal", "" + taskTimeSpentTotal);

      list.add(0, iterationMap);

      statusMap.put(sessionId, "100");

      log.info("L2 statusMap=" + statusMap);

      log.info("L2 verify=" + getProcessStatus(sessionId));
      log.info("-----------");

      // String jsonData=JsonUtil.encodeObj(list);
      String jsonData = JSONValue.toJSONString(list);

      out.println("<script>parent.tableResult=" + jsonData + "</script>");
      out.println("<script>parent.showTableResult()</script>");

    } catch (Exception ex) {
      log.error("ERROR: ", ex);
    }

    return list;
  }