Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix lintian manpage-not-compressed-with-max-compression warning
This patch introduces some low-level hacks on GZIP files to make
lintian happy regarding the man page compression level.
  • Loading branch information
Roman Kashitsyn committed Dec 14, 2013
commit cd5398c82520d7200a428fa90daa50f1b5b79413
28 changes: 26 additions & 2 deletions src/main/java/org/vafer/jdeb/producers/DataProducerManPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.vafer.jdeb.utils.Utils;

import java.io.*;
import java.util.zip.Deflater;
import java.util.zip.GZIPOutputStream;

/**
* DataProducer representing a man page entry.
Expand Down Expand Up @@ -89,7 +91,11 @@ private void produceCompressedPage( final DataConsumer receiver,
private byte[] getCompressedPageBytes() throws IOException, CompressorException {
InputStream inputStream = null;
final ByteArrayOutputStream inMemoryOut = new ByteArrayOutputStream();
final OutputStream compressedOut = COMPRESSOR.toCompressedOutputStream(inMemoryOut);
final OutputStream compressedOut = new GZIPOutputStream(inMemoryOut) {
{
def.setLevel(Deflater.BEST_COMPRESSION);
}
};

try {
inputStream = new BufferedInputStream(new FileInputStream(file));
Expand All @@ -99,7 +105,25 @@ private byte[] getCompressedPageBytes() throws IOException, CompressorException
IOUtils.closeQuietly(inputStream);
}

return inMemoryOut.toByteArray();
// Updating compression level to avoid the lintian
// `manpage-not-compressed-with-max-compression` error
return setBestCompressionFlag(inMemoryOut.toByteArray());
}

/**
* Sets XFLAG header field to BEST COMPRESSION.
* See http://www.gzip.org/zlib/rfc-gzip.html for details.
*
* @param bytes compressed file bytes, must be a valid GZIP file
* @return augmented file bytes
*/
private static byte[] setBestCompressionFlag( final byte[] bytes ) {

final int XFLAG_HEADER_INDEX = 8;
final byte BEST_COMPRESSION_FLAG = 2;

bytes[XFLAG_HEADER_INDEX] = BEST_COMPRESSION_FLAG;
return bytes;
}

static String makeDestination( final String dest, final File file ) {
Expand Down