I am having trouble using Deflater to write a GZIP file. I created a default header and used CRC32 to keep track of the checksum.
The file I am zipping is smaller than my buffer, but the output I get for this compressor is ~200 bytes larger than it should be (gzip creates a file of 457 bytes while my code is creating a file of 652 bytes. I printed the compressedSize and it says it was 634 bytes) I did a hexdump on my final file, and it says that both my trailer and my main file is incorrect, but my header is correct. I am not allowed to use GZIPOutputStream for this assignment, but I used it's code to write the header and trailer. The amount of bytes read in is correct.
The "manage" object is an object that does the reading and writing from System.in and System.out in a synchronized matter (this is for multithreading), and I verified that they should read and write a file in order. I looked at the GZIPOutputStream source and the DeflaterOutputStream source, and my code looks similar, so I am unsure why my compressor is giving me such a large compressed byte array. I played with the Deflater levels and the strategies, but they give me the same result.
EDIT: The constructor for my Deflater is Deflater compressor = new Deflater(Deflater.DEFAULT_LEVEL, true);
CRC32 checksum = new CRC32();
checksum.reset();
int uncompressedLength = 0;
uncompressedLength = manage.read(buff, threadNum, prime);
if (uncompressedLength > 0)
{
checksum.update(buff, 0, uncompressedLength);
compressor.setInput(buff);
compressor.finish();
byte[] output = new byte[BUFFER_SIZE];
compressor.deflate(output);
int compressedDataLength = (int) compressor.getBytesWritten();
manage.write(output, compressedDataLength, threadNum, (int) checksum.getValue(), uncompressedLength);