// // 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; } }
@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; } }
@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); } }
public void close() throws IOException { if (mBaseFileIsClosedWhenCallClose) { mFile.close(); } }
public long length() throws IOException { return mFile.length(); }