📄 comprdataio.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 "&"
* "<": "<" or "<"
* ">": ">" or ">"
* "@": "@"
*/
package de.innosystec.unrar.unpack;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import de.innosystec.unrar.Archive;
import de.innosystec.unrar.crc.RarCRC;
import de.innosystec.unrar.exception.RarException;
import de.innosystec.unrar.exception.RarException.RarExceptionType;
import de.innosystec.unrar.rarfile.FileHeader;
/**
* DOCUMENT ME
*
* @author $LastChangedBy$
* @version $LastChangedRevision$
*/
public class ComprDataIO
{
private long unpWrSize;
private long unpPackedSize;
private boolean testMode;
private boolean skipUnpCRC;
private InputStream inputStream;
private OutputStream outputStream;
private FileHeader subHead;
// cryptData Crypt;
// cryptData Decrypt;
private boolean packVolume;
private boolean unpVolume;
private boolean nextVolumeMissing;
private long totalPackRead;
private long unpArcSize;
private long curPackRead, curPackWrite, curUnpRead, curUnpWrite;
private long processedArcSize, totalArcSize;
private long packFileCRC, unpFileCRC, packedCRC;
private int encryption;
private int decryption;
private int lastPercent;
private char currentCommand;
private Archive archive;
public ComprDataIO(Archive arc)
{
this.archive = arc;
}
public void init(InputStream inputStream, OutputStream outputStream)
{
this.inputStream = inputStream;
this.outputStream = outputStream;
unpPackedSize = 0;
// showProgress = true;
testMode = false;
skipUnpCRC = false;
packVolume = false;
unpVolume = false;
nextVolumeMissing = false;
unpWrSize = 0;
// command = null;
encryption = 0;
decryption = 0;
totalPackRead = 0;
curPackRead = curPackWrite = curUnpRead = curUnpWrite = 0;
packFileCRC = unpFileCRC = packedCRC = 0xffffffff;
lastPercent = -1;
subHead = null;
currentCommand = 0;
processedArcSize = totalArcSize = 0;
}
public int unpRead(byte[] Addr, int offset, int Count) throws IOException, RarException
{
int RetCode=0,TotalRead=0;
while (Count > 0)
{
int ReadSize=(Count>unpPackedSize) ? (int)unpPackedSize:Count;
RetCode=inputStream.read(Addr, offset, Count);
if (subHead.isSplitAfter()){
packedCRC=RarCRC.rarCRC.checkCrc((int)packedCRC,Addr,offset,ReadSize);
}
curUnpRead+=RetCode;
TotalRead+=RetCode;
Count-=RetCode;
unpPackedSize-=RetCode;
if (unpPackedSize == 0 && unpVolume)
{
throw new RarException(RarExceptionType.notImplementedYet);
// if (!MergeArchive(archive,this,true,CurrentCommand))
// {
// NextVolumeMissing=true;
// return(-1);
// }
}
else{
break;
}
}
if (RetCode!=-1)
{
RetCode=TotalRead;
if (decryption!=0)
throw new RarException(RarExceptionType.notImplementedYet);
// if (decryption<20)
// decrypt.Crypt(Addr,RetCode,(Decryption==15) ? NEW_CRYPT : OLD_DECODE);
// else
// if (Decryption==20)
// for (uint I=0;I<RetCode;I+=16)
// Decrypt.DecryptBlock20(&Addr[I]);
// else
// {
// int CryptSize=(RetCode & 0xf)==0 ? RetCode:((RetCode & ~0xf)+16);
// Decrypt.DecryptBlock(Addr,CryptSize);
// }
}
return(RetCode);
}
public void unpWrite(byte[] Addr, int offset, int Count) throws IOException
{
unpWrSize = Count;
if (!testMode) {
// DestFile->Write(Addr,Count);
outputStream.write(Addr, offset, Count);
}
curUnpWrite += Count;
if (!skipUnpCRC){
if (archive.isOldFormat()){
unpFileCRC = RarCRC.rarCRC.checkOldCrc((short) unpFileCRC,Addr, Count);
}
else{
unpFileCRC = RarCRC.rarCRC.checkCrc((int) unpFileCRC, Addr,offset, Count);
}
}
}
// public void getUnpackedData(byte[] Data, long size)
// {
//
// }
public void setPackedSizeToRead(long size)
{
unpPackedSize = size;
}
public void setTestMode(boolean mode)
{
testMode = mode;
}
public void setSkipUnpCRC(boolean skip)
{
skipUnpCRC = skip;
}
public void setSubHeader(FileHeader hd)
{
subHead = hd;
}
public long getCurPackRead()
{
return curPackRead;
}
public void setCurPackRead(long curPackRead)
{
this.curPackRead = curPackRead;
}
public long getCurPackWrite()
{
return curPackWrite;
}
public void setCurPackWrite(long curPackWrite)
{
this.curPackWrite = curPackWrite;
}
public long getCurUnpRead()
{
return curUnpRead;
}
public void setCurUnpRead(long curUnpRead)
{
this.curUnpRead = curUnpRead;
}
public long getCurUnpWrite()
{
return curUnpWrite;
}
public void setCurUnpWrite(long curUnpWrite)
{
this.curUnpWrite = curUnpWrite;
}
public int getDecryption()
{
return decryption;
}
public void setDecryption(int decryption)
{
this.decryption = decryption;
}
public int getEncryption()
{
return encryption;
}
public void setEncryption(int encryption)
{
this.encryption = encryption;
}
public boolean isNextVolumeMissing()
{
return nextVolumeMissing;
}
public void setNextVolumeMissing(boolean nextVolumeMissing)
{
this.nextVolumeMissing = nextVolumeMissing;
}
public long getPackedCRC()
{
return packedCRC;
}
public void setPackedCRC(long packedCRC)
{
this.packedCRC = packedCRC;
}
public long getPackFileCRC()
{
return packFileCRC;
}
public void setPackFileCRC(long packFileCRC)
{
this.packFileCRC = packFileCRC;
}
public boolean isPackVolume()
{
return packVolume;
}
public void setPackVolume(boolean packVolume)
{
this.packVolume = packVolume;
}
public long getProcessedArcSize()
{
return processedArcSize;
}
public void setProcessedArcSize(long processedArcSize)
{
this.processedArcSize = processedArcSize;
}
public long getTotalArcSize()
{
return totalArcSize;
}
public void setTotalArcSize(long totalArcSize)
{
this.totalArcSize = totalArcSize;
}
public long getTotalPackRead()
{
return totalPackRead;
}
public void setTotalPackRead(long totalPackRead)
{
this.totalPackRead = totalPackRead;
}
public long getUnpArcSize()
{
return unpArcSize;
}
public void setUnpArcSize(long unpArcSize)
{
this.unpArcSize = unpArcSize;
}
public long getUnpFileCRC()
{
return unpFileCRC;
}
public void setUnpFileCRC(long unpFileCRC)
{
this.unpFileCRC = unpFileCRC;
}
public boolean isUnpVolume()
{
return unpVolume;
}
public void setUnpVolume(boolean unpVolume)
{
this.unpVolume = unpVolume;
}
public FileHeader getSubHeader()
{
return subHead;
}
// public void setEncryption(int method, char[] Password, byte[] Salt,
// boolean encrypt, boolean handsOffHash)
// {
//
// }
//
// public void setAV15Encryption()
// {
//
// }
//
// public void setCmt13Encryption()
// {
//
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -