My above code is reading TCP data and writing them in minute file under recording directory as follows:
/WSIGraphicRecord3/recordings_dir
/WSIGraphicRecord3/recordings_dir/20100512133155.ws
/WSIGraphicRecord3/recordings_dir/20100512133256.ws
/WSIGraphicRecord3/recordings_dir/20100512133357.ws
/WSIGraphicRecord3/recordings_dir/20100512133457.ws
/WSIGraphicRecord3/recordings_dir/20100512133557.ws
/WSIGraphicRecord3/recordings_dir/20100512133658.ws
/WSIGraphicRecord3/recordings_dir/20100512133800.ws
/WSIGraphicRecord3/recordings_dir/20100512133900.ws
/WSIGraphicRecord3/recordings_dir/20100512134001.ws
/WSIGraphicRecord3/recordings_dir/20100512134101.ws
/WSIGraphicRecord3/recordings_dir/20100512134202.ws
/WSIGraphicRecord3/recordings_dir/20100512134302.ws
/WSIGraphicRecord3/recordings_dir/20100512134403.ws
/WSIGraphicRecord3/recordings_dir/20100512134503.ws
/WSIGraphicRecord3/recordings_dir/20100512134603.ws
Now my question is how to playback these files with same speed?
I am able to record tcp data but don't know how to playback. If someone can help
will be greatly appreciated.
Here is my Record shipped:
package WSI;
import java.net.*; // for Socket
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.*; // for IOException and [File]Input/OutputStream
/*import java.util.*;
import javax.swing.*;
import javax.swing.Timer;*/
public class WSIGraphicRecord {
//private String file;
public static final int BUFSIZE = 1024; // Size of read buffer
//byte[] fileBArray = new byte[(int)file.length()];
private static final long MAX_RECORD_DURATION = 60*1000L;
private long startTime = 0;
// private long stopTime = 0;
private boolean running = false;
public void start() {
this.setStartTime(System.currentTimeMillis());
this.setRunning(true);
}
/* public void stop() {
this.stopTime = System.currentTimeMillis();
this.setRunning(false);
}*/
public static void main(String[] args) throws IOException {
WSIGraphicRecord rc = new WSIGraphicRecord();
if (args.length != 3) // Test for correct # of args
throw new IllegalArgumentException("Parameter(s): <Server> <Port>");
String server = args[0]; // Server name or IP address
int port = Integer.parseInt(args[1]); // Server port
// String filename = "WSI"; // File to read data from
int file_counter = 1;
long timeToFinish;
String dirName = args[2];
// Open input and output file (named input.gz)
// FileInputStream fileIn = new FileInputStream(filename);
//FileOutputStream fileOut = new FileOutputStream(filename + "-" + file_counter + ".ws");
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
String formattedDate = formatter.format(new Date());
FileOutputStream fileOut = new FileOutputStream( dirName+File.separator+formattedDate+".ws");
// Create socket connected to server on specified port
Socket sock = new Socket(server, port);
// Receive compressed byte stream from server
InputStream sockIn = sock.getInputStream();
int bytesRead; // Number of bytes read
byte[] buffer = new byte[BUFSIZE]; // Byte buffer
rc.start();
timeToFinish = MAX_RECORD_DURATION + rc.startTime ;
while ((bytesRead = sockIn.read(buffer)) != -1) {
rc.addFlag(fileOut);
fileOut.write((""+bytesRead).getBytes());
fileOut.write(buffer, 0, bytesRead);
// System.out.println(BytesUtils.getPrettyPrint(buffer));
System.out.print("R"); // Recording progress indicator
if ( System.currentTimeMillis() >= timeToFinish ){
fileOut.close();
file_counter++;
System.out.println("");
System.out.println("Time to make new file.....");
//fileOut = new FileOutputStream(filename+"-"+file_counter + ".ws");
formattedDate = formatter.format(new Date());
fileOut = new FileOutputStream(dirName+ File.separator+formattedDate+".ws");
/*
* add timestamp
*/
rc.start();
timeToFinish = MAX_RECORD_DURATION + rc.startTime ;
}
}
System.out.println(); // End progress indicator line
sock.close(); // Close the socket and its streams
// fileIn.close(); // Close file streams
fileOut.close();
}
/**
* @param startTime the startTime to set
*/
public void setStartTime(long startTime) {
this.startTime = startTime;
}
/**
* @return the startTime
*/
public long getStartTime() {
return startTime;
}
/**
* @param running the running to set
*/
public void setRunning(boolean running) {
this.running = running;
}
/**
* @return the running
*/
public boolean isRunning() {
return running;
}
public void addFlag(FileOutputStream fileOut) throws IOException {
String delimiter = "**********";
fileOut.write(delimiter.getBytes());
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
String formattedDate = formatter.format(new Date());
fileOut.write(formattedDate.getBytes());
}
}