ICompressionLevelCallback interface
Contents
- Introduction to the Library
- Basic support package (com.kryptel.bslx)
- Kryptel API Commons package (com.kryptel)
- ApiHelpers class
- Constants class
- IComponentCapabilities interface
- IComponentState interface
- ICompressionLevelCallback interface
- IDataSink interface
- IKryptelComponent interface
- INotification interface
- IProgressCallback interface
- IReplaceCallback interface
- Loader class
- Message class
- Progress class
- ProgressCallback class
- Cipher package (com.kryptel.cipher)
- Compressor package (com.kryptel.compressor)
- Exceptions package (com.kryptel.exceptions)
- Hash function package (com.kryptel.hash_function)
- MAC function package (com.kryptel.mac)
- Key-related functions (com.kryptel.key)
- Silver Key engine (com.kryptel.silver_key)
- Kryptel encrypted storage (com.kryptel.storage)
Declaration
package com.kryptel; public interface ICompressionLevelCallback { byte Get(String path) throws Exception; }
Description
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.
Get
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.
Example
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; } return CT_MAX_COMPRESSION; } }