Java "UnicodePy"

Admin User, created Oct 25. 2024
         
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
/**
* Compressed General Category and Numeric Value: Compressor
* <p>
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
* <p>
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
* <p>
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
* <p>
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
* <p>
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
public class UnicodePy {
/**
* Compress and print.
*/
public static void main(String[] args) throws IOException {
long ts = System.currentTimeMillis();
Compress.compress();
Writer wr;
if (args.length > 0) {
wr = new FileWriter(args[0], StandardCharsets.UTF_8);
} else {
wr = new OutputStreamWriter(System.out, StandardCharsets.UTF_8);
}
statistics(ts, wr);
dump(wr);
wr.flush();
if (args.length > 0)
wr.close();
}
/**
* Print the two pools and the entry point.
*/
private static void dump(Writer wr) throws IOException {
wr.write("pool = [");
for (int i = 0; i < Compress.pool.size(); i++) {
if (i != 0) {
wr.write(",\n");
wr.write(" ");
}
Compress.show(Compress.pool.get(i), wr);
}
wr.write("]\n");
wr.write("pool2 = [");
for (int i = 0; i < Compress.pool2.size(); i++) {
if (i != 0) {
wr.write(",\n");
wr.write(" ");
}
Compress.show(Compress.pool2.get(i), wr);
}
wr.write("]\n");
wr.write("buf3 = ");
Compress.show(Compress.buf3.toString(), wr);
wr.write("\n");
wr.write("\n");
wr.write("\n");
wr.write("def code_property(ch):\n");
wr.write(" return pool[pool2[buf3[ch >> "+
(Compress.PARA_BITS+Compress.BLOCK_BITS)+"]][(ch >> "+
Compress.PARA_BITS+") & 0x"+
Integer.toHexString(Compress.BLOCK_SIZE-1).toUpperCase()+"]][ch & 0x"+
Integer.toHexString(Compress.PARA_SIZE-1).toUpperCase()+"]\n");
wr.write("\n");
wr.write("\n");
wr.write("def code_category(ch):\n");
wr.write(" return code_property(ch) & 0x1F\n");
wr.write("\n");
wr.write("\n");
wr.write("def code_numeric(ch):\n");
wr.write(" return (code_property(ch) >> 5) - 1\n");
}
/**
* Print some statistics about the compresssion.
*
* @param ts The time stamp before compression was called.
*/
private static void statistics(long ts, Writer wr) throws IOException {
long ts2 = System.currentTimeMillis();
wr.write("###\n");
wr.write("# Compression took " + (ts2 - ts) + " ms\n");
wr.write("# Java Specification Version " + Compress.getVersion()+"\n");
wr.write("# \n");
int alpha = Compress.pool.size() * Compress.PARA_SIZE;
int beta = Compress.pool2.size() * Compress.BLOCK_SIZE;
int gamma = Compress.MAX_BLOCK;
wr.write("# pool.size()*PARA_SIZE= " + alpha+"\n");
wr.write("# pool2.size()*BLOCK_SIZE= " + beta+"\n");
wr.write("# MAX_BLOCK= " + gamma+"\n");
wr.write("# Total= " + (alpha + beta + gamma)+"\n");
wr.write("##\n");
wr.write("\n");
}
}