Beispiel #1
0
 @Override
 public synchronized int read() throws IOException {
   if (closed) {
     throw new IOException("Stream closed");
   }
   int result = -1;
   if (pos < fileLength) {
     if (pos > blockEnd) {
       blockSeekTo(pos);
     }
     result = blockStream.read();
     if (result >= 0) {
       pos++;
     }
   }
   if (stats != null & result >= 0) {
     stats.incrementBytesRead(1);
   }
   return result;
 }
Beispiel #2
0
 @Override
 public synchronized int read(byte buf[], int off, int len) throws IOException {
   if (closed) {
     throw new IOException("Stream closed");
   }
   if (pos < fileLength) {
     if (pos > blockEnd) {
       blockSeekTo(pos);
     }
     int realLen = Math.min(len, (int) (blockEnd - pos + 1));
     int result = blockStream.read(buf, off, realLen);
     if (result >= 0) {
       pos += result;
     }
     if (stats != null && result > 0) {
       stats.incrementBytesRead(result);
     }
     return result;
   }
   return -1;
 }