/*
Returns how much of the file has been processed in terms of bytes

@return progress percentage

@throws java.io.IOException in case of errors reading from the filestream provided by Hadoop
323433
@Override
	public  float getProgress() throws IOException {
	if (start == end) {
	      return 0.0f;
	    } else {
	      return Math.min(1.0f, (getFilePosition() - start) / (float)(end - start));
	    }
	}
1265505
def progress(byte, total, extra=""):
    
    if total == 0:
        progresstr = "Downloaded %dkB bytes" % (byte >> 10)
        progress_stream.write(progresstr + '\r')
        return
    progressbar(total, byte, extra)
1143151
@Override
    public float getProgress() throws IOException, InterruptedException
    {
        if (start == end) {
            return 0.0f;
        }
        else {
            return Math.min(1.0f, (pos - start) / (float) (end - start));
        }
    }
546234
@Override
    public long size() {
        if (this.isDirectory()) {
            return -1L;
        }

        final Asset asset = this.getArchive().get(this.path.toString()).getAsset();
        final InputStream stream = asset.openStream();
        int totalRead = 0;
        final byte[] buffer = new byte[1024 * 4];
        int read = 0;
        try {
            while ((read = stream.read(buffer, 0, buffer.length)) != -1) {
                totalRead += read;
            }
        } catch (final IOException ioe) {
            throw new RuntimeException(ioe);
        }

        return totalRead;
    }
214826
private synchronized float getInternal() {
    int phaseCount = phases.size();
    if (phaseCount != 0) {
      float subProgress =
        currentPhase < phaseCount ? phase().getInternal() : 0.0f;
      return progressPerPhase*(currentPhase + subProgress);
    } else {
      return progress;
    }
  }
912858
@Override public float getProgress() {
		if (length == 0)
			return 1;

		if (!isBGZF)
			return (float)(in.getPosition() - fileStart) / length;

		try {
			if (in.peek() == -1)
				return 1;
		} catch (IOException e) {
			return 1;
		}

		// Add 1 to the denominator to make sure that we never report 1 here.
		return (float)((bci.getFilePointer() >>> 16) - fileStart) / (length + 1);
	}
422133
public int read() throws IOException {
    while (true) {
      lockR.lock();
      try {
        if (availableCount.get() > 0) {
          // as long as there is available data
          // serve it even if closed
          int b = bytes[readCursor] & 0xFF;
          incReadCursor(1);
          availableCount.decrementAndGet();
          totalRead++;
          return b;
        } else if (closed){
          // when no bytes are left and buffer is closed
          // return -1
          return -1;
        }
      } finally {
        lockR.unlock();
      }
      sleep(1);
    }
  }
1009141
def get_progress(self):
        
        pos = self.reader.reader.tell()
        return min((pos - self.region_start) /
                   float(self.region_end - self.region_start),
                   1.0)
887442
public int read() throws IOException {
    if (totalRead >= totalExpected) {
      return -1;
    }

    int result = in.read();
    if (result != -1) {
      totalRead++;
    }
    return result;
  }
809800
private int read() {
        int curByte = 0;
        try {
            curByte = rawData.get() & 0xFF;
        } catch (Exception e) {
            header.status = GifDecoder.STATUS_FORMAT_ERROR;
        }
        return curByte;
    }
857402
public float getProgress()
            throws IOException {
        if (!_rows.hasNext()) {
            return 1;
        } else if (_rowsRead < _approximateSize) {
            return (float) _rowsRead / _approximateSize;
        } else {
            // We've already read the expected number of rows.
            return ((float) (_approximateSize - 1) + 0.5f) / _approximateSize;
        }
    }
956410
public double getAverage() {
        readLock.lock();
        try {
            // any values at all, needed to avoid a DivideByZero exception
            if (this.values.size() <= 0) {
                return 0;
            }
            return ((double)this.total / (double)this.values.size());
        } finally {
            readLock.unlock();
        }
    }
522204
public static function progress()
    {
        static $filesize = null;

        $args           = func_get_args();
        $isCurlResource = is_resource($args[0]) && get_resource_type($args[0]) === 'curl';

        $notification_code = !$isCurlResource ? $args[0] : false;
        $bytes_transferred = $isCurlResource ? $args[2] : $args[4];

        if ($isCurlResource) {
            $filesize = $args[1];
        } elseif ($notification_code == STREAM_NOTIFY_FILE_SIZE_IS) {
            $filesize = $args[5];
        }

        if ($bytes_transferred > 0) {
            if ($notification_code == STREAM_NOTIFY_PROGRESS | STREAM_NOTIFY_COMPLETED || $isCurlResource) {

                $progress = [
                    'code'        => $notification_code,
                    'filesize'    => $filesize,
                    'transferred' => $bytes_transferred,
                    'percent'     => $filesize <= 0 ? '-' : round(($bytes_transferred * 100) / $filesize, 1)
                ];

                if (self::$callback !== null) {
                    call_user_func(self::$callback, $progress);
                }
            }
        }
    }
1193386
def read_bytes(self):
		
		global exit_flag

		for self.i in range(0, self.length) :
			self.bytes[self.i] = i_max[self.i]
			self.maxbytes[self.i] = total_chunks[self.i]
			self.progress[self.i]["maximum"] = total_chunks[self.i]
			self.progress[self.i]["value"] = self.bytes[self.i]
			self.str[self.i].set(file_name[self.i]+ "       " + str(self.bytes[self.i]) 
								  + "KB / " + str(int(self.maxbytes[self.i] + 1)) + " KB")

		if exit_flag == self.length:
			exit_flag = 0
			self.frame.destroy()
		else:
			self.frame.after(10, self.read_bytes)
861361
public byte readByte() throws IOException {

		// buffer depleted ?
		if (head == tail) {
			head = 0;
			// Refill.
			tail = input.read(buffer, head, bufSize);
			if (tail == -1) {
				// no more data available.
				throw new IOException("No more data is available");
			}
		}

		return buffer[head++];
	}
1166290
@Override
   public double getSortProcessingRate(long currentTime) {
     long timeSpentSorting = 0;
     float progress = 0;
     Phase phase = getPhase();
     long sortFinishTime = getSortFinishTime();
     long shuffleFinishTime = getShuffleFinishTime();
     
     if (phase == Phase.SHUFFLE ) {
       return 0;
     } else if (getPhase() == Phase.SORT) {
       if (shuffleFinishTime < currentTime) {
         LOG.error("Shuffle finish time is " + shuffleFinishTime + 
             " which is < current time " + currentTime + 
             " in " + this.getTaskID());
       }
       timeSpentSorting =  currentTime - shuffleFinishTime;
       progress = getProgress() - (float)1.0/3;
       if (progress < 0) {
         LOG.error("Shuffle progress calculated to be " + progress + 
             " in task status for  " + this.getTaskID() + ".  Settings to 0");
         progress = 0;
       }
     } else if (getPhase() == Phase.REDUCE) {
       // when it is reduce phase, use 33%/(sort finish time - shuffle 
       // finish time as the progress rate. Using percentages instead of bytes
       // as it is tricky
       progress = (float)1.0/3;
       if (shuffleFinishTime <= sortFinishTime) {
         LOG.error("Shuffle finish fime is " + shuffleFinishTime + 
             " which is <= sort finish time " + sortFinishTime + 
             " in " + this.getTaskID());
         return 0;
       }
       timeSpentSorting = sortFinishTime - shuffleFinishTime;
     }
     
     sortProcessingRate = progress/timeSpentSorting; 
     return sortProcessingRate;
   }
484479
public Long getFileSizeAvg() {
        Long fileSizeAvg = 0L;
        if (items.size() != 0) {
            for (TableStat item : items) {
                if (item.getEndTime().equals(item.getStartTime())) {
                    fileSizeAvg += item.getFileSize();
                } else {
                    fileSizeAvg += item.getFileSize() * 1000
                                   / (item.getEndTime().getTime() - item.getStartTime().getTime());
                }
            }
            fileSizeAvg = fileSizeAvg / items.size();
        }
        return fileSizeAvg;
    }