|
- package net.hoo2.auth.vmodem;
-
- import java.io.*;
-
- class Image {
- static final int IMAGE_BUFFER_SIZE = 256*1024;
- static final byte[] IMAGE_BEGIN = {(byte)0xFF, (byte)0xD8};
- static final byte[] IMAGE_END = {(byte)0xFF, (byte)0xD9};
-
- private Com com_;
- private Log log_;
- private Transaction transaction_;
- private String filename_;
- private int items_;
- private byte[] code_;
-
- Image (Com com, Log log, byte[] code, String filename, int items) {
- com_ = com;
- log_ = log;
- transaction_= new Transaction(null, new byte[IMAGE_BUFFER_SIZE]);
- filename_ = filename;
- items_ = items;
- code_ = code;
- }
-
- void code (byte[] code) { code_ = code; }
-
- void caption (byte[] code) {
- String line;
-
- line = "Running video decoder with: " + new String(code);
- log_.write(line, true);
-
- transaction_ = com_.request (transaction_, null, null, null, false);
- line = new String(transaction_.getResponse());
- log_.out(line);
- }
-
- void run () {
- String file, line;
- BufferedOutputStream ostream;
-
- for (int i =1 ; i<= items_ ; ++i) {
- if (items_>1)
- file = filename_ + "_" + i + ".jpg";
- else
- file = filename_ + ".jpg";
- line = new String(code_) + ": ";
- log_.write(line);
- transaction_ = com_.request(transaction_, code_, IMAGE_BEGIN, IMAGE_END, true);
- line = "File= " + file
- + " Tr= " + (transaction_.arrival - transaction_.departure) + " [msec]"
- + " Tt= " + (System.currentTimeMillis() - transaction_.departure) + " [msec]";
- log_.write(line);
- try {
- ostream = new BufferedOutputStream(new FileOutputStream(file));
- ostream.write(transaction_.response);
- ostream.flush();
- ostream.close();
- }
- catch (Exception exp) {
- System.err.println ("Error creating " + file + exp.getMessage());
- return;
- }
- }
- }
- }
|