View Javadoc

1   package org.paneris.bibliomania.fti;
2   
3   import java.io.IOException;
4   import java.io.OutputStream;
5   /** 
6    * A family of classes to pack numbers into as small a size as possible. 
7    * Need to know: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html
8    * 
9    * @author williamc
10   * @since 2000-05-22
11   */
12  public abstract class Packer {
13    
14    /** Unsigned int from byte. */
15    public static int uint(byte b) {
16      return b >= 0 ? b : 256 + b;
17    }
18  
19    private int numberLength;
20    private int numberMax;
21  
22    /** 
23     * 
24     * @param numberLength number of bytes
25     * @param numberMax maximum representable
26     */
27    protected Packer(int numberLength, int numberMax) {
28      this.numberLength = numberLength;
29      this.numberMax = numberMax;
30    }
31  
32    public final int numberLength() {
33      return numberLength;
34    }
35  
36    public final int numberMax() {
37      return numberMax;
38    }
39  
40    public abstract int number(byte[] bytes, int off);
41  
42    public abstract Packer bigger();
43  
44    public abstract void write(OutputStream os, int number) throws IOException;
45  }