diff --git a/src/main/org/apache/tools/ant/taskdefs/AntStructure.java b/src/main/org/apache/tools/ant/taskdefs/AntStructure.java index f10444f51..31d6714a7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/AntStructure.java +++ b/src/main/org/apache/tools/ant/taskdefs/AntStructure.java @@ -281,7 +281,9 @@ public class AntStructure extends Task { enum = ih.getAttributes(); while (enum.hasMoreElements()) { String attrName = (String) enum.nextElement(); - if ("id".equals(attrName)) continue; + if ("id".equals(attrName)) { + continue; + } sb.append(lSep).append(" ").append(attrName).append(" "); Class type = ih.getAttributeType(attrName); diff --git a/src/main/org/apache/tools/ant/taskdefs/CVSPass.java b/src/main/org/apache/tools/ant/taskdefs/CVSPass.java index c74519187..361d2e526 100644 --- a/src/main/org/apache/tools/ant/taskdefs/CVSPass.java +++ b/src/main/org/apache/tools/ant/taskdefs/CVSPass.java @@ -110,8 +110,12 @@ public class CVSPass extends Task { * @exception BuildException if someting goes wrong with the build */ 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("password: " + password, project.MSG_DEBUG); diff --git a/src/main/org/apache/tools/ant/taskdefs/Checksum.java b/src/main/org/apache/tools/ant/taskdefs/Checksum.java index 7068ae52c..8e3d70ad4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Checksum.java +++ b/src/main/org/apache/tools/ant/taskdefs/Checksum.java @@ -353,7 +353,9 @@ public class Checksum extends MatchingTask implements Condition { fis = new FileInputStream(src); DigestInputStream dis = new DigestInputStream(fis, messageDigest); - while (dis.read() != -1); + while (dis.read() != -1) { + ; + } dis.close(); fis.close(); fis = null; diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java index 8a0c1eebf..81e5a4633 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java @@ -178,8 +178,9 @@ public class Cab extends MatchingTask { { String file = files.elementAt(i).toString(); if (new File(baseDir,file).lastModified() > - cabFile.lastModified()) + cabFile.lastModified()) { upToDate = false; + } } return upToDate; } @@ -282,7 +283,9 @@ public class Cab extends MatchingTask { Vector files = getFileList(); // quick exit if the target is up to date - if (isUpToDate(files)) return; + if (isUpToDate(files)) { + return; + } log("Building "+ archiveType +": "+ cabFile.getAbsolutePath()); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java index 4ebb349e5..b8b5fdd0d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/dotnet/CSharp.java @@ -176,10 +176,11 @@ public class CSharp */ protected String getReferencesParameter() { //bail on no references - if (notEmpty(_references)) + if (notEmpty(_references)) { return "/reference:"+_references; - else + } else { return null; + } } /** @@ -195,8 +196,9 @@ public class CSharp */ public void setReferenceFiles(Path path) { //demand create pathlist - if(_referenceFiles==null) + if(_referenceFiles==null) { _referenceFiles=new Path(this.project); + } _referenceFiles.append(path); } @@ -206,16 +208,18 @@ public class CSharp */ protected String getReferenceFilesParameter() { //bail on no references - if (_references==null) + if (_references==null) { return null; + } //iterate through the ref list & generate an entry for each //or just rely on the fact that the toString operator does this, but //noting that the separator is ';' on windows, ':' on unix String refpath=_references.toString(); //bail on no references listed - if (refpath.length()==0) + if (refpath.length()==0) { return null; + } StringBuffer s=new StringBuffer("/reference:"); s.append(refpath); @@ -285,8 +289,9 @@ public class CSharp s.append(DEFAULT_REFERENCE_LIST); return new String(s); } - else - return null; + else { + return null; + } } /** flag to enable automatic reference inclusion @@ -414,10 +419,11 @@ public class CSharp * @return The DocFile Parameter to CSC */ protected String getDocFileParameter() { - if (_docFile!=null) + if (_docFile!=null) { return "/doc:"+_docFile.toString(); - else + } else { return null; + } } /** warning level: 0-4, with 4 being most verbose @@ -498,10 +504,11 @@ public class CSharp * @return The MainClass Parameter to CSC */ protected String getMainClassParameter(){ - if (_mainClass!=null && _mainClass.length()!=0) + if (_mainClass!=null && _mainClass.length()!=0) { return "/main:"+_mainClass; - else + } else { return null; + } } /** any extra command options? @@ -532,11 +539,13 @@ public class CSharp protected String getExtraOptionsParameter() { if (_extraOptions!=null && _extraOptions.length()!=0) return _extraOptions; - else + else { return null; + } } - /** source directory upon which the search pattern is applied + /** source directory upon which the search + } pattern is applied */ private File _srcDir; @@ -544,7 +553,7 @@ public class CSharp * Set the source dir to find the files to be compiled * @param srcDirName The new SrcDir value */ - public void setSrcDir(File srcDirName){ + public void setSrcDir(File srcDirName) {{ _srcDir = srcDirName; } @@ -578,8 +587,9 @@ public class CSharp targetType.equals("module") ||targetType.equals("winexe") ) { _targetType=targetType; } - else + else { throw new BuildException("targetType " +targetType+" is not a valid type"); + } } /** @@ -597,10 +607,11 @@ public class CSharp * @return The TargetType Parameter to CSC */ protected String getTargetTypeParameter() { - if (notEmpty(_targetType)) + if (notEmpty(_targetType)) { return "/target:"+_targetType; - else + } else { return null; + } } /** icon for incorporation into apps @@ -621,10 +632,11 @@ public class CSharp * @return The Win32Icon Parameter to CSC */ protected String getWin32IconParameter() { - if (_win32icon!=null) + if (_win32icon!=null) { return "/win32icon:"+_win32icon.toString(); - else + } else { return null; + } } /** icon for incorporation into apps */ @@ -644,10 +656,11 @@ public class CSharp * @return The Win32Icon Parameter to CSC */ protected String getWin32ResParameter() { - if (_win32res!=null) + if (_win32res!=null) { return "/win32res:"+_win32res.toString(); - else + } else { return null; + } } /** @@ -707,10 +720,11 @@ public class CSharp * @return The Definitions Parameter to CSC */ protected String getDefinitionsParameter() { - if (notEmpty(_definitions)) + if (notEmpty(_definitions)) { return "/define:" + _definitions; - else + } else { return null; + } } /** list of extra modules to refer to @@ -730,10 +744,11 @@ public class CSharp * @return The AdditionalModules Parameter to CSC */ protected String getAdditionalModulesParameter() { - if (notEmpty(_additionalModules)) + if (notEmpty(_additionalModules)) { return "/addmodule:" + _additionalModules; - else + } else { return null; + } } /** output file. If not supplied this is derived from the @@ -757,8 +772,9 @@ public class CSharp File f = _outputFile; return "/out:"+f.toString(); } - else + else { return null; + } } /** flag to control action on execution trouble @@ -816,8 +832,9 @@ public class CSharp */ public void execute() throws BuildException { - if (_srcDir == null) + if (_srcDir == null) { _srcDir=project.resolveFile("."); + } NetCommand command=new NetCommand(this,"CSC",csc_exe_name); command.setFailOnError(getFailFailOnError()); diff --git a/src/main/org/apache/tools/bzip2/CBZip2InputStream.java b/src/main/org/apache/tools/bzip2/CBZip2InputStream.java index fbf1f173b..cd9fa3725 100644 --- a/src/main/org/apache/tools/bzip2/CBZip2InputStream.java +++ b/src/main/org/apache/tools/bzip2/CBZip2InputStream.java @@ -89,12 +89,13 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { private void makeMaps() { int i; nInUse = 0; - for (i = 0; i < 256; i++) + for (i = 0; i < 256; i++) { if (inUse[i]) { seqToUnseq[nInUse] = (char)i; unseqToSeq[i] = (char)nInUse; nInUse++; } + } } /* @@ -249,10 +250,11 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { storedBlockCRC = bsGetInt32(); - if (bsR(1) == 1) + if (bsR(1) == 1) { blockRandomised = true; - else + } else { blockRandomised = false; + } // currBlockNo++; getAndMoveToFrontDecode(); @@ -264,8 +266,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { private void endBlock() { computedBlockCRC = mCrc.getFinalCRC(); /* A bad CRC is considered a fatal error. */ - if (storedBlockCRC != computedBlockCRC) + if (storedBlockCRC != computedBlockCRC) { crcError(); + } computedCombinedCRC = (computedCombinedCRC << 1) | (computedCombinedCRC >>> 31); @@ -274,8 +277,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { private void complete() { storedCombinedCRC = bsGetInt32(); - if (storedCombinedCRC != computedCombinedCRC) + if (storedCombinedCRC != computedCombinedCRC) { crcError(); + } bsFinishedWithStream(); streamEnd = true; @@ -357,23 +361,28 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { int pp, i, j, vec; 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) { perm[pp] = j; pp++; - }; + } + } + }; - for(i = 0; i < MAX_CODE_LEN; i++) + for(i = 0; i < MAX_CODE_LEN; i++) { base[i] = 0; - for(i = 0; i < alphaSize; i++) + } + for(i = 0; i < alphaSize; i++) { base[length[i]+1]++; + } for(i = 1; i < MAX_CODE_LEN; i++) base[i] += base[i-1]; - for (i = 0; i < MAX_CODE_LEN; i++) + for (i = 0; i < MAX_CODE_LEN; i++) { limit[i] = 0; + } vec = 0; for (i = minLen; i <= maxLen; i++) { @@ -381,8 +390,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { limit[i] = 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]; + } } private void recvDecodingTables() { @@ -392,20 +402,27 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { boolean inUse16[] = new boolean[16]; /* 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; - else + } else { inUse16[i] = false; + } + } - for (i = 0; i < 256; i++) + for (i = 0; i < 256; i++) { 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; + } + } + } + } makeMaps(); alphaSize = nInUse+2; @@ -415,8 +432,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { nSelectors = bsR(15); for (i = 0; i < nSelectors; i++) { j = 0; - while (bsR(1) == 1) + while (bsR(1) == 1) { j++; + } selectorMtf[i] = (char)j; } @@ -424,8 +442,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { { char pos[] = new char[N_GROUPS]; char tmp, v; - for (v = 0; v < nGroups; v++) + for (v = 0; v < nGroups; v++) { pos[v] = v; + } for (i = 0; i < nSelectors; i++) { v = selectorMtf[i]; @@ -444,10 +463,11 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { int curr = bsR ( 5 ); for (i = 0; i < alphaSize; i++) { while (bsR(1) == 1) { - if (bsR(1) == 0) + if (bsR(1) == 0) { curr++; - else + } else { curr--; + } } len[t][i] = (char)curr; } @@ -458,10 +478,12 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { minLen = 32; maxLen = 0; for (i = 0; i < alphaSize; i++) { - if (len[t][i] > maxLen) + if (len[t][i] > maxLen) { maxLen = len[t][i]; - if (len[t][i] < minLen) + } + if (len[t][i] < minLen) { minLen = len[t][i]; + } } hbCreateDecodeTables(limit[t], base[t], perm[t], len[t], minLen, 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 cache misses. */ - for (i = 0; i <= 255; i++) + for (i = 0; i <= 255; i++) { unzftab[i] = 0; + } - for (i = 0; i <= 255; i++) + for (i = 0; i <= 255; i++) { yy[i] = (char) i; + } last = -1; @@ -536,18 +560,20 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { while(true) { - if (nextSym == EOB) + if (nextSym == EOB) { break; + } if (nextSym == RUNA || nextSym == RUNB) { char ch; int s = -1; int N = 1; do { - if (nextSym == RUNA) + if (nextSym == RUNA) { s = s + (0+1) * N; - else if (nextSym == RUNB) + } else if (nextSym == RUNB) { s = s + (1+1) * N; + } N = N * 2; { int zt, zn, zvec, zj; @@ -598,14 +624,16 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { s--; }; - if (last >= limitLast) + if (last >= limitLast) { blockOverrun(); + } continue; } else { char tmp; last++; - if (last >= limitLast) + if (last >= limitLast) { blockOverrun(); + } tmp = yy[nextSym-1]; unzftab[seqToUnseq[tmp]]++; @@ -625,8 +653,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { yy[j-2] = yy[j-3]; yy[j-3] = yy[j-4]; } - for (; j > 0; j--) + for (; j > 0; j--) { yy[j] = yy[j-1]; + } yy[0] = tmp; { @@ -673,10 +702,12 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { char ch; cftab[0] = 0; - for (i = 1; i <= 256; i++) + for (i = 1; i <= 256; i++) { cftab[i] = unzftab[i-1]; - for (i = 1; i <= 256; i++) + } + for (i = 1; i <= 256; i++) { cftab[i] += cftab[i-1]; + } for (i = 0; i <= last; i++) { ch = (char)ll8[i]; @@ -755,8 +786,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { if (rNToGo == 0) { rNToGo = rNums[rTPos]; rTPos++; - if(rTPos == 512) + if(rTPos == 512) { rTPos = 0; + } } rNToGo--; z ^= ((rNToGo == 1) ? 1 : 0); @@ -824,8 +856,9 @@ public class CBZip2InputStream extends InputStream implements BZip2Constants { blockSize100k = newSize100k; - if(newSize100k == 0) + if(newSize100k == 0) { return; + } int n = baseBlockSize * newSize100k; ll8 = new char[n]; diff --git a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java index 2663323e8..3b3f8bbd3 100644 --- a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java +++ b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java @@ -96,12 +96,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { private void makeMaps() { int i; nInUse = 0; - for (i = 0; i < 256; i++) + for (i = 0; i < 256; i++) { if (inUse[i]) { seqToUnseq[nInUse] = (char)i; unseqToSeq[i] = (char)nInUse; nInUse++; } + } } 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 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; + } while (true) { nNodes = alphaSize; @@ -143,8 +145,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { heap[zz] = tmp; } } - if (!(nHeap < (MAX_ALPHA_SIZE+2))) + if (!(nHeap < (MAX_ALPHA_SIZE+2))) { panic(); + } while (nHeap > 1) { n1 = heap[1]; @@ -156,13 +159,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { tmp = heap[zz]; while (true) { yy = zz << 1; - if (yy > nHeap) + if (yy > nHeap) { break; + } if (yy < nHeap && - weight[heap[yy+1]] < weight[heap[yy]]) + weight[heap[yy+1]] < weight[heap[yy]]) { yy++; - if (weight[tmp] < weight[heap[yy]]) + } + if (weight[tmp] < weight[heap[yy]]) { break; + } heap[zz] = heap[yy]; zz = yy; } @@ -177,13 +183,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { tmp = heap[zz]; while (true) { yy = zz << 1; - if (yy > nHeap) + if (yy > nHeap) { break; + } if (yy < nHeap && - weight[heap[yy+1]] < weight[heap[yy]]) + weight[heap[yy+1]] < weight[heap[yy]]) { yy++; - if (weight[tmp] < weight[heap[yy]]) + } + if (weight[tmp] < weight[heap[yy]]) { break; + } heap[zz] = heap[yy]; zz = yy; } @@ -213,8 +222,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { heap[zz] = tmp; } } - if (!(nNodes < (MAX_ALPHA_SIZE * 2))) + if (!(nNodes < (MAX_ALPHA_SIZE * 2))) { panic(); + } tooLong = false; for (i = 1; i <= alphaSize; i++) { @@ -225,12 +235,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { j++; } len[i-1] = (char)j; - if (j > maxLen) + if (j > maxLen) { tooLong = true; + } } - if (! tooLong) + if (! tooLong) { break; + } for (i = 1; i < alphaSize; i++) { j = weight[i] >> 8; @@ -403,11 +415,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } public void close() throws IOException { - if(closed) + if(closed) { return; + } - if(runLength > 0) + if(runLength > 0) { writeRun(); + } currentChar = -1; endBlock(); endCompression(); @@ -445,8 +459,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { last = -1; // ch = 0; - for(int i = 0; i < 256; i++) + for(int i = 0; i < 256; i++) { inUse[i] = false; + } /* 20 is just a paranoia constant */ allowableBlockSize = baseBlockSize * blockSize100k - 20; @@ -521,11 +536,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { vec = 0; for (n = minLen; n <= maxLen; n++) { - for (i = 0; i < alphaSize; i++) + for (i = 0; i < alphaSize; i++) { if (length[i] == n) { code[i] = vec; vec++; - }; + } + }; vec <<= 1; } } @@ -593,24 +609,28 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int nGroups, nBytes; 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; + } + } /* Decide how many coding tables to use */ - if (nMTF <= 0) + if (nMTF <= 0) { panic(); + } - if (nMTF < 200) + if (nMTF < 200) { nGroups = 2; - else if (nMTF < 600) + } else if (nMTF < 600) { nGroups = 3; - else if (nMTF < 1200) + } else if (nMTF < 1200) { nGroups = 4; - else if (nMTF < 2400) + } else if (nMTF < 2400) { nGroups = 5; - else + } else { nGroups = 6; + } /* Generate an initial set of coding tables */ { int nPart, remF, tFreq, aFreq; @@ -633,11 +653,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { 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; - else + } else { len[nPart-1][v] = (char)GREATER_ICOST; + } + } nPart--; gs = ge+1; @@ -652,12 +674,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { Iterate up to N_ITERS times to improve the tables. */ for (iter = 0; iter < N_ITERS; iter++) { - for (t = 0; t < nGroups; t++) + for (t = 0; t < nGroups; t++) { fave[t] = 0; + } for (t = 0; t < nGroups; t++) - for (v = 0; v < alphaSize; v++) + for (v = 0; v < alphaSize; v++) { rfreq[t][v] = 0; + } nSelectors = 0; totc = 0; @@ -665,18 +689,22 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { while (true) { /* Set group start & end marks. */ - if (gs >= nMTF) + if (gs >= nMTF) { break; + } ge = gs + G_SIZE - 1; - if (ge >= nMTF) + if (ge >= nMTF) { ge = nMTF-1; + } /* Calculate the cost of this group as coded 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) { short cost0, cost1, cost2, cost3, cost4, cost5; @@ -699,8 +727,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } else { for (i = gs; i <= ge; i++) { short icv = szptr[i]; - for (t = 0; t < nGroups; t++) + for (t = 0; t < nGroups; t++) { cost[t] += len[t][icv]; + } } } @@ -710,11 +739,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { */ bc = 999999999; bt = -1; - for (t = 0; t < nGroups; t++) + for (t = 0; t < nGroups; t++) { if (cost[t] < bc) { bc = cost[t]; bt = t; - }; + } + }; totc += bc; fave[bt]++; selector[nSelectors] = (char)bt; @@ -723,8 +753,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { /* Increment the symbol frequencies for the selected table. */ - for (i = gs; i <= ge; i++) + for (i = gs; i <= ge; i++) { rfreq[bt][szptr[i]]++; + } gs = ge+1; } @@ -732,8 +763,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { /* 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); + } } rfreq = null; @@ -742,16 +774,18 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { if (!(nGroups < 8)) panic(); - if (!(nSelectors < 32768 && nSelectors <= (2 + (900000 / G_SIZE)))) + if (!(nSelectors < 32768 && nSelectors <= (2 + (900000 / G_SIZE)))) { panic(); + } /* Compute MTF values for the selectors. */ { char pos[] = new char[N_GROUPS]; char ll_i, tmp2, tmp; - for (i = 0; i < nGroups; i++) + for (i = 0; i < nGroups; i++) { pos[i] = (char)i; + } for (i = 0; i < nSelectors; i++) { ll_i = selector[i]; j = 0; @@ -763,7 +797,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { pos[j] = tmp2; } pos[0] = tmp; - selectorMtf[i] = (char)j; + + } selectorMtf[i] = (char) {j; } } @@ -774,15 +809,19 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { minLen = 32; maxLen = 0; for (i = 0; i < alphaSize; i++) { - if (len[t][i] > maxLen) + if (len[t][i] > maxLen) { maxLen = len[t][i]; - if (len[t][i] < minLen) + } + if (len[t][i] < minLen) { minLen = len[t][i]; + } } - if (maxLen > 20) + if (maxLen > 20) { panic(); - if (minLen < 1) + } + if (minLen < 1) { panic(); + } hbAssignCodes(code[t], len[t], minLen, maxLen, alphaSize); } @@ -791,25 +830,33 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { boolean inUse16[] = new boolean[16]; for (i = 0; i < 16; i++) { 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; + } + } } nBytes = bytesOut; - for (i = 0; i < 16; i++) - if (inUse16[i]) + for (i = 0; i < 16; i++) { + if (inUse16[i]) { bsW(1,1); - else + } else { 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); - else + } else { bsW(1,0); + } + } + } + } } @@ -818,8 +865,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { bsW ( 3, nGroups ); bsW ( 15, nSelectors ); 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,0); } @@ -847,11 +895,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { selCtr = 0; gs = 0; while (true) { - if (gs >= nMTF) + if (gs >= nMTF) { break; + } ge = gs + G_SIZE - 1; - if (ge >= nMTF) + if (ge >= nMTF) { ge = nMTF-1; + } for (i = gs; i <= ge; i++) { bsW(len [selector[selCtr]] [szptr[i]], code [selector[selCtr]] [szptr[i]] ); @@ -860,8 +910,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { gs = ge+1; selCtr++; } - if (!(selCtr == nSelectors)) + if (!(selCtr == nSelectors)) { panic(); + } } private void moveToFrontCodeAndSend () throws IOException { @@ -877,12 +928,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int v; bigN = hi - lo + 1; - if (bigN < 2) + if (bigN < 2) { return; + } hp = 0; - while (incs[hp] < bigN) + while (incs[hp] < bigN) { hp++; + } hp--; for (; hp >= 0; hp--) { @@ -891,49 +944,56 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { i = lo + h; while (true) { /* copy 1 */ - if (i > hi) + if (i > hi) { break; + } v = zptr[i]; j = i; while ( fullGtU ( zptr[j-h]+d, v+d ) ) { zptr[j] = zptr[j-h]; j = j - h; - if (j <= (lo + h - 1)) + if (j <= (lo + h - 1)) { break; + } } zptr[j] = v; i++; /* copy 2 */ - if (i > hi) + if (i > hi) { break; + } v = zptr[i]; j = i; while ( fullGtU ( zptr[j-h]+d, v+d ) ) { zptr[j] = zptr[j-h]; j = j - h; - if (j <= (lo + h - 1)) + if (j <= (lo + h - 1)) { break; + } } zptr[j] = v; i++; /* copy 3 */ - if (i > hi) + if (i > hi) { break; + } v = zptr[i]; j = i; while ( fullGtU ( zptr[j-h]+d, v+d ) ) { zptr[j] = zptr[j-h]; j = j - h; - if (j <= (lo + h - 1)) + if (j <= (lo + h - 1)) { break; + } } zptr[j] = v; i++; - if (workDone > workLimit && firstAttempt) + if (workDone > workLimit && firstAttempt) { return; + } } } } @@ -962,8 +1022,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { b = c; c = t; } - if (a > b) + if (a > b) { b = a; + } return b; } @@ -977,8 +1038,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int unLo, unHi, ltLo, gtHi, med, n, m; int sp, lo, hi, d; 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(); + } sp = 0; @@ -988,8 +1050,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { sp++; while (sp > 0) { - if (sp >= QSORT_STACK_SIZE) + if (sp >= QSORT_STACK_SIZE) { panic(); + } sp--; lo = stack[sp].ll; @@ -998,8 +1061,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { if (hi - lo < SMALL_THRESH || d > DEPTH_THRESH) { simpleSort(lo, hi, d); - if (workDone > workLimit && firstAttempt) + if (workDone > workLimit && firstAttempt) { return; + } continue; } @@ -1012,8 +1076,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { while (true) { while (true) { - if (unLo > unHi) + if (unLo > unHi) { break; + } n = ((int)block[zptr[unLo]+d + 1]) - med; if (n == 0) { int temp = 0; @@ -1024,13 +1089,15 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { unLo++; continue; }; - if (n > 0) + if (n > 0) { break; + } unLo++; } while (true) { - if (unLo > unHi) + if (unLo > unHi) { break; + } n = ((int)block[zptr[unHi]+d + 1]) - med; if (n == 0) { int temp = 0; @@ -1041,12 +1108,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { unHi--; continue; }; - if (n < 0) + if (n < 0) { break; + } unHi--; } - if (unLo > unHi) + if (unLo > unHi) { break; + } int temp = 0; temp = zptr[unLo]; zptr[unLo] = zptr[unHi]; @@ -1103,10 +1172,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { */ // 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]; - for (i = 0; i <= last + NUM_OVERSHOOT_BYTES; i++) + } + for (i = 0; i <= last + NUM_OVERSHOOT_BYTES; i++) { quadrant[i] = 0; + } block[0] = (char)(block[last + 1]); @@ -1115,8 +1186,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { Use simpleSort(), since the full sorting mechanism has quite a large constant overhead. */ - for (i = 0; i <= last; i++) + for (i = 0; i <= last; i++) { zptr[i] = i; + } firstAttempt = false; workDone = workLimit = 0; simpleSort ( 0, last, 0 ); @@ -1125,8 +1197,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { for (i = 0; i <= 255; i++) bigDone[i] = false; - for (i = 0; i <= 65536; i++) + for (i = 0; i <= 65536; i++) { ftab[i] = 0; + } c1 = block[0]; for (i = 0; i <= last; i++) { @@ -1135,8 +1208,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { c1 = c2; } - for (i = 1; i <= 65536; i++) + for (i = 1; i <= 65536; i++) { ftab[i] += ftab[i - 1]; + } c1 = block[1]; for (i = 0; i < last; i++) { @@ -1157,14 +1231,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { big bucket. */ - for (i = 0; i <= 255; i++) + for (i = 0; i <= 255; i++) { runningOrder[i] = i; + } { int vv; int h = 1; - do + do { h = 3 * h + 1; + } while (h <= 256); do { h = h / 3; @@ -1172,12 +1248,15 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { vv = runningOrder[i]; j = i; while ((ftab[((runningOrder[j-h])+1) << 8] - - ftab[(runningOrder[j-h]) << 8]) > + - ftab[(runningOrder[j-h]) { + + } << 8]) > (ftab[((vv)+1) << 8] - ftab[(vv) << 8])) { runningOrder[j] = runningOrder[j-h]; j = j - h; - if (j <= (h - 1)) + if (j <= (h - 1)) { break; + } } runningOrder[j] = vv; } @@ -1209,8 +1288,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { if (hi > lo) { qSort3 ( lo, hi, 2 ); numQSorted += ( hi - lo + 1 ); - if (workDone > workLimit && firstAttempt) + if (workDone > workLimit && firstAttempt) { return; + } } ftab[sb] |= SETMASK; } @@ -1231,27 +1311,31 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart; int shifts = 0; - while ((bbSize >> shifts) > 65534) + while ((bbSize >> shifts) > 65534) { shifts++; + } for (j = 0; j < bbSize; j++) { int a2update = zptr[bbStart + j]; int qVal = (j >> shifts); quadrant[a2update] = qVal; - if (a2update < NUM_OVERSHOOT_BYTES) + if (a2update < NUM_OVERSHOOT_BYTES) { quadrant[a2update + last + 1] = qVal; + } } - if (! ( ((bbSize-1) >> shifts) <= 65535 )) + if (! ( ((bbSize-1) >> shifts) <= 65535 )) { panic(); + } } /* Now scan this big bucket so as to synthesise the 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; + } for (j = ftab[ss << 8] & CLEARMASK; 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; + } } } } @@ -1272,15 +1357,17 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { int i; int rNToGo = 0; int rTPos = 0; - for (i = 0; i < 256; i++) + for (i = 0; i < 256; i++) { inUse[i] = false; + } for (i = 0; i <= last; i++) { if (rNToGo == 0) { rNToGo = (char)rNums[rTPos]; rTPos++; - if(rTPos == 512) + if(rTPos == 512) { rTPos = 0; + } } rNToGo--; block[i + 1] ^= ((rNToGo == 1) ? 1 : 0); @@ -1310,14 +1397,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { } origPtr = -1; - for (i = 0; i <= last; i++) + for (i = 0; i <= last; i++) { if (zptr[i] == 0) { origPtr = i; break; - }; + } + }; - if (origPtr == -1) + if (origPtr == -1) { panic(); + } } private boolean fullGtU(int i1, int i2) { @@ -1327,43 +1416,49 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } i1++; i2++; c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } i1++; i2++; c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } i1++; i2++; c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } i1++; i2++; c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } i1++; i2++; c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } i1++; i2++; @@ -1372,45 +1467,53 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { do { c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) + if (s1 != s2) { return (s1 > s2); + } i1++; i2++; c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) + if (s1 != s2) { return (s1 > s2); + } i1++; i2++; c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) + if (s1 != s2) { return (s1 > s2); + } i1++; i2++; c1 = block[i1 + 1]; c2 = block[i2 + 1]; - if (c1 != c2) + if (c1 != c2) { return (c1 > c2); + } s1 = quadrant[i1]; s2 = quadrant[i2]; - if (s1 != s2) + if (s1 != s2) { return (s1 > s2); + } i1++; i2++; @@ -1481,13 +1584,15 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { makeMaps(); EOB = nInUse+1; - for (i = 0; i <= EOB; i++) + for (i = 0; i <= EOB; i++) { mtfFreq[i] = 0; + } wr = 0; zPend = 0; - for (i = 0; i < nInUse; i++) + for (i = 0; i < nInUse; i++) { yy[i] = (char) i; + } for (i = 0; i <= last; i++) { @@ -1523,8 +1628,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { mtfFreq[RUNB]++; break; }; - if (zPend < 2) + if (zPend < 2) { break; + } zPend = (zPend - 2) / 2; }; zPend = 0; @@ -1550,8 +1656,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { mtfFreq[RUNB]++; break; } - if (zPend < 2) + if (zPend < 2) { break; + } zPend = (zPend - 2) / 2; } } diff --git a/src/main/org/apache/tools/bzip2/CRC.java b/src/main/org/apache/tools/bzip2/CRC.java index 77608864b..75eac4800 100644 --- a/src/main/org/apache/tools/bzip2/CRC.java +++ b/src/main/org/apache/tools/bzip2/CRC.java @@ -156,8 +156,9 @@ class CRC { void updateCRC(int inCh) { int temp = (globalCrc >> 24) ^ inCh; - if(temp < 0) + if(temp < 0) { temp = 256 + temp; + } globalCrc = (globalCrc << 8) ^ CRC.crc32Table[temp]; }