I
irfanAbi
Gast
Hallo!
kann jemand mir bei diesem Java code weiter helfen.
Das Programm liest die Daten aus Ethereal (Sniffer Software) aus, rechnet die Daten und gibt sie als Text Datei aus.
Datei bis zu 2 Megabyte kann er Lesen aber wenn es zu gross wird fägt er anzu mäkern.
Das kommt bei Eclipse raus: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Es wäre sehr nett wenn jemand mir da weiter helfen würde.
So sieht das Programm aus:
[/u]
kann jemand mir bei diesem Java code weiter helfen.
Das Programm liest die Daten aus Ethereal (Sniffer Software) aus, rechnet die Daten und gibt sie als Text Datei aus.
Datei bis zu 2 Megabyte kann er Lesen aber wenn es zu gross wird fägt er anzu mäkern.
Das kommt bei Eclipse raus: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Es wäre sehr nett wenn jemand mir da weiter helfen würde.
So sieht das Programm aus:
Code:
package tk_labor;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
//
public class Converter {//deraclaration d'1 classe public de type converter
private final int NO_IDX = 0;//parametres de la classe
private final int TIMESTAMP_IDX = 1;
private final int SOURCE_IDX = 2;
private final int DEST_IDX = 3;
private final int PROTINFO_IDX = 4;
private final int CODEC_IDX = 7;
private final int SSRC_IDX = 9;
private final int SEQNO_IDX = 10;
private final int TIME_IDX = 11;
Document doc;//object de nom doc de type document qui donne acces aux methodes de la classe document
public Converter() {//constructeur qui permet d'initialiser les parametres
doc = new Document();//initialisation de doc
}
public void doConvert(String inLine) {//methode (doconvert) de type void ayant un para. inline de type String
if(inLine == null)//si inline est vide alors le prog s'arrete(return)
return;
int no;
double tStamp;
String ssrc;
inLine = inLine.trim();
String fields[] = inLine.split(",? +");//declaration et initialisation d'1 array (field) de type array
//for(int i=0; i<fields.length; i++) {//
// System.out.println("" + i + " " + fields[i]);
//}
DocRow row = new DocRow();//declaration d'1 object (row) de type docrow init. avec new docrow
if(fields.length<12)
return;
if(!fields[PROTINFO_IDX].equals("RTP"))
return;
//System.out.println(inLine);
Integer n = new Integer(fields[NO_IDX]);//procesus de transformation d'1 String en un int
no = n.intValue();
Double timeStamp1 = new Double(fields[TIMESTAMP_IDX]);
tStamp = timeStamp1.doubleValue();
row.setTStamp1(timeStamp1.doubleValue());
int idx = fields[SEQNO_IDX].indexOf("=");
String sseqno = fields[SEQNO_IDX].substring(idx + 1);
Long seqno = new Long(sseqno);
idx = fields[SSRC_IDX].indexOf("=");
ssrc = fields[SSRC_IDX].substring(idx + 1);
idx = fields[TIME_IDX].indexOf("=");
String stime = fields[TIME_IDX].substring(idx + 1);
Double time = new Double(stime);
int seqNoIndex = doc.getSeqNoIndex(seqno.longValue(), time.doubleValue());
if(seqNoIndex == -1) {
//add
row.setNo1(no);
row.setTStamp1(tStamp);
row.setSource1(fields[SOURCE_IDX]);
row.setDestination1(fields[DEST_IDX]);
row.setProtInfo(fields[PROTINFO_IDX]);
row.setCodec(fields[CODEC_IDX]);
row.setSsrc(ssrc);
row.setSeqNo(seqno.longValue());
row.setTime1(time.doubleValue());
doc.addRow(row);
} else {
//update
row.setNo2(no);
row.setTStamp2(tStamp);
row.setSource2(fields[SOURCE_IDX]);
row.setDestination2(fields[DEST_IDX]);
row.setTime2(time.doubleValue());
doc.updateRow(row, seqNoIndex);
}
//row.debug();
}
public void readInputFile() {
String file = "C:\\Dokumente und Einstellungen\\Admin\\Desktop\\Daten";
//String file = "C:\\Programme\\eclipse\\workspace\\dpla\\etc\\gas_mail2.txt";
//String file = "C:\\Programme\\eclipse\\workspace\\dpla\\etc\\fichier_v3.txt";
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String inLine;
int i = 0;
while((inLine=in.readLine()) != null) {
doConvert(inLine);
//if(++i>200) break;
}
} catch(FileNotFoundException e) {
System.out.println("ERROR: " + e);
} catch(IOException e) {
System.out.println("ERROR: " + e);
}
doc.computeAllRowDeviation();
}
public void print() {
doc.printAllValidRows();
}
public void write() {
doc.writeAllRows();
}
public void debug() {
doc.debugAllRows();
}
public static void main(String[] args) {
System.out.println("Running the converter...");
Converter conv = new Converter();
conv.readInputFile();
//conv.print();
conv.write();
System.out.println("End.");
}
}
package tk_labor;
/**
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DocRow {
private int no1;
private int no2;
private double tStamp1;
private double tStamp2;
private String source1;
private String destination1;
private String source2;
private String destination2;
private String protInfo;
private String codec;
private String ssrc;
private long seqNo;
private double time1; private double time2;
private double timeDiff;
private double deviation;
private int ssrcIndex;
public DocRow() {
//super();
no1 = 0;
no2 = 0;
tStamp1 = 0;
tStamp2 = 0;
source1 = "";
destination1 = "";
source2 = "";
destination2 = "";
protInfo = null;
codec = null;
ssrc = null;
seqNo = 0;
time1 = 0;
time2 = 0;
timeDiff = 0;
deviation = 0;
ssrcIndex = 0;
}
public int getNo1() {
return no1;
}
public void setNo1(int no1) {
this.no1 = no1;
}
public int getNo2() {
return no2;
}
public void setNo2(int no2) {
this.no2 = no2;
}
public double getTStamp1() {
return tStamp1;
}
public void setTStamp1(double tStamp1) {
this.tStamp1 = tStamp1;
}
public double getTStamp2() {
return tStamp2;
}
public void setTStamp2(double tStamp2) {
this.tStamp2 = tStamp2;
}
public String getSource1() {
return source1;
}
public void setSource1(String source1) {
this.source1 = source1;
}
public String getDestination1() {
return destination1;
}
public void setDestination1(String destination1) {
this.destination1 = destination1;
}
public String getSource2() {
return source2;
}
public void setSource2(String source2) {
this.source2 = source2;
}
public String getDestination2() {
return destination2;
}
public void setDestination2(String destination2) {
this.destination2 = destination2;
}
public String getProtInfo() {
return protInfo;
}
public void setProtInfo(String protInfo) {
this.protInfo = protInfo;
}
public String getCodec() {
return codec;
}
public void setCodec(String codec) {
this.codec = codec;
}
public String getSsrc() {
return ssrc;
}
public void setSsrc(String ssrc) {
this.ssrc = ssrc;
}
public long getSeqNo() {
return seqNo;
}
public void setSeqNo(long seqNo) {
this.seqNo = seqNo;
}
public double getTime1() {
return time1;
}
public void setTime1(double time1) {
this.time1 = time1;
}
public double getTime2() {
return time2;
}
public void setTime2(double time2) {
this.time2 = time2;
}
public double getTimeDiff() {
return timeDiff;
}
public void setTimeDiff(double timeDiff) {
this.timeDiff = timeDiff;
}
public double getDeviation() {
return deviation;
}
public void setDeviation(double deviation) {
this.deviation = deviation;
}
public int getSsrcIndex() {
return ssrcIndex;
}
public void setSsrcIndex(int ssrcIndex) {
this.ssrcIndex = ssrcIndex;
}
public void print() {
String line = "" + no1 + ";" +
no2 + ";" +
tStamp1 + ";" +
tStamp2 + ";" +
source1 + ";" +
destination1 + ";" +
source2 + ";" +
destination2 + ";" +
protInfo + ";" +
codec + ";" +
ssrc + ";" +
seqNo + ";" +
time1 + ";" +
time2 + ";" +
timeDiff + ";" +
deviation;
System.out.println(line);
}
public String write() {
String line = "" + /*no1 + ";" +
no2 + ";" +
tStamp1 + ";" +
tStamp2 + ";" +
source1 + ";" +
destination1 + ";" +
source2 + ";" +
destination2 + ";" +
protInfo + ";" +
codec + ";" +
ssrc + ";" +
seqNo + ";" +
time1 + ";" +
time2 + ";" +*/
timeDiff + ";" +
deviation;
return line;
}
public void debug() {
System.out.println("no1 : " + no1);
System.out.println("no2 : " + no2);
System.out.println("tStamp1 : " + tStamp1);
System.out.println("tStamp2 : " + tStamp2);
System.out.println("source1 : " + source1);
System.out.println("destination1 : " + destination1);
System.out.println("source2 : " + source2);
System.out.println("destination2 : " + destination2);
System.out.println("protInfo : " + protInfo);
System.out.println("codec : " + codec);
System.out.println("ssrc : " + ssrc);
System.out.println("seqNo : " + seqNo);
System.out.println("time1 : " + time1);
System.out.println("time2 : " + time2); System.out.println("timeDiff : " + timeDiff); System.out.println("deviation : " + deviation);
System.out.println("ssrcIndex : " + ssrcIndex);
}
}
package tk_labor;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
/**
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Document {
private Vector rows;
private Hashtable ssrcTab;
public Document() {
rows = new Vector();
ssrcTab = new Hashtable();
}
public int getRowCount(int ssrcIndex) {
//public int getAnzahlPakete(int ssrcIndex) {//
int rowCount = 0;
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getSsrcIndex()==ssrcIndex)
rowCount++;
}
return rowCount;
}
public int getValidRowCount(int ssrcIndex) {
int validRowCount = 0;
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getNo2() != 0 && row.getSsrcIndex()==ssrcIndex)
validRowCount++;
}
return validRowCount;
}
public double getSumDiffTime(int ssrcIndex) {
double sumDiffTime = 0;
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getNo2() != 0 && row.getSsrcIndex()==ssrcIndex)
sumDiffTime += row.getTimeDiff();
}
return sumDiffTime;
}
public double getDiffTimeAverage(int ssrcIndex) {
double diffTimeAverage = 0;
double validRowCount = getValidRowCount(ssrcIndex);
if(validRowCount>0) {
diffTimeAverage = getSumDiffTime(ssrcIndex) / validRowCount;
}
return diffTimeAverage;
}
/**
* @param seqno
* @return index i if found, -1 otherwise
*/
public int getSeqNoIndex(long seqno, double time) {
//System.out.println("Entering Document.getSeqNo: " + seqno);
int ret = -1;
int i = 0;
while(i<rows.size()) {
DocRow row = (DocRow)rows.elementAt(i);
if(seqno==row.getSeqNo() && time==row.getTime1()) {
ret = i;
break;
}
i++;
}
//System.out.println("Leaving Document.getSeqNo: " + ret);
return ret;
}
public int getSsrcIndex(String inSsrc) {
//System.out.println("inSsrc: " + inSsrc);
int ret = 0;
String sret = null;
if(inSsrc==null)
return 0;
Object o = ssrcTab.get(inSsrc);
if(o!=null) {
sret = o.toString();
Integer n = new Integer(sret);
ret = n.intValue();
} else {
ret = ssrcTab.size();
ret++;
sret = "" + ret;
ssrcTab.put(inSsrc, sret);
}
return ret;
}
public void addRow(DocRow row) {
int ssrcIndex = getSsrcIndex(row.getSsrc());
row.setSsrcIndex(ssrcIndex);
rows.addElement(row);
}
public void updateRow(DocRow inRow, int idx) {
if(idx>=rows.size())
return;
DocRow row = (DocRow)rows.elementAt(idx);
row.setNo2(inRow.getNo2());
row.setTStamp2(inRow.getTStamp2());
row.setSource2(inRow.getSource2());
row.setDestination2(inRow.getDestination2());
row.setTime2(inRow.getTime2());
//row.setTimeDiff(Math.abs(row.getTStamp2() - row.getTStamp1())/1000);
row.setTimeDiff(Math.abs(row.getTStamp2() - row.getTStamp1()));
rows.setElementAt(row, idx);
}
public void computeAllRowDeviation() {
Enumeration idxs = ssrcTab.elements();
while(idxs.hasMoreElements()) {
String s = (String)idxs.nextElement();
Integer n = new Integer(s);
int ssrcIndex = n.intValue();
double diffTimeAverage = getDiffTimeAverage(ssrcIndex);
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getNo2()!=0 && row.getSsrcIndex()==ssrcIndex) {
row.setDeviation(Math.abs(diffTimeAverage - row.getTimeDiff()));
rows.setElementAt(row, i);
}
}
}
}
public double getMinTimeDiff(int ssrcIndex) {
double min = 9999;
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getNo2() != 0 && row.getSsrcIndex()==ssrcIndex) {
if(i==0) {
min = row.getTimeDiff();
System.out.println("row.getTimeDiff");
} else {
if(min>row.getTimeDiff())
min = row.getTimeDiff();
}
}
}
return min;
}
public double getMaxTimeDiff(int ssrcIndex) {
double max = 0;
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getNo2() != 0 && row.getSsrcIndex()==ssrcIndex) {
if(i==0) {
max = row.getTimeDiff();
} else {
if(max<row.getTimeDiff())
max = row.getTimeDiff();
}
}
}
return max;
}
public double getMinDeviation(int ssrcIndex) {
double min = 9999;
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getNo2() != 0 && row.getSsrcIndex()==ssrcIndex) {
if(i==0) {
min = row.getDeviation();
} else {
if(min>row.getDeviation())
min = row.getDeviation();
}
}
}
return min;
}
public double getMaxDeviation(int ssrcIndex) {
double max = 0;
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getNo2() != 0 && row.getSsrcIndex()==ssrcIndex) {
if(i==0) {
max = row.getDeviation();
} else {
if(max<row.getDeviation())
max = row.getDeviation();
}
}
}
return max;
}
public void printAllValidRows() {
Enumeration idxs = ssrcTab.elements();
while(idxs.hasMoreElements()) {
String s = (String)idxs.nextElement();
Integer n = new Integer(s);
int ssrcIndex = n.intValue();
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getNo2()!=0 && row.getSsrcIndex()==ssrcIndex)
row.print();
}
DecimalFormat df = new DecimalFormat("000.000000");
int validRowCount = getValidRowCount(ssrcIndex);
System.out.println("validRowCount : " + validRowCount);
System.out.println("inValidRowCount : " + (getRowCount(ssrcIndex) - validRowCount)); //(rows.size()-getValidRowCount(ssrcIndex)-1));
System.out.println("sumDiffTime : " + getSumDiffTime(ssrcIndex));
System.out.println("diffTimeAverage : " + getDiffTimeAverage(ssrcIndex));
}
}
public void writeAllRows() {
//String outputDirectory = "C:\\Programme\\eclipse\\workspace\\dpla\\etc\\";
String outputDirectory = "C:\\Dokumente und Einstellungen\\Admin\\desktop\\";
Enumeration keys = ssrcTab.keys();
while(keys.hasMoreElements()) {
String key = (String)keys.nextElement();
String s = (String)ssrcTab.get(key);
Integer n = new Integer(s);
int ssrcIndex = n.intValue();
String filename = outputDirectory + "Daten_" + ssrcIndex + ".txt";
String summaryFile = outputDirectory + "Daten_" + ssrcIndex + "z.txt";
delete(filename);
delete(summaryFile);
System.out.println("fileneame: " + filename);
System.out.println("Empfangene_Pakete : " + getValidRowCount(ssrcIndex));
if(getValidRowCount(ssrcIndex)<200) {
continue;
}
String line = null;
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
if(row.getNo2()!=0 && row.getSsrcIndex()==ssrcIndex) {
line = row.write();
writeLine(filename, line);
}
}
DecimalFormat df = new DecimalFormat("0.0000%");
int validRowCount = getValidRowCount(ssrcIndex);
line = ("Empfangene_Pakete : " + validRowCount);
writeLine(summaryFile, line);
line = ("Paketverlust : " + (getRowCount(ssrcIndex) - validRowCount));
writeLine(summaryFile, line);
line = ("RTT_Gesamt_Summe : " + getSumDiffTime(ssrcIndex));
writeLine(summaryFile, line);
line = ("RTT_Mittelwert : " + getDiffTimeAverage(ssrcIndex));
writeLine(summaryFile, line);
line = ("min_Verzoegerung : " + getMinTimeDiff(ssrcIndex));
writeLine(summaryFile, line);
line = ("max_Verzoegerung : " + getMaxTimeDiff(ssrcIndex));
writeLine(summaryFile, line);
line = ("min_Jitter : " + getMinDeviation(ssrcIndex));
writeLine(summaryFile, line);
line = ("max_Jitter : " + getMaxDeviation(ssrcIndex));
writeLine(summaryFile, line);
double lostRate = ((getRowCount(ssrcIndex) - validRowCount)/(double)getRowCount(ssrcIndex));
line = ("Verlustsrate : " + df.format(lostRate));
writeLine(summaryFile, line);
}
}
public void debugAllRows() {
for(int i=0; i<rows.size(); i++) {
DocRow row = (DocRow)rows.elementAt(i);
row.debug();
}
}
private void delete(String filename) {
File f = new File(filename);
if(!f.exists())
return;
if(!f.canWrite()) {
System.out.println("Cannot delete: " + filename + " - write protected");
return;
}
boolean success = f.delete();
if(!success) {
System.out.println("Deletion failed");
}
}
private void writeLine(String filename, String line) {
try {
PrintWriter fileOut = new PrintWriter(new FileWriter(filename, true));
fileOut.println(line);
if(fileOut.checkError()) {
System.out.println("Error in Document.writeLine: " + filename + " - " + line);
}
fileOut.close();
} catch (IOException e) {
System.out.println("Exception in Document.writeLine " + e);
}
}
}