⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rangecoder.java

📁 java下操作rar文件,创建,压缩/解压缩等等.
💻 JAVA
字号:
/*
 * Copyright (c) 2007 innoSysTec (R) GmbH, Germany. All rights reserved.
 * Original author: Edmund Wagner
 * Creation date: 31.05.2007
 *
 * Source: $HeadURL$
 * Last changed: $LastChangedDate$
 * 
 * the unrar licence applies to all junrar source and binary distributions 
 * you are not allowed to use this source to re-create the RAR compression algorithm
 * 
 * Here some html entities which can be used for escaping javadoc tags:
 * "&":  "&" or "&"
 * "<":  "&#060;" or "&lt;"
 * ">":  "&#062;" or "&gt;"
 * "@":  "&#064;" 
 */
package de.innosystec.unrar.unpack.ppm;

import java.io.IOException;

import de.innosystec.unrar.exception.RarException;
import de.innosystec.unrar.unpack.Unpack;

/**
 * DOCUMENT ME
 * 
 * @author $LastChangedBy$
 * @version $LastChangedRevision$
 */
public class RangeCoder
{
	public static final int TOP = 1 << 24;

	public static final int BOT = 1 << 15;

	private static final long uintMask = 0xFFFFffffL;

	private long low, code, range;

	private SubRange subRange = new SubRange();

	private Unpack unpackRead;

	public SubRange getSubRange()
	{
		return subRange;
	}

	public void initDecoder(Unpack unpackRead) throws IOException, RarException
	{
		this.unpackRead = unpackRead;

		low = code = 0;
		range = 0xFFFFffffL;
		for (int i = 0; i < 4; i++) {
			code = ((code << 8) | getChar()&0xff)&uintMask;
		}
	}

	public long getCurrentCount()
	{
		range = range / subRange.getScale();
		return ((code - low) / (range));
	}

	public long getCurrentShiftCount(int SHIFT)
	{
		range = range >>>SHIFT;
		return (code - low) / (range);
	}

	public void decode()
	{
		low += (range * subRange.getLowCount())&uintMask;
		range *= (subRange.getHighCount() - subRange.getLowCount())&uintMask;
	}

	// public void putChar(int c){
	//    	
	// }
	public int getChar() throws IOException, RarException
	{
		return (unpackRead.getChar());
	}

	public void ariDecNormalize() throws IOException, RarException
	{
		while ((low ^ (low + range)) < TOP || range < BOT && ((range = -low & (BOT - 1)) != 0 ? true : true)) 
		{
			code = ((code << 8) | unpackRead.getChar()&0xff)&uintMask;
			range = (range << 8)&uintMask;
			low = (low << 8)&uintMask;
		}
	}

	public static class SubRange
	{
		private int lowCount, highCount, scale;

		public int getHighCount()
		{
			return highCount;
		}

		public void setHighCount(int highCount)
		{
			this.highCount = highCount;
		}

		public int getLowCount()
		{
			return lowCount;
		}

		public void setLowCount(int lowCount)
		{
			this.lowCount = lowCount;
		}

		public int getScale()
		{
			return scale;
		}

		public void setScale(int scale)
		{
			this.scale = scale;
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -