Пример #1
0
 //
 // this method is blocking communocation
 public int read() throws IOException {
   try {
     int ret = -1;
     byte[] buffer = new byte[1];
     boolean first = true;
     do {
       mFile.seek(mFilePointer);
       ret = mFile.read(buffer);
       if (mBlockOn == false || first == false || ret != 0) {
         break;
       }
       first = false;
       waitForUnreadable(TIMEOUT);
     } while (true);
     if (ret > 0) {
       seek(mFilePointer + 1);
     }
     if (ret < 0) {
       mIsEOF = true;
       return -1;
     }
     if (ret == 0) {
       return -2;
     }
     return 0xFF & buffer[0];
   } catch (IOException e) {
     mIsEOF = true;
     throw e;
   }
 }
Пример #2
0
  @Override
  public int read(byte[] out, int start, int len) throws IOException {

    try {
      int ret = 0;
      boolean first = true;
      do {
        mFile.seek(mFilePointer);
        ret = mFile.read(out, start, len);
        if (mBlockOn == false || first == false || ret != 0) {
          break;
        }
        first = false;
        waitForUnreadable(TIMEOUT);
      } while (true);
      if (ret > 0) {
        mFilePointer += ret;
      }
      if (ret < 0) {
        mIsEOF = true;
      } else {
        mIsEOF = false;
      }
      return ret;
    } catch (IOException e) {
      mIsEOF = true;
      throw e;
    }
  }
Пример #3
0
 @Override
 public int waitForUnreadable(int timeout) throws IOException {
   long len = this.length();
   long fp = this.getFilePointer();
   if (0 < (len - fp)) {
     return 1;
   } else {
     return mFile.waitForUnreadable(timeout);
   }
 }
Пример #4
0
 public void close() throws IOException {
   if (mBaseFileIsClosedWhenCallClose) {
     mFile.close();
   }
 }
Пример #5
0
 public long length() throws IOException {
   return mFile.length();
 }