0% found this document useful (0 votes)
74 views2 pages

Compression Parallel

This method takes an integer array as input, converts it to a string with spaces, compresses the string using BZip2 compression, and returns the size of the compressed data. It handles multi-threaded compression using a thread pool or single-threaded compression. Any errors compressing the data causes an error message to be printed and an invalid value to be returned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views2 pages

Compression Parallel

This method takes an integer array as input, converts it to a string with spaces, compresses the string using BZip2 compression, and returns the size of the compressed data. It handles multi-threaded compression using a thread pool or single-threaded compression. Any errors compressing the data causes an error message to be printed and an invalid value to be returned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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);
}
}
}

You might also like