]> source.dussan.org Git - tigervnc.git/commitdiff
[Refactoring] Added a separate function to connect to a byte range via HTTP using...
authorConstantin Kaplinsky <const@tightvnc.com>
Sat, 21 Jun 2008 11:41:42 +0000 (11:41 +0000)
committerConstantin Kaplinsky <const@tightvnc.com>
Sat, 21 Jun 2008 11:41:42 +0000 (11:41 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2610 3789f03b-4d11-0410-bbf8-ca57d06f2519

java/src/com/tightvnc/rfbplayer/FbsConnection.java

index 20b0154435c280f001a3ac71d52f81c7e7470b16..d952f4fef168c6119c9b420eb0bc27923f040d68 100644 (file)
@@ -199,20 +199,15 @@ public class FbsConnection {
     }
 
     // Prepare URLConnection to the right part of the .fbk file.
-    URLConnection fbkConn = fbkURL.openConnection();
-    long firstByteOffset = entryPoint.key_fpos;
-    long lastByteOffset = entryPoint.key_fpos + entryPoint.key_size - 1;
-    String rangeSpec = "bytes=" + firstByteOffset + "-" + lastByteOffset;
-    System.err.println("Range: " + rangeSpec);
-    fbkConn.setRequestProperty("Range", rangeSpec);
-    fbkConn.connect();
-    DataInputStream is = new DataInputStream(fbkConn.getInputStream());
+    InputStream is =
+        openByteRange(fbkURL, entryPoint.key_fpos, entryPoint.key_size);
+    DataInputStream dis = new DataInputStream(is);
 
     // Load keyframe data from the .fbk file.
-    int keyDataSize = is.readInt();
+    int keyDataSize = dis.readInt();
     byte[] keyData = new byte[keyDataSize];
-    is.readFully(keyData);
-    is.close();
+    dis.readFully(keyData);
+    dis.close();
 
     // Open the FBS stream.
     URLConnection fbsConn = fbsURL.openConnection();
@@ -221,4 +216,15 @@ public class FbsConnection {
                               keyData, entryPoint.fbs_skip);
   }
 
+  private InputStream openByteRange(URL url, long offset, long length)
+      throws IOException {
+    URLConnection conn = url.openConnection();
+    long lastByteOffset = offset + length - 1;
+    String rangeSpec = "bytes=" + offset + "-" + lastByteOffset;
+    System.err.println("Range: " + rangeSpec);
+    conn.setRequestProperty("Range", rangeSpec);
+    conn.connect();
+    return conn.getInputStream();
+  }
+
 }