Skip to content

Commit

Permalink
Defaultd to level 3 if the level is not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
flanglet committed Jan 22, 2024
1 parent a886cf3 commit a38aa9d
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions java/src/main/java/kanzi/app/BlockCompressor.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,45 +68,60 @@ public class BlockCompressor implements Runnable, Callable<Integer>
private final String codec;
private final String transform;
private int blockSize;
private final int level; // command line compression level
private final int jobs;
private final List<Listener> listeners;
private final ExecutorService pool;


public BlockCompressor(Map<String, Object> map)
{
this.level = map.containsKey("level") ? (Integer) map.remove("level") : -1;
Boolean bForce = (Boolean) map.remove("overwrite");
this.overwrite = (bForce == null) ? false : bForce;
Boolean bSkip = (Boolean) map.remove("skipBlocks");
this.skipBlocks = (bSkip == null) ? false : bSkip;
String iName = (String) map.remove("inputName");
this.inputName = iName.isEmpty() ? STDIN : iName;
String oName = (String) map.remove("outputName");
this.outputName = (oName.isEmpty() && STDIN.equalsIgnoreCase(iName)) ? STDOUT : oName;
String strTransf;
String strCodec;
int level = - 1;

if (this.level >= 0)
if (map.containsKey("level") == true)
{
String tranformAndCodec = getTransformAndCodec(this.level);
level = (Integer) map.remove("level");

if ((level < 0) || (level > 9))
throw new IllegalArgumentException("Invalid compression level (must be in [0..9], got " + level);

String tranformAndCodec = getTransformAndCodec(level);
String[] tokens = tranformAndCodec.split("&");
strTransf = tokens[0];
strCodec = tokens[1];
this.transform = tokens[0];
this.codec = tokens[1];
}
else
{
strTransf = (String) map.remove("transform");
strCodec = (String) map.remove("entropy");
if ((map.containsKey("transform") == false) && (map.containsKey("entropy") == false))
{
// Defaults to level 3
String tranformAndCodec = getTransformAndCodec(3);
String[] tokens = tranformAndCodec.split("&");
this.transform = tokens[0];
this.codec = tokens[1];
}
else
{
// Extract transform names. Curate input (EG. NONE+NONE+xxxx => xxxx)
String strT = map.containsKey("transform") ? (String) map.remove("transform") : "NONE";
TransformFactory tf = new TransformFactory();
this.transform = tf.getName(tf.getType(strT));
this.codec = map.containsKey("entropy") ? (String) map.remove("entropy") : "NONE";
}
}

this.codec = (strCodec == null) ? "ANS0" : strCodec;
Boolean bForce = (Boolean) map.remove("overwrite");
this.overwrite = (bForce == null) ? false : bForce;
Boolean bSkip = (Boolean) map.remove("skipBlocks");
this.skipBlocks = (bSkip == null) ? false : bSkip;
String iName = (String) map.remove("inputName");
this.inputName = iName.isEmpty() ? STDIN : iName;
String oName = (String) map.remove("outputName");
this.outputName = (oName.isEmpty() && STDIN.equalsIgnoreCase(iName)) ? STDOUT : oName;
Integer iBlockSize = (Integer) map.remove("block");

if (iBlockSize == null)
{
switch (this.level)
switch (level)
{
case 6:
this.blockSize = 2 * DEFAULT_BLOCK_SIZE;
Expand Down Expand Up @@ -139,9 +154,6 @@ public BlockCompressor(Map<String, Object> map)
this.blockSize = Math.min((bs+15) & -16, MAX_BLOCK_SIZE);
}

// Extract transform names. Curate input (EG. NONE+NONE+xxxx => xxxx)
TransformFactory bff = new TransformFactory();
this.transform = (strTransf == null) ? "BWT+RANK+ZRLT" : bff.getName(bff.getType(strTransf));
Boolean bChecksum = (Boolean) map.remove("checksum");
this.checksum = (bChecksum == null) ? false : bChecksum;
Boolean bReorder = (Boolean) map.remove("fileReorder");
Expand Down

0 comments on commit a38aa9d

Please sign in to comment.