import java.lang.*; import java.net.*; import java.io.*; import java.awt.*; public class extractor { final static int END = 9999999; public static void main(String argv[]) { int from, to; boolean fail = false; if (argv.length < 3 || argv.length > 4) { System.err. println("Syntax: extractor []"); System.exit(1); } from = 0; try { from = Integer.parseInt(argv[2]); } catch (NumberFormatException ex) { fail = true; } if (fail || from < 0) { System.err.println("Bad argument 3. Should be a positive integer."); System.exit(1); } to = END; if (argv.length > 3) try { to = Integer.parseInt(argv[3]); } catch (NumberFormatException ex) { fail = true; } if (fail || to <= from) { System.err.println("Bad argument 4. Should be a positive integer."); System.exit(1); } NetrekGame game = new NetrekGame(); game.disable(); RandomAccessFile infile = null; try { infile = new RandomAccessFile(argv[0], "r"); } catch (IOException ex) { System.err.println("Cannot open file " + argv[0]); System.exit(1); } DataOutput outdata = null; try { outdata = new DataOutputStream(new FileOutputStream(argv[1])); } catch (IOException ex) { System.err.println("Cannot create file " + argv[1]); System.exit(1); } long start = 0, end = 0; int packet = 0; boolean ok = true; while (packet < from && ok) { ok = game.step(infile); packet++; } if (!ok) { System.err.println("Recording ends before packet " + from); System.exit(1); } System.err.println("Found beginning..."); try { start = infile.getFilePointer(); } catch (IOException ex) { System.err.println("Ooops... cannot find first file pos..."); System.exit(1); } System.out.println(start); if (start > 0) try { game.DumpStateInit(outdata); game.DumpState(outdata); } catch (IOException ex) { System.err.println("Ooops... cannot dump inital state..."); System.exit(1); } if (to == END) try end = infile.length(); catch (IOException ex) { } else { while (packet < to && ok) { ok = game.step(infile); packet++; } try { end = infile.getFilePointer(); } catch (IOException ex) { System.err.println("Ooops... cannot find second file pos..."); System.exit(1); } System.err.println("Found end..."); } System.out.println(end); try { infile.seek(start); byte buf[] = new byte[(int) (end - start)]; infile.readFully(buf); outdata.write(buf, 0, buf.length); } catch (IOException ex) { System.err.println("Ooops... could not perform extraction..."); System.exit(1); } System.err.println("Done..."); System.exit(0); } }