FbsConnection(String fbsLocation, String indexLocationPrefix, Applet applet)
throws MalformedURLException {
+ // Construct URLs from strings.
URL base = null;
if (applet != null) {
base = applet.getCodeBase();
}
fbsURL = new URL(base, fbsLocation);
- fbiURL = null;
- fbkURL = null;
+ fbiURL = fbkURL = null;
if (indexLocationPrefix != null) {
- fbiURL = new URL(base, indexLocationPrefix + ".fbi");
- fbkURL = new URL(base, indexLocationPrefix + ".fbk");
+ try {
+ fbiURL = new URL(base, indexLocationPrefix + ".fbi");
+ fbkURL = new URL(base, indexLocationPrefix + ".fbk");
+ } catch (MalformedURLException e) {
+ fbiURL = fbkURL = null;
+ }
}
+
+ // Try to load the .fbi index file.
+ loadIndex();
}
FbsInputStream connect(long timeOffset) throws IOException {
return fbs;
}
+ private void loadIndex() {
+ // Loading .fbi makes sense only if both .fbi and .fbk files are available.
+ if (fbiURL != null && fbkURL != null) {
+ try {
+ // Connect.
+ URLConnection connection = fbiURL.openConnection();
+ connection.connect();
+ DataInputStream is = new DataInputStream(connection.getInputStream());
+
+ // Check file signature.
+ byte[] b = new byte[12];
+ is.readFully(b);
+ if (b[0] != 'F' || b[1] != 'B' || b[2] != 'I' || b[3] != ' ' ||
+ b[4] != '0' || b[5] != '0' || b[6] != '1' || b[7] != '.' ||
+ b[8] < '0' || b[8] > '9' || b[9] < '0' || b[9] > '9' ||
+ b[10] < '0' || b[10] > '9' || b[11] != '\n') {
+ System.err.println("Warning: bad .fbi file data, not using index");
+ fbiURL = null;
+ }
+
+ // Load index from the .fbi file.
+ // FIXME: Real loading is not implemented yet.
+ int numRecords = 0;
+ try {
+ while (true) {
+ is.readInt();
+ is.readInt();
+ is.readInt();
+ is.readInt();
+ is.readInt();
+ numRecords++;
+ }
+ } catch (EOFException e) {
+ } catch (IOException e) {
+ System.err.println("Warning: Index data may be incomplete");
+ }
+ System.err.println("Loaded index data, " + numRecords + " records");
+ } catch (IOException e) {
+ System.err.println("Warning: I/O exception while loading index: " + e);
+ System.err.println("Warning: failed to load .fbi, not using index");
+ }
+ }
+ }
+
}
VncCanvas vc;
String sessionURL;
+ String idxPrefix;
long initialTimeOffset;
double playbackSpeed;
boolean autoPlay;
try {
java.applet.Applet applet = (inAnApplet) ? this : null;
- FbsConnection conn = new FbsConnection(sessionURL, null, applet);
+ FbsConnection conn = new FbsConnection(sessionURL, idxPrefix, applet);
fbs = conn.connect(initialTimeOffset);
rfb = new RfbProto(fbs);
public void readParameters() {
sessionURL = readParameter("URL", true);
+ idxPrefix = readParameter("Index", false);
initialTimeOffset = readLongParameter("Position", 0);
if (initialTimeOffset < 0)