ICompressionLevelCallback interface


package com.kryptel;

public interface ICompressionLevelCallback {
  byte Get(String path) throws Exception;


If the file does not contain regular data patterns (an example is encrypted or compressed files), then compressing such a file will increase its size instead of reducing it. So we need some way to control compression depending on the file contents.

Silver Key solves this problem by checking the names of input files against the Don't compress list of file extensions. Kryptel agents use a more advanced method – ICompressionLevelCallback. A file agent calls this callback for every file in the encryption batch.

This interface is optional; the client may choose not to implement it. In this case just pass null where the interface pointer is required and the agent will always use Constants.DEFAULT_COMPRESSION_LEVEL.


byte Get(String path) throws Exception;

The argument is the full path to a file. The returned value is the required compression level from 0 (no compression) to 9 (max compression). See also the CT_* named constants in the Constants class.


This example sets the compression level exactly as Silver Key does, i.e. by checking the file extension against the internal Don't compress list.

class CompressionLevel implements ICompressionLevelCallback {

  private static String[] nonCompressible = { ".jpg", ".jpeg", ".png", ".gif", ".mp3", ".flac",
                                              ".ape", ".mp4", ".mov", ".zip", ".rar", ".7z" };
  public byte Get(String path) {
    for (String s: nonCompressible) {
      int len = s.length();
      int pos = path.length() - len;
      if ((pos > 0) && path.substring(pos).equalsIgnoreCase(s)) return CT_NO_COMPRESSION;