Sunteți pe pagina 1din 2

public static double CompressionTestStatistics(int[] S)

byte[] compAOB;
ByteArrayOutputStream byteArrOutStream;
double invalidOut;
double T;
int byteLenOfCompAOB;
int i;
OutputStream outStream;
String errorMsg;
String SWithSpace;
char[] SWithSpaceChar;
StringWriter error;

SWithSpaceChar = new char[S.length * 2 - 1];


i = 0;
while (i < SWithSpaceChar.length - 2)
{
SWithSpaceChar[i] = (char) (S[i / 2] + '0');
i++;
SWithSpaceChar[i] = ' ';
i++;
}
// Last Char
SWithSpaceChar[i] = (char) (S[i / 2] + '0');
SWithSpace = new String(SWithSpaceChar);
byteArrOutStream = new ByteArrayOutputStream();
if (isMultiThreaded)
{
BZip2EncoderExecutorService executor =
BZip2OutputStream.createExecutorService(NUM_CORES);
BZip2OutputStreamSettings settings = new
BZip2OutputStreamSettings().setExecutorService(executor).setNumberOfEncoderThreads(
NUM_CORES);
try
{
outStream = new BZip2OutputStream(byteArrOutStream, settings);
try
{

outStream.write(SWithSpace.getBytes());
}
finally
{
outStream.close();
}
compAOB = byteArrOutStream.toByteArray();;
byteLenOfCompAOB = compAOB.length;
T = (double) (byteLenOfCompAOB);
executor.shutdown();
return (T);
}
catch (IOException e)
{
error = new StringWriter();
e.printStackTrace(new PrintWriter(error));
errorMsg = "Compression Test Statistics tidak dapat diimplementasi
karena adanya eror berikut :\n" + error.toString();
System.out.println(errorMsg);
invalidOut = -1d;
executor.shutdown();
return (invalidOut);
}
finally
{
executor.shutdown();
}
}
else
{
try
{
outStream = new BZip2OutputStream(byteArrOutStream);
try
{
outStream.write(SWithSpace.getBytes());
}
finally
{
outStream.close();
}
compAOB = byteArrOutStream.toByteArray();
byteLenOfCompAOB = compAOB.length;
T = (double) (byteLenOfCompAOB);
return (T);
}
catch (IOException e)
{
error = new StringWriter();
e.printStackTrace(new PrintWriter(error));
errorMsg = "Compression Test Statistics tidak dapat diimplementasi
karena adanya eror berikut :\n" + error.toString();
System.out.println(errorMsg);
invalidOut = -1d;
return (invalidOut);
}
}
}

S-ar putea să vă placă și