diff options
author | Constantin Kaplinsky <const@tightvnc.com> | 2008-06-19 07:51:42 +0000 |
---|---|---|
committer | Constantin Kaplinsky <const@tightvnc.com> | 2008-06-19 07:51:42 +0000 |
commit | ab0eaa24c3a964445529a75cfb15a59279300431 (patch) | |
tree | 4b34685cd646af81f408cb17e3c8d448af7d622e /java | |
parent | 7fea1c46a56368181739373787122d5607c1e91b (diff) | |
download | tigervnc-ab0eaa24c3a964445529a75cfb15a59279300431.tar.gz tigervnc-ab0eaa24c3a964445529a75cfb15a59279300431.zip |
[Refactoring] Reading an FBS data block has been separated in a new method with improved error handling.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2593 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'java')
-rw-r--r-- | java/src/com/tightvnc/rfbplayer/FbsInputStream.java | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/java/src/com/tightvnc/rfbplayer/FbsInputStream.java b/java/src/com/tightvnc/rfbplayer/FbsInputStream.java index e12c9f5a..0e6ebfa2 100644 --- a/java/src/com/tightvnc/rfbplayer/FbsInputStream.java +++ b/java/src/com/tightvnc/rfbplayer/FbsInputStream.java @@ -190,19 +190,7 @@ class FbsInputStream extends InputStream { // Just wait unless we are performing playback OR seeking. waitWhilePaused(); - bufferSize = (int)readUnsigned32(); - if (bufferSize >= 0) { - int realSize = (bufferSize + 3) & 0xFFFFFFFC; - buffer = new byte[realSize]; - readFully(buffer); - bufferPos = 0; - timeOffset = (long)(readUnsigned32() / playbackSpeed); - } - - if (bufferSize < 0 || timeOffset < 0) { - buffer = null; - bufferSize = 0; - bufferPos = 0; + if (!readDataBlock(0)) { return false; } @@ -230,6 +218,41 @@ class FbsInputStream extends InputStream { return true; } + /** + * Read FBS data block into the buffer. + * + * @param numBytesSkip specifies how many bytes should be skipped in the + * beginning of the data block. + * @return true on success, false if end of file was reached. + * @throws java.io.IOException can be thrown while reading from the + * underlying input stream, or as a result of bad FBS file data. + */ + private boolean readDataBlock(int numBytesSkip) throws IOException { + // Read byte counter, check for EOF condition. + long readResult = readUnsigned32(); + if (readResult < 0) { + return false; + } + + bufferSize = (int)readResult; + if (bufferSize >= 0) { + int alignedSize = (bufferSize + 3) & 0xFFFFFFFC; + buffer = new byte[alignedSize]; + readFully(buffer); + bufferPos = numBytesSkip; + timeOffset = (long)(readUnsigned32() / playbackSpeed); + } + + if (bufferSize < 0 || timeOffset < 0 || bufferPos >= bufferSize) { + buffer = null; + bufferSize = 0; + bufferPos = 0; + throw new IOException("Invalid FBS file data"); + } + + return true; + } + // // In paused mode, wait for external notification on this object. // |