package jcomparator;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Paolo
*/
private int equalByte;
private double percentEqual;
private double percentCharging;
this.fileOne = pFileOne;
this.fileTwo = pFileTwo;
this.equalByte = 0;
this.percentEqual = 0.0;
this.percentCharging = 0.0;
}
public void start() {
this.
startThread = new Thread(this);
this.startThread.start();
}
public boolean isAlive() {
return this.startThread.isAlive();
}
public void run() {
try {
long lengOne = this.fileOne.length();
long lengTwo = this.fileTwo.length();
long minLeng = (lengOne < lengTwo ? lengOne : lengTwo);
long maxLeng = (lengOne > lengTwo ? lengOne : lengTwo);
byte[] bufferOne = new byte[(int) lengOne];
byte[] bufferTwo = new byte[(int) lengTwo];
try {
inputOne.read(bufferOne);
inputTwo.read(bufferTwo);
}
for (int i = 0; i < minLeng; i++) {
if (bufferOne[i] == bufferTwo[i]) {
this.equalByte++;
this.percentEqual = (double) (this.equalByte * 100) / maxLeng;
if (this.percentEqual < 0.001) {
this.percentEqual = 0;
}
}
this.percentCharging = (double) (i * 100) / (minLeng-1);
if (this.percentCharging < 0.001) {
this.percentCharging = 0;
}
try {
}
}
}
}
public int getEqualByte() {
return equalByte;
}
public String getPercentEqual
() {
String percent
= this.
percentEqual + "";
split[0] = "";
split[1] = "";
boolean afterPoint = false;
for (int i = 0; i < percent.length(); i++) {
if (percent.charAt(i) == '.') {
afterPoint = true;
}
if (!afterPoint) {
split[0] = split[0] + percent.charAt(i);
} else {
split[1] = split[1] + percent.charAt(i);
}
}
String retval
= split
[0
] + split
[1
].
substring(0, 2
);
return retval;
}
public String getPercentCharging
() {
String percent
= this.
percentCharging + "";
split[0] = "";
split[1] = "";
boolean afterPoint = false;
for (int i = 0; i < percent.length(); i++) {
if (percent.charAt(i) == '.') {
afterPoint = true;
}
if (!afterPoint) {
split[0] = split[0] + percent.charAt(i);
} else {
split[1] = split[1] + percent.charAt(i);
}
}
String retval
= split
[0
] + split
[1
].
substring(0, 2
);
return retval;
}
}