Browse Source

Fix bad coding style.

then/else parts of if statement and loop body must always been enclosed
in a block statement.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270630 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 24 years ago
parent
commit
7a4e9ca227
8 changed files with 357 additions and 188 deletions
  1. +3
    -1
      src/main/org/apache/tools/ant/taskdefs/AntStructure.java
  2. +6
    -2
      src/main/org/apache/tools/ant/taskdefs/CVSPass.java
  3. +3
    -1
      src/main/org/apache/tools/ant/taskdefs/Checksum.java
  4. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
  5. +44
    -27
      src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java
  6. +71
    -38
      src/main/org/apache/tools/bzip2/CBZip2InputStream.java
  7. +223
    -116
      src/main/org/apache/tools/bzip2/CBZip2OutputStream.java
  8. +2
    -1
      src/main/org/apache/tools/bzip2/CRC.java

+ 3
- 1
src/main/org/apache/tools/ant/taskdefs/AntStructure.java View File

@@ -281,7 +281,9 @@ public class AntStructure extends Task {
enum = ih.getAttributes(); enum = ih.getAttributes();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
String attrName = (String) enum.nextElement(); String attrName = (String) enum.nextElement();
if ("id".equals(attrName)) continue;
if ("id".equals(attrName)) {
continue;
}
sb.append(lSep).append(" ").append(attrName).append(" "); sb.append(lSep).append(" ").append(attrName).append(" ");
Class type = ih.getAttributeType(attrName); Class type = ih.getAttributeType(attrName);


+ 6
- 2
src/main/org/apache/tools/ant/taskdefs/CVSPass.java View File

@@ -110,8 +110,12 @@ public class CVSPass extends Task {
* @exception BuildException if someting goes wrong with the build * @exception BuildException if someting goes wrong with the build
*/ */
public final void execute() throws BuildException { public final void execute() throws BuildException {
if(cvsRoot==null)throw new BuildException("cvsroot is required");
if(password==null)throw new BuildException("password is required");
if(cvsRoot==null) {
throw new BuildException("cvsroot is required");
}
if(password==null) {
throw new BuildException("password is required");
}


log("cvsRoot: " + cvsRoot, project.MSG_DEBUG); log("cvsRoot: " + cvsRoot, project.MSG_DEBUG);
log("password: " + password, project.MSG_DEBUG); log("password: " + password, project.MSG_DEBUG);


+ 3
- 1
src/main/org/apache/tools/ant/taskdefs/Checksum.java View File

@@ -353,7 +353,9 @@ public class Checksum extends MatchingTask implements Condition {
fis = new FileInputStream(src); fis = new FileInputStream(src);
DigestInputStream dis = new DigestInputStream(fis, DigestInputStream dis = new DigestInputStream(fis,
messageDigest); messageDigest);
while (dis.read() != -1);
while (dis.read() != -1) {
;
}
dis.close(); dis.close();
fis.close(); fis.close();
fis = null; fis = null;


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/optional/Cab.java View File

@@ -178,8 +178,9 @@ public class Cab extends MatchingTask {
{ {
String file = files.elementAt(i).toString(); String file = files.elementAt(i).toString();
if (new File(baseDir,file).lastModified() > if (new File(baseDir,file).lastModified() >
cabFile.lastModified())
cabFile.lastModified()) {
upToDate = false; upToDate = false;
}
} }
return upToDate; return upToDate;
} }
@@ -282,7 +283,9 @@ public class Cab extends MatchingTask {
Vector files = getFileList(); Vector files = getFileList();
// quick exit if the target is up to date // quick exit if the target is up to date
if (isUpToDate(files)) return;
if (isUpToDate(files)) {
return;
}


log("Building "+ archiveType +": "+ cabFile.getAbsolutePath()); log("Building "+ archiveType +": "+ cabFile.getAbsolutePath());




+ 44
- 27
src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java View File

@@ -176,10 +176,11 @@ public class CSharp
*/ */
protected String getReferencesParameter() { protected String getReferencesParameter() {
//bail on no references //bail on no references
if (notEmpty(_references))
if (notEmpty(_references)) {
return "/reference:"+_references; return "/reference:"+_references;
else
} else {
return null; return null;
}
} }
/** /**
@@ -195,8 +196,9 @@ public class CSharp
*/ */
public void setReferenceFiles(Path path) { public void setReferenceFiles(Path path) {
//demand create pathlist //demand create pathlist
if(_referenceFiles==null)
if(_referenceFiles==null) {
_referenceFiles=new Path(this.project); _referenceFiles=new Path(this.project);
}
_referenceFiles.append(path); _referenceFiles.append(path);
} }
@@ -206,16 +208,18 @@ public class CSharp
*/ */
protected String getReferenceFilesParameter() { protected String getReferenceFilesParameter() {
//bail on no references //bail on no references
if (_references==null)
if (_references==null) {
return null; return null;
}
//iterate through the ref list & generate an entry for each //iterate through the ref list & generate an entry for each
//or just rely on the fact that the toString operator does this, but //or just rely on the fact that the toString operator does this, but
//noting that the separator is ';' on windows, ':' on unix //noting that the separator is ';' on windows, ':' on unix
String refpath=_references.toString(); String refpath=_references.toString();
//bail on no references listed //bail on no references listed
if (refpath.length()==0)
if (refpath.length()==0) {
return null; return null;
}
StringBuffer s=new StringBuffer("/reference:"); StringBuffer s=new StringBuffer("/reference:");
s.append(refpath); s.append(refpath);
@@ -285,8 +289,9 @@ public class CSharp
s.append(DEFAULT_REFERENCE_LIST); s.append(DEFAULT_REFERENCE_LIST);
return new String(s); return new String(s);
} }
else
return null;
else {
return null;
}
} }
/** flag to enable automatic reference inclusion /** flag to enable automatic reference inclusion
@@ -414,10 +419,11 @@ public class CSharp
* @return The DocFile Parameter to CSC * @return The DocFile Parameter to CSC
*/ */
protected String getDocFileParameter() { protected String getDocFileParameter() {
if (_docFile!=null)
if (_docFile!=null) {
return "/doc:"+_docFile.toString(); return "/doc:"+_docFile.toString();
else
} else {
return null; return null;
}
} }
/** warning level: 0-4, with 4 being most verbose /** warning level: 0-4, with 4 being most verbose
@@ -498,10 +504,11 @@ public class CSharp
* @return The MainClass Parameter to CSC * @return The MainClass Parameter to CSC
*/ */
protected String getMainClassParameter(){ protected String getMainClassParameter(){
if (_mainClass!=null && _mainClass.length()!=0)
if (_mainClass!=null && _mainClass.length()!=0) {
return "/main:"+_mainClass; return "/main:"+_mainClass;
else
} else {
return null; return null;
}
} }
/** any extra command options? /** any extra command options?
@@ -532,11 +539,13 @@ public class CSharp
protected String getExtraOptionsParameter() { protected String getExtraOptionsParameter() {
if (_extraOptions!=null && _extraOptions.length()!=0) if (_extraOptions!=null && _extraOptions.length()!=0)
return _extraOptions; return _extraOptions;
else
else {
return null; return null;
}
} }
/** source directory upon which the search pattern is applied
/** source directory upon which the search
} pattern is applied
*/ */
private File _srcDir; private File _srcDir;
@@ -544,7 +553,7 @@ public class CSharp
* Set the source dir to find the files to be compiled * Set the source dir to find the files to be compiled
* @param srcDirName The new SrcDir value * @param srcDirName The new SrcDir value
*/ */
public void setSrcDir(File srcDirName){
public void setSrcDir(File srcDirName) {{
_srcDir = srcDirName; _srcDir = srcDirName;
} }
@@ -578,8 +587,9 @@ public class CSharp
targetType.equals("module") ||targetType.equals("winexe") ) { targetType.equals("module") ||targetType.equals("winexe") ) {
_targetType=targetType; _targetType=targetType;
} }
else
else {
throw new BuildException("targetType " +targetType+" is not a valid type"); throw new BuildException("targetType " +targetType+" is not a valid type");
}
} }
/** /**
@@ -597,10 +607,11 @@ public class CSharp
* @return The TargetType Parameter to CSC * @return The TargetType Parameter to CSC
*/ */
protected String getTargetTypeParameter() { protected String getTargetTypeParameter() {
if (notEmpty(_targetType))
if (notEmpty(_targetType)) {
return "/target:"+_targetType; return "/target:"+_targetType;
else
} else {
return null; return null;
}
} }
/** icon for incorporation into apps /** icon for incorporation into apps
@@ -621,10 +632,11 @@ public class CSharp
* @return The Win32Icon Parameter to CSC * @return The Win32Icon Parameter to CSC
*/ */
protected String getWin32IconParameter() { protected String getWin32IconParameter() {
if (_win32icon!=null)
if (_win32icon!=null) {
return "/win32icon:"+_win32icon.toString(); return "/win32icon:"+_win32icon.toString();
else
} else {
return null; return null;
}
} }
/** icon for incorporation into apps /** icon for incorporation into apps
*/ */
@@ -644,10 +656,11 @@ public class CSharp
* @return The Win32Icon Parameter to CSC * @return The Win32Icon Parameter to CSC
*/ */
protected String getWin32ResParameter() { protected String getWin32ResParameter() {
if (_win32res!=null)
if (_win32res!=null) {
return "/win32res:"+_win32res.toString(); return "/win32res:"+_win32res.toString();
else
} else {
return null; return null;
}
} }
/** /**
@@ -707,10 +720,11 @@ public class CSharp
* @return The Definitions Parameter to CSC * @return The Definitions Parameter to CSC
*/ */
protected String getDefinitionsParameter() { protected String getDefinitionsParameter() {
if (notEmpty(_definitions))
if (notEmpty(_definitions)) {
return "/define:" + _definitions; return "/define:" + _definitions;
else
} else {
return null; return null;
}
} }
/** list of extra modules to refer to /** list of extra modules to refer to
@@ -730,10 +744,11 @@ public class CSharp
* @return The AdditionalModules Parameter to CSC * @return The AdditionalModules Parameter to CSC
*/ */
protected String getAdditionalModulesParameter() { protected String getAdditionalModulesParameter() {
if (notEmpty(_additionalModules))
if (notEmpty(_additionalModules)) {
return "/addmodule:" + _additionalModules; return "/addmodule:" + _additionalModules;
else
} else {
return null; return null;
}
} }
/** output file. If not supplied this is derived from the /** output file. If not supplied this is derived from the
@@ -757,8 +772,9 @@ public class CSharp
File f = _outputFile; File f = _outputFile;
return "/out:"+f.toString(); return "/out:"+f.toString();
} }
else
else {
return null; return null;
}
} }
/** flag to control action on execution trouble /** flag to control action on execution trouble
@@ -816,8 +832,9 @@ public class CSharp
*/ */
public void execute() public void execute()
throws BuildException { throws BuildException {
if (_srcDir == null)
if (_srcDir == null) {
_srcDir=project.resolveFile("."); _srcDir=project.resolveFile(".");
}
NetCommand command=new NetCommand(this,"CSC",csc_exe_name); NetCommand command=new NetCommand(this,"CSC",csc_exe_name);
command.setFailOnError(getFailFailOnError()); command.setFailOnError(getFailFailOnError());


+ 71
- 38
src/main/org/apache/tools/bzip2/CBZip2InputStream.java View File

@@ -89,12 +89,13 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
private void makeMaps() { private void makeMaps() {
int i; int i;
nInUse = 0; nInUse = 0;
for (i = 0; i < 256; i++)
for (i = 0; i < 256; i++) {
if (inUse[i]) { if (inUse[i]) {
seqToUnseq[nInUse] = (char)i; seqToUnseq[nInUse] = (char)i;
unseqToSeq[i] = (char)nInUse; unseqToSeq[i] = (char)nInUse;
nInUse++; nInUse++;
} }
}
} }


/* /*
@@ -249,10 +250,11 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {


storedBlockCRC = bsGetInt32(); storedBlockCRC = bsGetInt32();


if (bsR(1) == 1)
if (bsR(1) == 1) {
blockRandomised = true; blockRandomised = true;
else
} else {
blockRandomised = false; blockRandomised = false;
}


// currBlockNo++; // currBlockNo++;
getAndMoveToFrontDecode(); getAndMoveToFrontDecode();
@@ -264,8 +266,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
private void endBlock() { private void endBlock() {
computedBlockCRC = mCrc.getFinalCRC(); computedBlockCRC = mCrc.getFinalCRC();
/* A bad CRC is considered a fatal error. */ /* A bad CRC is considered a fatal error. */
if (storedBlockCRC != computedBlockCRC)
if (storedBlockCRC != computedBlockCRC) {
crcError(); crcError();
}


computedCombinedCRC = (computedCombinedCRC << 1) computedCombinedCRC = (computedCombinedCRC << 1)
| (computedCombinedCRC >>> 31); | (computedCombinedCRC >>> 31);
@@ -274,8 +277,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {


private void complete() { private void complete() {
storedCombinedCRC = bsGetInt32(); storedCombinedCRC = bsGetInt32();
if (storedCombinedCRC != computedCombinedCRC)
if (storedCombinedCRC != computedCombinedCRC) {
crcError(); crcError();
}


bsFinishedWithStream(); bsFinishedWithStream();
streamEnd = true; streamEnd = true;
@@ -357,23 +361,28 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
int pp, i, j, vec; int pp, i, j, vec;


pp = 0; pp = 0;
for(i = minLen; i <= maxLen; i++)
for(j = 0; j < alphaSize; j++)
for(i = minLen; i <= maxLen; i++) {
for(j = 0; j < alphaSize; j++) {
if (length[j] == i) { if (length[j] == i) {
perm[pp] = j; perm[pp] = j;
pp++; pp++;
};
}
}
};


for(i = 0; i < MAX_CODE_LEN; i++)
for(i = 0; i < MAX_CODE_LEN; i++) {
base[i] = 0; base[i] = 0;
for(i = 0; i < alphaSize; i++)
}
for(i = 0; i < alphaSize; i++) {
base[length[i]+1]++; base[length[i]+1]++;
}


for(i = 1; i < MAX_CODE_LEN; i++) for(i = 1; i < MAX_CODE_LEN; i++)
base[i] += base[i-1]; base[i] += base[i-1];


for (i = 0; i < MAX_CODE_LEN; i++)
for (i = 0; i < MAX_CODE_LEN; i++) {
limit[i] = 0; limit[i] = 0;
}
vec = 0; vec = 0;


for (i = minLen; i <= maxLen; i++) { for (i = minLen; i <= maxLen; i++) {
@@ -381,8 +390,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
limit[i] = vec-1; limit[i] = vec-1;
vec <<= 1; vec <<= 1;
} }
for (i = minLen + 1; i <= maxLen; i++)
for (i = minLen + 1; i <= maxLen; i++) {
base[i] = ((limit[i-1] + 1) << 1) - base[i]; base[i] = ((limit[i-1] + 1) << 1) - base[i];
}
} }


private void recvDecodingTables() { private void recvDecodingTables() {
@@ -392,20 +402,27 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
boolean inUse16[] = new boolean[16]; boolean inUse16[] = new boolean[16];


/* Receive the mapping table */ /* Receive the mapping table */
for (i = 0; i < 16; i++)
if (bsR(1) == 1)
for (i = 0; i < 16; i++) {
if (bsR(1) == 1) {
inUse16[i] = true; inUse16[i] = true;
else
} else {
inUse16[i] = false; inUse16[i] = false;
}
}


for (i = 0; i < 256; i++)
for (i = 0; i < 256; i++) {
inUse[i] = false; inUse[i] = false;
}


for (i = 0; i < 16; i++)
if (inUse16[i])
for (j = 0; j < 16; j++)
if (bsR(1) == 1)
for (i = 0; i < 16; i++) {
if (inUse16[i]) {
for (j = 0; j < 16; j++) {
if (bsR(1) == 1) {
inUse[i * 16 + j] = true; inUse[i * 16 + j] = true;
}
}
}
}


makeMaps(); makeMaps();
alphaSize = nInUse+2; alphaSize = nInUse+2;
@@ -415,8 +432,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
nSelectors = bsR(15); nSelectors = bsR(15);
for (i = 0; i < nSelectors; i++) { for (i = 0; i < nSelectors; i++) {
j = 0; j = 0;
while (bsR(1) == 1)
while (bsR(1) == 1) {
j++; j++;
}
selectorMtf[i] = (char)j; selectorMtf[i] = (char)j;
} }


@@ -424,8 +442,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
{ {
char pos[] = new char[N_GROUPS]; char pos[] = new char[N_GROUPS];
char tmp, v; char tmp, v;
for (v = 0; v < nGroups; v++)
for (v = 0; v < nGroups; v++) {
pos[v] = v; pos[v] = v;
}


for (i = 0; i < nSelectors; i++) { for (i = 0; i < nSelectors; i++) {
v = selectorMtf[i]; v = selectorMtf[i];
@@ -444,10 +463,11 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
int curr = bsR ( 5 ); int curr = bsR ( 5 );
for (i = 0; i < alphaSize; i++) { for (i = 0; i < alphaSize; i++) {
while (bsR(1) == 1) { while (bsR(1) == 1) {
if (bsR(1) == 0)
if (bsR(1) == 0) {
curr++; curr++;
else
} else {
curr--; curr--;
}
} }
len[t][i] = (char)curr; len[t][i] = (char)curr;
} }
@@ -458,10 +478,12 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
minLen = 32; minLen = 32;
maxLen = 0; maxLen = 0;
for (i = 0; i < alphaSize; i++) { for (i = 0; i < alphaSize; i++) {
if (len[t][i] > maxLen)
if (len[t][i] > maxLen) {
maxLen = len[t][i]; maxLen = len[t][i];
if (len[t][i] < minLen)
}
if (len[t][i] < minLen) {
minLen = len[t][i]; minLen = len[t][i];
}
} }
hbCreateDecodeTables(limit[t], base[t], perm[t], len[t], minLen, hbCreateDecodeTables(limit[t], base[t], perm[t], len[t], minLen,
maxLen, alphaSize); maxLen, alphaSize);
@@ -488,11 +510,13 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
in a separate pass, and so saves a block's worth of in a separate pass, and so saves a block's worth of
cache misses. cache misses.
*/ */
for (i = 0; i <= 255; i++)
for (i = 0; i <= 255; i++) {
unzftab[i] = 0; unzftab[i] = 0;
}


for (i = 0; i <= 255; i++)
for (i = 0; i <= 255; i++) {
yy[i] = (char) i; yy[i] = (char) i;
}


last = -1; last = -1;


@@ -536,18 +560,20 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {


while(true) { while(true) {


if (nextSym == EOB)
if (nextSym == EOB) {
break; break;
}


if (nextSym == RUNA || nextSym == RUNB) { if (nextSym == RUNA || nextSym == RUNB) {
char ch; char ch;
int s = -1; int s = -1;
int N = 1; int N = 1;
do { do {
if (nextSym == RUNA)
if (nextSym == RUNA) {
s = s + (0+1) * N; s = s + (0+1) * N;
else if (nextSym == RUNB)
} else if (nextSym == RUNB) {
s = s + (1+1) * N; s = s + (1+1) * N;
}
N = N * 2; N = N * 2;
{ {
int zt, zn, zvec, zj; int zt, zn, zvec, zj;
@@ -598,14 +624,16 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
s--; s--;
}; };


if (last >= limitLast)
if (last >= limitLast) {
blockOverrun(); blockOverrun();
}
continue; continue;
} else { } else {
char tmp; char tmp;
last++; last++;
if (last >= limitLast)
if (last >= limitLast) {
blockOverrun(); blockOverrun();
}


tmp = yy[nextSym-1]; tmp = yy[nextSym-1];
unzftab[seqToUnseq[tmp]]++; unzftab[seqToUnseq[tmp]]++;
@@ -625,8 +653,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
yy[j-2] = yy[j-3]; yy[j-2] = yy[j-3];
yy[j-3] = yy[j-4]; yy[j-3] = yy[j-4];
} }
for (; j > 0; j--)
for (; j > 0; j--) {
yy[j] = yy[j-1]; yy[j] = yy[j-1];
}


yy[0] = tmp; yy[0] = tmp;
{ {
@@ -673,10 +702,12 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
char ch; char ch;


cftab[0] = 0; cftab[0] = 0;
for (i = 1; i <= 256; i++)
for (i = 1; i <= 256; i++) {
cftab[i] = unzftab[i-1]; cftab[i] = unzftab[i-1];
for (i = 1; i <= 256; i++)
}
for (i = 1; i <= 256; i++) {
cftab[i] += cftab[i-1]; cftab[i] += cftab[i-1];
}


for (i = 0; i <= last; i++) { for (i = 0; i <= last; i++) {
ch = (char)ll8[i]; ch = (char)ll8[i];
@@ -755,8 +786,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {
if (rNToGo == 0) { if (rNToGo == 0) {
rNToGo = rNums[rTPos]; rNToGo = rNums[rTPos];
rTPos++; rTPos++;
if(rTPos == 512)
if(rTPos == 512) {
rTPos = 0; rTPos = 0;
}
} }
rNToGo--; rNToGo--;
z ^= ((rNToGo == 1) ? 1 : 0); z ^= ((rNToGo == 1) ? 1 : 0);
@@ -824,8 +856,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants {


blockSize100k = newSize100k; blockSize100k = newSize100k;


if(newSize100k == 0)
if(newSize100k == 0) {
return; return;
}


int n = baseBlockSize * newSize100k; int n = baseBlockSize * newSize100k;
ll8 = new char[n]; ll8 = new char[n];


+ 223
- 116
src/main/org/apache/tools/bzip2/CBZip2OutputStream.java View File

@@ -96,12 +96,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
private void makeMaps() { private void makeMaps() {
int i; int i;
nInUse = 0; nInUse = 0;
for (i = 0; i < 256; i++)
for (i = 0; i < 256; i++) {
if (inUse[i]) { if (inUse[i]) {
seqToUnseq[nInUse] = (char)i; seqToUnseq[nInUse] = (char)i;
unseqToSeq[i] = (char)nInUse; unseqToSeq[i] = (char)nInUse;
nInUse++; nInUse++;
} }
}
} }


protected static void hbMakeCodeLengths(char[] len, int[] freq, protected static void hbMakeCodeLengths(char[] len, int[] freq,
@@ -117,8 +118,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
int weight[] = new int[MAX_ALPHA_SIZE * 2]; int weight[] = new int[MAX_ALPHA_SIZE * 2];
int parent[] = new int[MAX_ALPHA_SIZE * 2]; int parent[] = new int[MAX_ALPHA_SIZE * 2];


for (i = 0; i < alphaSize; i++)
for (i = 0; i < alphaSize; i++) {
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8; weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
}


while (true) { while (true) {
nNodes = alphaSize; nNodes = alphaSize;
@@ -143,8 +145,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
heap[zz] = tmp; heap[zz] = tmp;
} }
} }
if (!(nHeap < (MAX_ALPHA_SIZE+2)))
if (!(nHeap < (MAX_ALPHA_SIZE+2))) {
panic(); panic();
}


while (nHeap > 1) { while (nHeap > 1) {
n1 = heap[1]; n1 = heap[1];
@@ -156,13 +159,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
tmp = heap[zz]; tmp = heap[zz];
while (true) { while (true) {
yy = zz << 1; yy = zz << 1;
if (yy > nHeap)
if (yy > nHeap) {
break; break;
}
if (yy < nHeap && if (yy < nHeap &&
weight[heap[yy+1]] < weight[heap[yy]])
weight[heap[yy+1]] < weight[heap[yy]]) {
yy++; yy++;
if (weight[tmp] < weight[heap[yy]])
}
if (weight[tmp] < weight[heap[yy]]) {
break; break;
}
heap[zz] = heap[yy]; heap[zz] = heap[yy];
zz = yy; zz = yy;
} }
@@ -177,13 +183,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
tmp = heap[zz]; tmp = heap[zz];
while (true) { while (true) {
yy = zz << 1; yy = zz << 1;
if (yy > nHeap)
if (yy > nHeap) {
break; break;
}
if (yy < nHeap && if (yy < nHeap &&
weight[heap[yy+1]] < weight[heap[yy]])
weight[heap[yy+1]] < weight[heap[yy]]) {
yy++; yy++;
if (weight[tmp] < weight[heap[yy]])
}
if (weight[tmp] < weight[heap[yy]]) {
break; break;
}
heap[zz] = heap[yy]; heap[zz] = heap[yy];
zz = yy; zz = yy;
} }
@@ -213,8 +222,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
heap[zz] = tmp; heap[zz] = tmp;
} }
} }
if (!(nNodes < (MAX_ALPHA_SIZE * 2)))
if (!(nNodes < (MAX_ALPHA_SIZE * 2))) {
panic(); panic();
}


tooLong = false; tooLong = false;
for (i = 1; i <= alphaSize; i++) { for (i = 1; i <= alphaSize; i++) {
@@ -225,12 +235,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
j++; j++;
} }
len[i-1] = (char)j; len[i-1] = (char)j;
if (j > maxLen)
if (j > maxLen) {
tooLong = true; tooLong = true;
}
} }


if (! tooLong)
if (! tooLong) {
break; break;
}


for (i = 1; i < alphaSize; i++) { for (i = 1; i < alphaSize; i++) {
j = weight[i] >> 8; j = weight[i] >> 8;
@@ -403,11 +415,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
} }


public void close() throws IOException { public void close() throws IOException {
if(closed)
if(closed) {
return; return;
}


if(runLength > 0)
if(runLength > 0) {
writeRun(); writeRun();
}
currentChar = -1; currentChar = -1;
endBlock(); endBlock();
endCompression(); endCompression();
@@ -445,8 +459,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
last = -1; last = -1;
// ch = 0; // ch = 0;


for(int i = 0; i < 256; i++)
for(int i = 0; i < 256; i++) {
inUse[i] = false; inUse[i] = false;
}


/* 20 is just a paranoia constant */ /* 20 is just a paranoia constant */
allowableBlockSize = baseBlockSize * blockSize100k - 20; allowableBlockSize = baseBlockSize * blockSize100k - 20;
@@ -521,11 +536,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {


vec = 0; vec = 0;
for (n = minLen; n <= maxLen; n++) { for (n = minLen; n <= maxLen; n++) {
for (i = 0; i < alphaSize; i++)
for (i = 0; i < alphaSize; i++) {
if (length[i] == n) { if (length[i] == n) {
code[i] = vec; code[i] = vec;
vec++; vec++;
};
}
};
vec <<= 1; vec <<= 1;
} }
} }
@@ -593,24 +609,28 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
int nGroups, nBytes; int nGroups, nBytes;


alphaSize = nInUse + 2; alphaSize = nInUse + 2;
for (t = 0; t < N_GROUPS; t++)
for (v = 0; v < alphaSize; v++)
for (t = 0; t < N_GROUPS; t++) {
for (v = 0; v < alphaSize; v++) {
len[t][v] = (char)GREATER_ICOST; len[t][v] = (char)GREATER_ICOST;
}
}


/* Decide how many coding tables to use */ /* Decide how many coding tables to use */
if (nMTF <= 0)
if (nMTF <= 0) {
panic(); panic();
}


if (nMTF < 200)
if (nMTF < 200) {
nGroups = 2; nGroups = 2;
else if (nMTF < 600)
} else if (nMTF < 600) {
nGroups = 3; nGroups = 3;
else if (nMTF < 1200)
} else if (nMTF < 1200) {
nGroups = 4; nGroups = 4;
else if (nMTF < 2400)
} else if (nMTF < 2400) {
nGroups = 5; nGroups = 5;
else
} else {
nGroups = 6; nGroups = 6;
}


/* Generate an initial set of coding tables */ { /* Generate an initial set of coding tables */ {
int nPart, remF, tFreq, aFreq; int nPart, remF, tFreq, aFreq;
@@ -633,11 +653,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
ge--; ge--;
} }


for (v = 0; v < alphaSize; v++)
if (v >= gs && v <= ge)
for (v = 0; v < alphaSize; v++) {
if (v >= gs && v <= ge) {
len[nPart-1][v] = (char)LESSER_ICOST; len[nPart-1][v] = (char)LESSER_ICOST;
else
} else {
len[nPart-1][v] = (char)GREATER_ICOST; len[nPart-1][v] = (char)GREATER_ICOST;
}
}


nPart--; nPart--;
gs = ge+1; gs = ge+1;
@@ -652,12 +674,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
Iterate up to N_ITERS times to improve the tables. Iterate up to N_ITERS times to improve the tables.
*/ */
for (iter = 0; iter < N_ITERS; iter++) { for (iter = 0; iter < N_ITERS; iter++) {
for (t = 0; t < nGroups; t++)
for (t = 0; t < nGroups; t++) {
fave[t] = 0; fave[t] = 0;
}


for (t = 0; t < nGroups; t++) for (t = 0; t < nGroups; t++)
for (v = 0; v < alphaSize; v++)
for (v = 0; v < alphaSize; v++) {
rfreq[t][v] = 0; rfreq[t][v] = 0;
}


nSelectors = 0; nSelectors = 0;
totc = 0; totc = 0;
@@ -665,18 +689,22 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
while (true) { while (true) {


/* Set group start & end marks. */ /* Set group start & end marks. */
if (gs >= nMTF)
if (gs >= nMTF) {
break; break;
}
ge = gs + G_SIZE - 1; ge = gs + G_SIZE - 1;
if (ge >= nMTF)
if (ge >= nMTF) {
ge = nMTF-1; ge = nMTF-1;
}


/* /*
Calculate the cost of this group as coded Calculate the cost of this group as coded
by each of the coding tables. by each of the coding tables.
*/ */
for (t = 0; t < nGroups; t++)
cost[t] = 0;
for (t = 0; t < nGroups; t++) { {
cost[t
}] = 0;
}


if (nGroups == 6) { if (nGroups == 6) {
short cost0, cost1, cost2, cost3, cost4, cost5; short cost0, cost1, cost2, cost3, cost4, cost5;
@@ -699,8 +727,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
} else { } else {
for (i = gs; i <= ge; i++) { for (i = gs; i <= ge; i++) {
short icv = szptr[i]; short icv = szptr[i];
for (t = 0; t < nGroups; t++)
for (t = 0; t < nGroups; t++) {
cost[t] += len[t][icv]; cost[t] += len[t][icv];
}
} }
} }


@@ -710,11 +739,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
*/ */
bc = 999999999; bc = 999999999;
bt = -1; bt = -1;
for (t = 0; t < nGroups; t++)
for (t = 0; t < nGroups; t++) {
if (cost[t] < bc) { if (cost[t] < bc) {
bc = cost[t]; bc = cost[t];
bt = t; bt = t;
};
}
};
totc += bc; totc += bc;
fave[bt]++; fave[bt]++;
selector[nSelectors] = (char)bt; selector[nSelectors] = (char)bt;
@@ -723,8 +753,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
/* /*
Increment the symbol frequencies for the selected table. Increment the symbol frequencies for the selected table.
*/ */
for (i = gs; i <= ge; i++)
for (i = gs; i <= ge; i++) {
rfreq[bt][szptr[i]]++; rfreq[bt][szptr[i]]++;
}


gs = ge+1; gs = ge+1;
} }
@@ -732,8 +763,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
/* /*
Recompute the tables based on the accumulated frequencies. Recompute the tables based on the accumulated frequencies.
*/ */
for (t = 0; t < nGroups; t++)
for (t = 0; t < nGroups; t++) {
hbMakeCodeLengths(len[t], rfreq[t], alphaSize, 20); hbMakeCodeLengths(len[t], rfreq[t], alphaSize, 20);
}
} }


rfreq = null; rfreq = null;
@@ -742,16 +774,18 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {


if (!(nGroups < 8)) if (!(nGroups < 8))
panic(); panic();
if (!(nSelectors < 32768 && nSelectors <= (2 + (900000 / G_SIZE))))
if (!(nSelectors < 32768 && nSelectors <= (2 + (900000 / G_SIZE)))) {
panic(); panic();
}




/* Compute MTF values for the selectors. */ /* Compute MTF values for the selectors. */
{ {
char pos[] = new char[N_GROUPS]; char pos[] = new char[N_GROUPS];
char ll_i, tmp2, tmp; char ll_i, tmp2, tmp;
for (i = 0; i < nGroups; i++)
for (i = 0; i < nGroups; i++) {
pos[i] = (char)i; pos[i] = (char)i;
}
for (i = 0; i < nSelectors; i++) { for (i = 0; i < nSelectors; i++) {
ll_i = selector[i]; ll_i = selector[i];
j = 0; j = 0;
@@ -763,7 +797,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
pos[j] = tmp2; pos[j] = tmp2;
} }
pos[0] = tmp; pos[0] = tmp;
selectorMtf[i] = (char)j;
} selectorMtf[i] = (char) {j;
} }
} }


@@ -774,15 +809,19 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
minLen = 32; minLen = 32;
maxLen = 0; maxLen = 0;
for (i = 0; i < alphaSize; i++) { for (i = 0; i < alphaSize; i++) {
if (len[t][i] > maxLen)
if (len[t][i] > maxLen) {
maxLen = len[t][i]; maxLen = len[t][i];
if (len[t][i] < minLen)
}
if (len[t][i] < minLen) {
minLen = len[t][i]; minLen = len[t][i];
}
} }
if (maxLen > 20)
if (maxLen > 20) {
panic(); panic();
if (minLen < 1)
}
if (minLen < 1) {
panic(); panic();
}
hbAssignCodes(code[t], len[t], minLen, maxLen, alphaSize); hbAssignCodes(code[t], len[t], minLen, maxLen, alphaSize);
} }


@@ -791,25 +830,33 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
boolean inUse16[] = new boolean[16]; boolean inUse16[] = new boolean[16];
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
inUse16[i] = false; inUse16[i] = false;
for (j = 0; j < 16; j++)
if (inUse[i * 16 + j])
for (j = 0; j < 16; j++) {
if (inUse[i * 16 + j]) {
inUse16[i] = true; inUse16[i] = true;
}
}
} }


nBytes = bytesOut; nBytes = bytesOut;
for (i = 0; i < 16; i++)
if (inUse16[i])
for (i = 0; i < 16; i++) {
if (inUse16[i]) {
bsW(1,1); bsW(1,1);
else
} else {
bsW(1,0); bsW(1,0);
}
}


for (i = 0; i < 16; i++)
if (inUse16[i])
for (j = 0; j < 16; j++)
if (inUse[i * 16 + j])
for (i = 0; i < 16; i++) {
if (inUse16[i]) {
for (j = 0; j < 16; j++) {
if (inUse[i * 16 + j]) {
bsW(1,1); bsW(1,1);
else
} else {
bsW(1,0); bsW(1,0);
}
}
}
}


} }


@@ -818,8 +865,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
bsW ( 3, nGroups ); bsW ( 3, nGroups );
bsW ( 15, nSelectors ); bsW ( 15, nSelectors );
for (i = 0; i < nSelectors; i++) { for (i = 0; i < nSelectors; i++) {
for (j = 0; j < selectorMtf[i]; j++)
for (j = 0; j < selectorMtf[i]; j++) {
bsW(1,1); bsW(1,1);
}
bsW(1,0); bsW(1,0);
} }


@@ -847,11 +895,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
selCtr = 0; selCtr = 0;
gs = 0; gs = 0;
while (true) { while (true) {
if (gs >= nMTF)
if (gs >= nMTF) {
break; break;
}
ge = gs + G_SIZE - 1; ge = gs + G_SIZE - 1;
if (ge >= nMTF)
if (ge >= nMTF) {
ge = nMTF-1; ge = nMTF-1;
}
for (i = gs; i <= ge; i++) { for (i = gs; i <= ge; i++) {
bsW(len [selector[selCtr]] [szptr[i]], bsW(len [selector[selCtr]] [szptr[i]],
code [selector[selCtr]] [szptr[i]] ); code [selector[selCtr]] [szptr[i]] );
@@ -860,8 +910,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
gs = ge+1; gs = ge+1;
selCtr++; selCtr++;
} }
if (!(selCtr == nSelectors))
if (!(selCtr == nSelectors)) {
panic(); panic();
}
} }


private void moveToFrontCodeAndSend () throws IOException { private void moveToFrontCodeAndSend () throws IOException {
@@ -877,12 +928,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
int v; int v;


bigN = hi - lo + 1; bigN = hi - lo + 1;
if (bigN < 2)
if (bigN < 2) {
return; return;
}


hp = 0; hp = 0;
while (incs[hp] < bigN)
while (incs[hp] < bigN) {
hp++; hp++;
}
hp--; hp--;


for (; hp >= 0; hp--) { for (; hp >= 0; hp--) {
@@ -891,49 +944,56 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
i = lo + h; i = lo + h;
while (true) { while (true) {
/* copy 1 */ /* copy 1 */
if (i > hi)
if (i > hi) {
break; break;
}
v = zptr[i]; v = zptr[i];
j = i; j = i;
while ( fullGtU ( zptr[j-h]+d, v+d ) ) { while ( fullGtU ( zptr[j-h]+d, v+d ) ) {
zptr[j] = zptr[j-h]; zptr[j] = zptr[j-h];
j = j - h; j = j - h;
if (j <= (lo + h - 1))
if (j <= (lo + h - 1)) {
break; break;
}
} }
zptr[j] = v; zptr[j] = v;
i++; i++;


/* copy 2 */ /* copy 2 */
if (i > hi)
if (i > hi) {
break; break;
}
v = zptr[i]; v = zptr[i];
j = i; j = i;
while ( fullGtU ( zptr[j-h]+d, v+d ) ) { while ( fullGtU ( zptr[j-h]+d, v+d ) ) {
zptr[j] = zptr[j-h]; zptr[j] = zptr[j-h];
j = j - h; j = j - h;
if (j <= (lo + h - 1))
if (j <= (lo + h - 1)) {
break; break;
}
} }
zptr[j] = v; zptr[j] = v;
i++; i++;


/* copy 3 */ /* copy 3 */
if (i > hi)
if (i > hi) {
break; break;
}
v = zptr[i]; v = zptr[i];
j = i; j = i;
while ( fullGtU ( zptr[j-h]+d, v+d ) ) { while ( fullGtU ( zptr[j-h]+d, v+d ) ) {
zptr[j] = zptr[j-h]; zptr[j] = zptr[j-h];
j = j - h; j = j - h;
if (j <= (lo + h - 1))
if (j <= (lo + h - 1)) {
break; break;
}
} }
zptr[j] = v; zptr[j] = v;
i++; i++;


if (workDone > workLimit && firstAttempt)
if (workDone > workLimit && firstAttempt) {
return; return;
}
} }
} }
} }
@@ -962,8 +1022,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
b = c; b = c;
c = t; c = t;
} }
if (a > b)
if (a > b) {
b = a; b = a;
}
return b; return b;
} }


@@ -977,8 +1038,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
int unLo, unHi, ltLo, gtHi, med, n, m; int unLo, unHi, ltLo, gtHi, med, n, m;
int sp, lo, hi, d; int sp, lo, hi, d;
StackElem[] stack = new StackElem[QSORT_STACK_SIZE]; StackElem[] stack = new StackElem[QSORT_STACK_SIZE];
for(int count = 0; count < QSORT_STACK_SIZE; count++)
for(int count = 0; count < QSORT_STACK_SIZE; count++) {
stack[count] = new StackElem(); stack[count] = new StackElem();
}


sp = 0; sp = 0;


@@ -988,8 +1050,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
sp++; sp++;


while (sp > 0) { while (sp > 0) {
if (sp >= QSORT_STACK_SIZE)
if (sp >= QSORT_STACK_SIZE) {
panic(); panic();
}


sp--; sp--;
lo = stack[sp].ll; lo = stack[sp].ll;
@@ -998,8 +1061,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {


if (hi - lo < SMALL_THRESH || d > DEPTH_THRESH) { if (hi - lo < SMALL_THRESH || d > DEPTH_THRESH) {
simpleSort(lo, hi, d); simpleSort(lo, hi, d);
if (workDone > workLimit && firstAttempt)
if (workDone > workLimit && firstAttempt) {
return; return;
}
continue; continue;
} }


@@ -1012,8 +1076,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {


while (true) { while (true) {
while (true) { while (true) {
if (unLo > unHi)
if (unLo > unHi) {
break; break;
}
n = ((int)block[zptr[unLo]+d + 1]) - med; n = ((int)block[zptr[unLo]+d + 1]) - med;
if (n == 0) { if (n == 0) {
int temp = 0; int temp = 0;
@@ -1024,13 +1089,15 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
unLo++; unLo++;
continue; continue;
}; };
if (n > 0)
if (n > 0) {
break; break;
}
unLo++; unLo++;
} }
while (true) { while (true) {
if (unLo > unHi)
if (unLo > unHi) {
break; break;
}
n = ((int)block[zptr[unHi]+d + 1]) - med; n = ((int)block[zptr[unHi]+d + 1]) - med;
if (n == 0) { if (n == 0) {
int temp = 0; int temp = 0;
@@ -1041,12 +1108,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
unHi--; unHi--;
continue; continue;
}; };
if (n < 0)
if (n < 0) {
break; break;
}
unHi--; unHi--;
} }
if (unLo > unHi)
if (unLo > unHi) {
break; break;
}
int temp = 0; int temp = 0;
temp = zptr[unLo]; temp = zptr[unLo];
zptr[unLo] = zptr[unHi]; zptr[unLo] = zptr[unHi];
@@ -1103,10 +1172,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
*/ */


// if (verbosity >= 4) fprintf ( stderr, " sort initialise ...\n" ); // if (verbosity >= 4) fprintf ( stderr, " sort initialise ...\n" );
for (i = 0; i < NUM_OVERSHOOT_BYTES; i++)
for (i = 0; i < NUM_OVERSHOOT_BYTES; i++) {
block[last + i + 2] = block[(i % (last + 1)) + 1]; block[last + i + 2] = block[(i % (last + 1)) + 1];
for (i = 0; i <= last + NUM_OVERSHOOT_BYTES; i++)
}
for (i = 0; i <= last + NUM_OVERSHOOT_BYTES; i++) {
quadrant[i] = 0; quadrant[i] = 0;
}


block[0] = (char)(block[last + 1]); block[0] = (char)(block[last + 1]);


@@ -1115,8 +1186,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
Use simpleSort(), since the full sorting mechanism Use simpleSort(), since the full sorting mechanism
has quite a large constant overhead. has quite a large constant overhead.
*/ */
for (i = 0; i <= last; i++)
for (i = 0; i <= last; i++) {
zptr[i] = i; zptr[i] = i;
}
firstAttempt = false; firstAttempt = false;
workDone = workLimit = 0; workDone = workLimit = 0;
simpleSort ( 0, last, 0 ); simpleSort ( 0, last, 0 );
@@ -1125,8 +1197,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
for (i = 0; i <= 255; i++) for (i = 0; i <= 255; i++)
bigDone[i] = false; bigDone[i] = false;


for (i = 0; i <= 65536; i++)
for (i = 0; i <= 65536; i++) {
ftab[i] = 0; ftab[i] = 0;
}


c1 = block[0]; c1 = block[0];
for (i = 0; i <= last; i++) { for (i = 0; i <= last; i++) {
@@ -1135,8 +1208,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
c1 = c2; c1 = c2;
} }


for (i = 1; i <= 65536; i++)
for (i = 1; i <= 65536; i++) {
ftab[i] += ftab[i - 1]; ftab[i] += ftab[i - 1];
}


c1 = block[1]; c1 = block[1];
for (i = 0; i < last; i++) { for (i = 0; i < last; i++) {
@@ -1157,14 +1231,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
big bucket. big bucket.
*/ */


for (i = 0; i <= 255; i++)
for (i = 0; i <= 255; i++) {
runningOrder[i] = i; runningOrder[i] = i;
}


{ {
int vv; int vv;
int h = 1; int h = 1;
do
do {
h = 3 * h + 1; h = 3 * h + 1;
}
while (h <= 256); while (h <= 256);
do { do {
h = h / 3; h = h / 3;
@@ -1172,12 +1248,15 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
vv = runningOrder[i]; vv = runningOrder[i];
j = i; j = i;
while ((ftab[((runningOrder[j-h])+1) << 8] while ((ftab[((runningOrder[j-h])+1) << 8]
- ftab[(runningOrder[j-h]) << 8]) >
- ftab[(runningOrder[j-h]) {
} << 8]) >
(ftab[((vv)+1) << 8] - ftab[(vv) << 8])) { (ftab[((vv)+1) << 8] - ftab[(vv) << 8])) {
runningOrder[j] = runningOrder[j-h]; runningOrder[j] = runningOrder[j-h];
j = j - h; j = j - h;
if (j <= (h - 1))
if (j <= (h - 1)) {
break; break;
}
} }
runningOrder[j] = vv; runningOrder[j] = vv;
} }
@@ -1209,8 +1288,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
if (hi > lo) { if (hi > lo) {
qSort3 ( lo, hi, 2 ); qSort3 ( lo, hi, 2 );
numQSorted += ( hi - lo + 1 ); numQSorted += ( hi - lo + 1 );
if (workDone > workLimit && firstAttempt)
if (workDone > workLimit && firstAttempt) {
return; return;
}
} }
ftab[sb] |= SETMASK; ftab[sb] |= SETMASK;
} }
@@ -1231,27 +1311,31 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
int bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart; int bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
int shifts = 0; int shifts = 0;


while ((bbSize >> shifts) > 65534)
while ((bbSize >> shifts) > 65534) {
shifts++; shifts++;
}


for (j = 0; j < bbSize; j++) { for (j = 0; j < bbSize; j++) {
int a2update = zptr[bbStart + j]; int a2update = zptr[bbStart + j];
int qVal = (j >> shifts); int qVal = (j >> shifts);
quadrant[a2update] = qVal; quadrant[a2update] = qVal;
if (a2update < NUM_OVERSHOOT_BYTES)
if (a2update < NUM_OVERSHOOT_BYTES) {
quadrant[a2update + last + 1] = qVal; quadrant[a2update + last + 1] = qVal;
}
} }


if (! ( ((bbSize-1) >> shifts) <= 65535 ))
if (! ( ((bbSize-1) >> shifts) <= 65535 )) {
panic(); panic();
}
} }


/* /*
Now scan this big bucket so as to synthesise the Now scan this big bucket so as to synthesise the
sorted order for small buckets [t, ss] for all t != ss. sorted order for small buckets [t, ss] for all t != ss.
*/ */
for (j = 0; j <= 255; j++)
for (j = 0; j <= 255; j++) {
copy[j] = ftab[(j << 8) + ss] & CLEARMASK; copy[j] = ftab[(j << 8) + ss] & CLEARMASK;
}


for (j = ftab[ss << 8] & CLEARMASK; for (j = ftab[ss << 8] & CLEARMASK;
j < (ftab[(ss+1) << 8] & CLEARMASK); j++) { j < (ftab[(ss+1) << 8] & CLEARMASK); j++) {
@@ -1262,8 +1346,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
} }
} }


for (j = 0; j <= 255; j++)
for (j = 0; j <= 255; j++) {
ftab[(j << 8) + ss] |= SETMASK; ftab[(j << 8) + ss] |= SETMASK;
}
} }
} }
} }
@@ -1272,15 +1357,17 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
int i; int i;
int rNToGo = 0; int rNToGo = 0;
int rTPos = 0; int rTPos = 0;
for (i = 0; i < 256; i++)
for (i = 0; i < 256; i++) {
inUse[i] = false; inUse[i] = false;
}


for (i = 0; i <= last; i++) { for (i = 0; i <= last; i++) {
if (rNToGo == 0) { if (rNToGo == 0) {
rNToGo = (char)rNums[rTPos]; rNToGo = (char)rNums[rTPos];
rTPos++; rTPos++;
if(rTPos == 512)
if(rTPos == 512) {
rTPos = 0; rTPos = 0;
}
} }
rNToGo--; rNToGo--;
block[i + 1] ^= ((rNToGo == 1) ? 1 : 0); block[i + 1] ^= ((rNToGo == 1) ? 1 : 0);
@@ -1310,14 +1397,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
} }


origPtr = -1; origPtr = -1;
for (i = 0; i <= last; i++)
for (i = 0; i <= last; i++) {
if (zptr[i] == 0) { if (zptr[i] == 0) {
origPtr = i; origPtr = i;
break; break;
};
}
};


if (origPtr == -1)
if (origPtr == -1) {
panic(); panic();
}
} }


private boolean fullGtU(int i1, int i2) { private boolean fullGtU(int i1, int i2) {
@@ -1327,43 +1416,49 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {


c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
i1++; i1++;
i2++; i2++;


c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
i1++; i1++;
i2++; i2++;


c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
i1++; i1++;
i2++; i2++;


c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
i1++; i1++;
i2++; i2++;


c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
i1++; i1++;
i2++; i2++;


c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
i1++; i1++;
i2++; i2++;


@@ -1372,45 +1467,53 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
do { do {
c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
s1 = quadrant[i1]; s1 = quadrant[i1];
s2 = quadrant[i2]; s2 = quadrant[i2];
if (s1 != s2)
if (s1 != s2) {
return (s1 > s2); return (s1 > s2);
}
i1++; i1++;
i2++; i2++;


c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
s1 = quadrant[i1]; s1 = quadrant[i1];
s2 = quadrant[i2]; s2 = quadrant[i2];
if (s1 != s2)
if (s1 != s2) {
return (s1 > s2); return (s1 > s2);
}
i1++; i1++;
i2++; i2++;


c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
s1 = quadrant[i1]; s1 = quadrant[i1];
s2 = quadrant[i2]; s2 = quadrant[i2];
if (s1 != s2)
if (s1 != s2) {
return (s1 > s2); return (s1 > s2);
}
i1++; i1++;
i2++; i2++;


c1 = block[i1 + 1]; c1 = block[i1 + 1];
c2 = block[i2 + 1]; c2 = block[i2 + 1];
if (c1 != c2)
if (c1 != c2) {
return (c1 > c2); return (c1 > c2);
}
s1 = quadrant[i1]; s1 = quadrant[i1];
s2 = quadrant[i2]; s2 = quadrant[i2];
if (s1 != s2)
if (s1 != s2) {
return (s1 > s2); return (s1 > s2);
}
i1++; i1++;
i2++; i2++;


@@ -1481,13 +1584,15 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
makeMaps(); makeMaps();
EOB = nInUse+1; EOB = nInUse+1;


for (i = 0; i <= EOB; i++)
for (i = 0; i <= EOB; i++) {
mtfFreq[i] = 0; mtfFreq[i] = 0;
}


wr = 0; wr = 0;
zPend = 0; zPend = 0;
for (i = 0; i < nInUse; i++)
for (i = 0; i < nInUse; i++) {
yy[i] = (char) i; yy[i] = (char) i;
}




for (i = 0; i <= last; i++) { for (i = 0; i <= last; i++) {
@@ -1523,8 +1628,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
mtfFreq[RUNB]++; mtfFreq[RUNB]++;
break; break;
}; };
if (zPend < 2)
if (zPend < 2) {
break; break;
}
zPend = (zPend - 2) / 2; zPend = (zPend - 2) / 2;
}; };
zPend = 0; zPend = 0;
@@ -1550,8 +1656,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants {
mtfFreq[RUNB]++; mtfFreq[RUNB]++;
break; break;
} }
if (zPend < 2)
if (zPend < 2) {
break; break;
}
zPend = (zPend - 2) / 2; zPend = (zPend - 2) / 2;
} }
} }


+ 2
- 1
src/main/org/apache/tools/bzip2/CRC.java View File

@@ -156,8 +156,9 @@ class CRC {


void updateCRC(int inCh) { void updateCRC(int inCh) {
int temp = (globalCrc >> 24) ^ inCh; int temp = (globalCrc >> 24) ^ inCh;
if(temp < 0)
if(temp < 0) {
temp = 256 + temp; temp = 256 + temp;
}
globalCrc = (globalCrc << 8) ^ CRC.crc32Table[temp]; globalCrc = (globalCrc << 8) ^ CRC.crc32Table[temp];
} }




Loading…
Cancel
Save