You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ol...@apache.org on 2011/06/08 23:00:28 UTC

svn commit: r1133554 [5/5] - in /tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm: ./ accessor/ assertion/ core/ exception/ lzx/

Modified: tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxState.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxState.java?rev=1133554&r1=1133553&r2=1133554&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxState.java (original)
+++ tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmLzxState.java Wed Jun  8 21:00:27 2011
@@ -25,286 +25,286 @@ import org.apache.tika.parser.chm.core.C
 import org.apache.tika.parser.chm.exception.ChmParsingException;
 
 public class ChmLzxState {
-	/* Class' members */
-	private int window; /* the actual decoding window */
-	private long window_size; /* window size (32Kb through 2Mb) */
-	private int window_position; /* current offset within the window */
-	private int main_tree_elements; /* number of main tree elements */
-	private LzxState hadStarted; /* have we started decoding at all yet? */
-	private int block_type; /* type of this block */
-	private int block_length; /* uncompressed length of this block */
-	private int block_remaining; /* uncompressed bytes still left to decode */
-	private int frames_read; /* the number of CFDATA blocks processed */
-	private int intel_file_size; /* magic header value used for transform */
-	private long intel_current_possition; /* current offset in transform space */
-	private IntelState intel_state; /* have we seen any translatable data yet? */
-	private long R0; /* for the LRU offset system */
-	private long R1; /* for the LRU offset system */
-	private long R2; /* for the LRU offset system */
-
-	// Trees - PRETREE, MAINTREE, LENGTH, ALIGNED
-	protected short[] mainTreeLengtsTable;
-	protected short[] mainTreeTable;
-
-	protected short[] lengthTreeTable;
-	protected short[] lengthTreeLengtsTable;
-
-	protected short[] alignedLenTable;
-	protected short[] alignedTreeTable;
-
-	protected short[] getMainTreeTable() {
-		return mainTreeTable;
-	}
-
-	protected short[] getAlignedTreeTable() {
-		return alignedTreeTable;
-	}
-
-	protected void setAlignedTreeTable(short[] alignedTreeTable) {
-		this.alignedTreeTable = alignedTreeTable;
-	}
-
-	protected short[] getLengthTreeTable() {
-		if (lengthTreeTable != null)
-			return this.lengthTreeTable;
-		else
-			throw new ChmParsingException("lengthTreeTable is null");
-	}
-
-	protected void setLengthTreeTable(short[] lengthTreeTable) {
-		this.lengthTreeTable = lengthTreeTable;
-	}
-
-	protected void setMainTreeTable(short[] mainTreeTable) {
-		this.mainTreeTable = mainTreeTable;
-	}
-
-	protected short[] getAlignedLenTable() {
-		return this.alignedLenTable;
-	}
-
-	protected void setAlignedLenTable(short[] alignedLenTable) {
-		this.alignedLenTable = alignedLenTable;
-	}
-
-	/**
-	 * It suits for informative outlook
-	 */
-	public String toString() {
-		StringBuilder sb = new StringBuilder();
-		sb.append("actual decoding window:=" + getWindow()
-				+ System.getProperty("line.separator"));
-		sb.append("window size (32Kb through 2Mb):=" + getWindowSize()
-				+ System.getProperty("line.separator"));
-		sb.append("current offset within the window:=" + getWindowPosition()
-				+ System.getProperty("line.separator"));
-		sb.append("number of main tree elements:=" + getMainTreeElements()
-				+ System.getProperty("line.separator"));
-		sb.append("have we started decoding at all yet?:=" + getHadStarted()
-				+ System.getProperty("line.separator"));
-		sb.append("type of this block:=" + getBlockType()
-				+ System.getProperty("line.separator"));
-		sb.append("uncompressed length of this block:=" + getBlockLength()
-				+ System.getProperty("line.separator"));
-		sb.append("uncompressed bytes still left to decode:="
-				+ getBlockRemaining() + System.getProperty("line.separator"));
-		sb.append("the number of CFDATA blocks processed:=" + getFramesRead()
-				+ System.getProperty("line.separator"));
-		sb.append("magic header value used for transform:="
-				+ getIntelFileSize() + System.getProperty("line.separator"));
-		sb.append("current offset in transform space:="
-				+ getIntelCurrentPossition()
-				+ System.getProperty("line.separator"));
-		sb.append("have we seen any translatable data yet?:=" + getIntelState()
-				+ System.getProperty("line.separator"));
-		sb.append("R0 for the LRU offset system:=" + getR0()
-				+ System.getProperty("line.separator"));
-		sb.append("R1 for the LRU offset system:=" + getR1()
-				+ System.getProperty("line.separator"));
-		sb.append("R2 for the LRU offset system:=" + getR2()
-				+ System.getProperty("line.separator"));
-		sb.append("main tree length:=" + getMainTreeLengtsTable().length
-				+ System.getProperty("line.separator"));
-		sb.append("secondary tree length:=" + getLengthTreeLengtsTable().length
-				+ System.getProperty("line.separator"));
-		return sb.toString();
-	}
-
-	public ChmLzxState(int window) {
-		if (window >= 0) {
-			int position_slots;
-			int win = ChmCommons.getWindowSize(window);
-			setWindowSize(1 << win);
-			/* LZX supports window sizes of 2^15 (32Kb) through 2^21 (2Mb) */
-			if (win < 15 || win > 21)
-				System.err
-						.println("window less than 15 or window greater than 21");
-			/* Calculates required position slots */
-			if (win == 20)
-				position_slots = 42;
-			else if (win == 21)
-				position_slots = 50;
-			else
-				position_slots = win << 1;
-
-			setR0(1);
-			setR1(1);
-			setR2(1);
-			setMainTreeElements(512);
-			setHadStarted(LzxState.NOT_STARTED_DECODING);
-			setFramesRead(0);
-			setBlockRemaining(0);
-			setBlockType(ChmConstants.LZX_BLOCKTYPE_INVALID);
-			setIntelCurrentPossition(0);
-			setIntelState(IntelState.NOT_STARTED);
-			setWindowPosition(0);
-			setMainTreeLengtsTable(new short[getMainTreeElements()]);
-			setLengthTreeLengtsTable(new short[ChmConstants.LZX_NUM_SECONDARY_LENGTHS]);
-		} else
-			throw new CancellationException(
-					"window size should be more than zero");
-	}
-
-	protected void setWindow(int window) {
-		this.window = window;
-	}
-
-	protected int getWindow() {
-		return window;
-	}
-
-	protected void setWindowSize(long window_size) {
-		this.window_size = window_size;
-	}
-
-	protected long getWindowSize() {
-		return window_size;
-	}
-
-	protected void setWindowPosition(int window_position) {
-		this.window_position = window_position;
-	}
-
-	protected int getWindowPosition() {
-		return window_position;
-	}
-
-	protected void setMainTreeElements(int main_tree_elements) {
-		this.main_tree_elements = main_tree_elements;
-	}
-
-	protected int getMainTreeElements() {
-		return main_tree_elements;
-	}
-
-	protected void setHadStarted(LzxState hadStarted) {
-		this.hadStarted = hadStarted;
-	}
-
-	protected LzxState getHadStarted() {
-		return hadStarted;
-	}
-
-	protected void setBlockType(int block_type) {
-		this.block_type = block_type;
-	}
-
-	public int getBlockType() {
-		return block_type;
-	}
-
-	protected void setBlockLength(int block_length) {
-		this.block_length = block_length;
-	}
-
-	protected int getBlockLength() {
-		return block_length;
-	}
-
-	protected void setBlockRemaining(int block_remaining) {
-		this.block_remaining = block_remaining;
-	}
-
-	protected int getBlockRemaining() {
-		return block_remaining;
-	}
-
-	protected void setFramesRead(int frames_read) {
-		this.frames_read = frames_read;
-	}
-
-	protected void increaseFramesRead() {
-		this.frames_read = getFramesRead() + 1;
-	}
-
-	protected int getFramesRead() {
-		return frames_read;
-	}
-
-	protected void setIntelFileSize(int intel_file_size) {
-		this.intel_file_size = intel_file_size;
-	}
-
-	protected int getIntelFileSize() {
-		return intel_file_size;
-	}
-
-	protected void setIntelCurrentPossition(long intel_current_possition) {
-		this.intel_current_possition = intel_current_possition;
-	}
-
-	protected long getIntelCurrentPossition() {
-		return intel_current_possition;
-	}
-
-	protected void setIntelState(IntelState intel_state) {
-		this.intel_state = intel_state;
-	}
-
-	protected IntelState getIntelState() {
-		return intel_state;
-	}
-
-	protected void setR0(long r0) {
-		R0 = r0;
-	}
-
-	protected long getR0() {
-		return R0;
-	}
-
-	protected void setR1(long r1) {
-		R1 = r1;
-	}
-
-	protected long getR1() {
-		return R1;
-	}
-
-	protected void setR2(long r2) {
-		R2 = r2;
-	}
-
-	protected long getR2() {
-		return R2;
-	}
-
-	public static void main(String[] args) {
-	}
-
-	public void setMainTreeLengtsTable(short[] mainTreeLengtsTable) {
-		this.mainTreeLengtsTable = mainTreeLengtsTable;
-	}
-
-	public short[] getMainTreeLengtsTable() {
-		return mainTreeLengtsTable;
-	}
-
-	public void setLengthTreeLengtsTable(short[] lengthTreeLengtsTable) {
-		this.lengthTreeLengtsTable = lengthTreeLengtsTable;
-	}
-
-	public short[] getLengthTreeLengtsTable() {
-		return lengthTreeLengtsTable;
-	}
+    /* Class' members */
+    private int window; /* the actual decoding window */
+    private long window_size; /* window size (32Kb through 2Mb) */
+    private int window_position; /* current offset within the window */
+    private int main_tree_elements; /* number of main tree elements */
+    private LzxState hadStarted; /* have we started decoding at all yet? */
+    private int block_type; /* type of this block */
+    private int block_length; /* uncompressed length of this block */
+    private int block_remaining; /* uncompressed bytes still left to decode */
+    private int frames_read; /* the number of CFDATA blocks processed */
+    private int intel_file_size; /* magic header value used for transform */
+    private long intel_current_possition; /* current offset in transform space */
+    private IntelState intel_state; /* have we seen any translatable data yet? */
+    private long R0; /* for the LRU offset system */
+    private long R1; /* for the LRU offset system */
+    private long R2; /* for the LRU offset system */
+
+    // Trees - PRETREE, MAINTREE, LENGTH, ALIGNED
+    protected short[] mainTreeLengtsTable;
+    protected short[] mainTreeTable;
+
+    protected short[] lengthTreeTable;
+    protected short[] lengthTreeLengtsTable;
+
+    protected short[] alignedLenTable;
+    protected short[] alignedTreeTable;
+
+    protected short[] getMainTreeTable() {
+        return mainTreeTable;
+    }
+
+    protected short[] getAlignedTreeTable() {
+        return alignedTreeTable;
+    }
+
+    protected void setAlignedTreeTable(short[] alignedTreeTable) {
+        this.alignedTreeTable = alignedTreeTable;
+    }
+
+    protected short[] getLengthTreeTable() {
+        if (lengthTreeTable != null)
+            return this.lengthTreeTable;
+        else
+            throw new ChmParsingException("lengthTreeTable is null");
+    }
+
+    protected void setLengthTreeTable(short[] lengthTreeTable) {
+        this.lengthTreeTable = lengthTreeTable;
+    }
+
+    protected void setMainTreeTable(short[] mainTreeTable) {
+        this.mainTreeTable = mainTreeTable;
+    }
+
+    protected short[] getAlignedLenTable() {
+        return this.alignedLenTable;
+    }
+
+    protected void setAlignedLenTable(short[] alignedLenTable) {
+        this.alignedLenTable = alignedLenTable;
+    }
+
+    /**
+     * It suits for informative outlook
+     */
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("actual decoding window:=" + getWindow()
+                + System.getProperty("line.separator"));
+        sb.append("window size (32Kb through 2Mb):=" + getWindowSize()
+                + System.getProperty("line.separator"));
+        sb.append("current offset within the window:=" + getWindowPosition()
+                + System.getProperty("line.separator"));
+        sb.append("number of main tree elements:=" + getMainTreeElements()
+                + System.getProperty("line.separator"));
+        sb.append("have we started decoding at all yet?:=" + getHadStarted()
+                + System.getProperty("line.separator"));
+        sb.append("type of this block:=" + getBlockType()
+                + System.getProperty("line.separator"));
+        sb.append("uncompressed length of this block:=" + getBlockLength()
+                + System.getProperty("line.separator"));
+        sb.append("uncompressed bytes still left to decode:="
+                + getBlockRemaining() + System.getProperty("line.separator"));
+        sb.append("the number of CFDATA blocks processed:=" + getFramesRead()
+                + System.getProperty("line.separator"));
+        sb.append("magic header value used for transform:="
+                + getIntelFileSize() + System.getProperty("line.separator"));
+        sb.append("current offset in transform space:="
+                + getIntelCurrentPossition()
+                + System.getProperty("line.separator"));
+        sb.append("have we seen any translatable data yet?:=" + getIntelState()
+                + System.getProperty("line.separator"));
+        sb.append("R0 for the LRU offset system:=" + getR0()
+                + System.getProperty("line.separator"));
+        sb.append("R1 for the LRU offset system:=" + getR1()
+                + System.getProperty("line.separator"));
+        sb.append("R2 for the LRU offset system:=" + getR2()
+                + System.getProperty("line.separator"));
+        sb.append("main tree length:=" + getMainTreeLengtsTable().length
+                + System.getProperty("line.separator"));
+        sb.append("secondary tree length:=" + getLengthTreeLengtsTable().length
+                + System.getProperty("line.separator"));
+        return sb.toString();
+    }
+
+    public ChmLzxState(int window) {
+        if (window >= 0) {
+            int position_slots;
+            int win = ChmCommons.getWindowSize(window);
+            setWindowSize(1 << win);
+            /* LZX supports window sizes of 2^15 (32Kb) through 2^21 (2Mb) */
+            if (win < 15 || win > 21)
+                System.err
+                        .println("window less than 15 or window greater than 21");
+            /* Calculates required position slots */
+            if (win == 20)
+                position_slots = 42;
+            else if (win == 21)
+                position_slots = 50;
+            else
+                position_slots = win << 1;
+
+            setR0(1);
+            setR1(1);
+            setR2(1);
+            setMainTreeElements(512);
+            setHadStarted(LzxState.NOT_STARTED_DECODING);
+            setFramesRead(0);
+            setBlockRemaining(0);
+            setBlockType(ChmConstants.LZX_BLOCKTYPE_INVALID);
+            setIntelCurrentPossition(0);
+            setIntelState(IntelState.NOT_STARTED);
+            setWindowPosition(0);
+            setMainTreeLengtsTable(new short[getMainTreeElements()]);
+            setLengthTreeLengtsTable(new short[ChmConstants.LZX_NUM_SECONDARY_LENGTHS]);
+        } else
+            throw new CancellationException(
+                    "window size should be more than zero");
+    }
+
+    protected void setWindow(int window) {
+        this.window = window;
+    }
+
+    protected int getWindow() {
+        return window;
+    }
+
+    protected void setWindowSize(long window_size) {
+        this.window_size = window_size;
+    }
+
+    protected long getWindowSize() {
+        return window_size;
+    }
+
+    protected void setWindowPosition(int window_position) {
+        this.window_position = window_position;
+    }
+
+    protected int getWindowPosition() {
+        return window_position;
+    }
+
+    protected void setMainTreeElements(int main_tree_elements) {
+        this.main_tree_elements = main_tree_elements;
+    }
+
+    protected int getMainTreeElements() {
+        return main_tree_elements;
+    }
+
+    protected void setHadStarted(LzxState hadStarted) {
+        this.hadStarted = hadStarted;
+    }
+
+    protected LzxState getHadStarted() {
+        return hadStarted;
+    }
+
+    protected void setBlockType(int block_type) {
+        this.block_type = block_type;
+    }
+
+    public int getBlockType() {
+        return block_type;
+    }
+
+    protected void setBlockLength(int block_length) {
+        this.block_length = block_length;
+    }
+
+    protected int getBlockLength() {
+        return block_length;
+    }
+
+    protected void setBlockRemaining(int block_remaining) {
+        this.block_remaining = block_remaining;
+    }
+
+    protected int getBlockRemaining() {
+        return block_remaining;
+    }
+
+    protected void setFramesRead(int frames_read) {
+        this.frames_read = frames_read;
+    }
+
+    protected void increaseFramesRead() {
+        this.frames_read = getFramesRead() + 1;
+    }
+
+    protected int getFramesRead() {
+        return frames_read;
+    }
+
+    protected void setIntelFileSize(int intel_file_size) {
+        this.intel_file_size = intel_file_size;
+    }
+
+    protected int getIntelFileSize() {
+        return intel_file_size;
+    }
+
+    protected void setIntelCurrentPossition(long intel_current_possition) {
+        this.intel_current_possition = intel_current_possition;
+    }
+
+    protected long getIntelCurrentPossition() {
+        return intel_current_possition;
+    }
+
+    protected void setIntelState(IntelState intel_state) {
+        this.intel_state = intel_state;
+    }
+
+    protected IntelState getIntelState() {
+        return intel_state;
+    }
+
+    protected void setR0(long r0) {
+        R0 = r0;
+    }
+
+    protected long getR0() {
+        return R0;
+    }
+
+    protected void setR1(long r1) {
+        R1 = r1;
+    }
+
+    protected long getR1() {
+        return R1;
+    }
+
+    protected void setR2(long r2) {
+        R2 = r2;
+    }
+
+    protected long getR2() {
+        return R2;
+    }
+
+    public static void main(String[] args) {
+    }
+
+    public void setMainTreeLengtsTable(short[] mainTreeLengtsTable) {
+        this.mainTreeLengtsTable = mainTreeLengtsTable;
+    }
+
+    public short[] getMainTreeLengtsTable() {
+        return mainTreeLengtsTable;
+    }
+
+    public void setLengthTreeLengtsTable(short[] lengthTreeLengtsTable) {
+        this.lengthTreeLengtsTable = lengthTreeLengtsTable;
+    }
+
+    public short[] getLengthTreeLengtsTable() {
+        return lengthTreeLengtsTable;
+    }
 }

Modified: tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmSection.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmSection.java?rev=1133554&r1=1133553&r2=1133554&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmSection.java (original)
+++ tika/trunk/tika-parsers/src/main/java/org/apache/tika/parser/chm/lzx/ChmSection.java Wed Jun  8 21:00:27 2011
@@ -22,187 +22,186 @@ import java.util.Arrays;
 import org.apache.tika.parser.chm.core.ChmCommons;
 
 public class ChmSection {
-	private byte[] data;
-	private int swath;// kiks
-	private int total;// remains
-	private int buffer;// val
-
-	public ChmSection(byte[] data) {
-		ChmCommons.assertByteArrayNotNull(data);
-		setData(data);
-	}
-
-	/* Utilities */
-	public byte[] reverseByteOrder(byte[] toBeReversed) {
-		ChmCommons.assertByteArrayNotNull(toBeReversed);
-		ChmCommons.reverse(toBeReversed);
-		return toBeReversed;
-	}
-
-	public int checkBit(int i) {
-		return ((getBuffer() & (1 << (getTotal() - i))) == 0) ? 0 : 1;
-	}
-
-	public int getSyncBits(int bit) {
-		return getDesyncBits(bit, bit);
-	}
-
-	public int getDesyncBits(int bit, int removeBit) {
-		while (getTotal() < 16) {
-			setBuffer((getBuffer() << 16) + unmarshalUByte()
-					+ (unmarshalUByte() << 8));
-			setTotal(getTotal() + 16);
-		}
-		int tmp = (getBuffer() >>> (getTotal() - bit));
-		setTotal(getTotal() - removeBit);
-		setBuffer(getBuffer() - ((getBuffer() >>> getTotal()) << getTotal()));
-		return tmp;
-	}
-
-	public int unmarshalUByte() {
-		return (int) (getByte() & 255);
-	}
-
-	public byte getByte() {
-		if (getSwath() < getData().length) {
-			setSwath(getSwath() + 1);
-			return getData()[getSwath() - 1];
-		} else
-			return 0;
-	}
-
-	public int getLeft() {
-		return (getData().length - getSwath());
-	}
-
-	public byte[] getData() {
-		return data;
-	}
-
-	public BigInteger getBigInteger(int i) {
-		if (getData() == null)
-			return BigInteger.ZERO;
-		if (getData().length - getSwath() < i)
-			i = getData().length - getSwath();
-		byte[] tmp = new byte[i];
-		for (int j = i - 1; j >= 0; j--) {
-			tmp[i - j - 1] = getData()[getSwath() + j];
-		}
-		setSwath(getSwath() + i);
-		return new BigInteger(tmp);
-	}
-
-	public byte[] stringToAsciiBytes(String s) {
-		char[] c = s.toCharArray();
-		byte[] byteval = new byte[c.length];
-		for (int i = 0; i < c.length; i++)
-			byteval[i] = (byte) c[i];
-		return byteval;
-	}
-
-	public BigInteger unmarshalUlong() {
-		return getBigInteger(8);
-	}
-
-	public long unmarshalUInt() {
-		return getBigInteger(4).longValue();
-	}
-
-	public int unmarshalInt() {
-		return getBigInteger(4).intValue();
-	}
-
-	public byte[] unmarshalBytes(int i) {
-		if (i == 0)
-			return new byte[1];
-		byte[] t = new byte[i];
-		for (int j = 0; j < i; j++)
-			t[j] = getData()[j + getSwath()];
-		setSwath(getSwath() + i);
-		return t;
-	}
-
-	public BigInteger getEncint() {
-		byte ob;
-		BigInteger bi = BigInteger.ZERO;
-		byte[] nb = new byte[1];
-		while ((ob = this.getByte()) < 0) {
-			nb[0] = (byte) ((ob & 0x7f));
-			bi = bi.shiftLeft(7).add(new BigInteger(nb));
-		}
-		nb[0] = (byte) ((ob & 0x7f));
-		bi = bi.shiftLeft(7).add(new BigInteger(nb));
-		return bi;
-	}
-
-	public char unmarshalUtfChar() {
-		byte ob;
-		int i = 1;
-		byte[] ba;
-		ob = this.getByte();
-		if (ob < 0) {
-			i = 2;
-			while ((ob << (24 + i)) < 0)
-				i++;
-		}
-		ba = new byte[i];
-		ba[0] = ob;
-		int j = 1;
-		while (j < i) {
-			ba[j] = this.getByte();
-			j++;
-		}
-		i = ba.length;
-		if (i == 1)
-			return (char) ba[0];
-		else {
-			int n;
-			n = ba[0] & 15; // 00001111b, gets last 4 bits
-			j = 1;
-			while (j < i)
-				n = (n << 6) + (ba[j++] & 63);// 00111111b,gets last 6 bits
-			return (char) n;
-		}
-	}
-
-	private void setData(byte[] data) {
-		this.data = data;
-	}
-
-	public int getSwath() {
-		return swath;
-	}
-
-	public void setSwath(int swath) {
-		this.swath = swath;
-	}
-
-	public int getTotal() {
-		return total;
-	}
-
-	public void setTotal(int total) {
-		this.total = total;
-	}
-
-	private int getBuffer() {
-		return buffer;
-	}
-
-	private void setBuffer(int buffer) {
-		this.buffer = buffer;
-	}
-
-	/**
-	 * @param args
-	 */
-	public static void main(String[] args) {
-		int result = 8 & 255;
-		System.out.println("result " + result);
-		byte[] array = { 4, 78, -67, 90, 1, -33 };
-		ChmSection chmSection = new ChmSection(array);
-		System.out.println("before " + Arrays.toString(array));
-		System.out.println("after "
-				+ Arrays.toString(chmSection.reverseByteOrder(array)));
-	}
+    private byte[] data;
+    private int swath;// kiks
+    private int total;// remains
+    private int buffer;// val
+
+    public ChmSection(byte[] data) {
+        ChmCommons.assertByteArrayNotNull(data);
+        setData(data);
+    }
+
+    /* Utilities */
+    public byte[] reverseByteOrder(byte[] toBeReversed) {
+        ChmCommons.assertByteArrayNotNull(toBeReversed);
+        ChmCommons.reverse(toBeReversed);
+        return toBeReversed;
+    }
+
+    public int checkBit(int i) {
+        return ((getBuffer() & (1 << (getTotal() - i))) == 0) ? 0 : 1;
+    }
+
+    public int getSyncBits(int bit) {
+        return getDesyncBits(bit, bit);
+    }
+
+    public int getDesyncBits(int bit, int removeBit) {
+        while (getTotal() < 16) {
+            setBuffer((getBuffer() << 16) + unmarshalUByte()
+                    + (unmarshalUByte() << 8));
+            setTotal(getTotal() + 16);
+        }
+        int tmp = (getBuffer() >>> (getTotal() - bit));
+        setTotal(getTotal() - removeBit);
+        setBuffer(getBuffer() - ((getBuffer() >>> getTotal()) << getTotal()));
+        return tmp;
+    }
+
+    public int unmarshalUByte() {
+        return (int) (getByte() & 255);
+    }
+
+    public byte getByte() {
+        if (getSwath() < getData().length) {
+            setSwath(getSwath() + 1);
+            return getData()[getSwath() - 1];
+        } else
+            return 0;
+    }
+
+    public int getLeft() {
+        return (getData().length - getSwath());
+    }
+
+    public byte[] getData() {
+        return data;
+    }
+
+    public BigInteger getBigInteger(int i) {
+        if (getData() == null)
+            return BigInteger.ZERO;
+        if (getData().length - getSwath() < i)
+            i = getData().length - getSwath();
+        byte[] tmp = new byte[i];
+        for (int j = i - 1; j >= 0; j--) {
+            tmp[i - j - 1] = getData()[getSwath() + j];
+        }
+        setSwath(getSwath() + i);
+        return new BigInteger(tmp);
+    }
+
+    public byte[] stringToAsciiBytes(String s) {
+        char[] c = s.toCharArray();
+        byte[] byteval = new byte[c.length];
+        for (int i = 0; i < c.length; i++)
+            byteval[i] = (byte) c[i];
+        return byteval;
+    }
+
+    public BigInteger unmarshalUlong() {
+        return getBigInteger(8);
+    }
+
+    public long unmarshalUInt() {
+        return getBigInteger(4).longValue();
+    }
+
+    public int unmarshalInt() {
+        return getBigInteger(4).intValue();
+    }
+
+    public byte[] unmarshalBytes(int i) {
+        if (i == 0)
+            return new byte[1];
+        byte[] t = new byte[i];
+        for (int j = 0; j < i; j++)
+            t[j] = getData()[j + getSwath()];
+        setSwath(getSwath() + i);
+        return t;
+    }
+
+    public BigInteger getEncint() {
+        byte ob;
+        BigInteger bi = BigInteger.ZERO;
+        byte[] nb = new byte[1];
+        while ((ob = this.getByte()) < 0) {
+            nb[0] = (byte) ((ob & 0x7f));
+            bi = bi.shiftLeft(7).add(new BigInteger(nb));
+        }
+        nb[0] = (byte) ((ob & 0x7f));
+        bi = bi.shiftLeft(7).add(new BigInteger(nb));
+        return bi;
+    }
+
+    public char unmarshalUtfChar() {
+        byte ob;
+        int i = 1;
+        byte[] ba;
+        ob = this.getByte();
+        if (ob < 0) {
+            i = 2;
+            while ((ob << (24 + i)) < 0)
+                i++;
+        }
+        ba = new byte[i];
+        ba[0] = ob;
+        int j = 1;
+        while (j < i) {
+            ba[j] = this.getByte();
+            j++;
+        }
+        i = ba.length;
+        if (i == 1)
+            return (char) ba[0];
+        else {
+            int n;
+            n = ba[0] & 15; // 00001111b, gets last 4 bits
+            j = 1;
+            while (j < i)
+                n = (n << 6) + (ba[j++] & 63);// 00111111b,gets last 6 bits
+            return (char) n;
+        }
+    }
+
+    private void setData(byte[] data) {
+        this.data = data;
+    }
+
+    public int getSwath() {
+        return swath;
+    }
+
+    public void setSwath(int swath) {
+        this.swath = swath;
+    }
+
+    public int getTotal() {
+        return total;
+    }
+
+    public void setTotal(int total) {
+        this.total = total;
+    }
+
+    private int getBuffer() {
+        return buffer;
+    }
+
+    private void setBuffer(int buffer) {
+        this.buffer = buffer;
+    }
+
+    /**
+     * @param args
+     */
+    public static void main(String[] args) {
+        int result = 8 & 255;
+        System.out.println("result " + result);
+        byte[] array = { 4, 78, -67, 90, 1, -33 };
+        ChmSection chmSection = new ChmSection(array);
+        System.out.println("before " + Arrays.toString(array));
+        System.out.println("after " + Arrays.toString(chmSection.reverseByteOrder(array)));
+    }
 }