diff --git a/proposal/myrmidon/src/java/org/apache/aut/bzip2/CBZip2OutputStream.java b/proposal/myrmidon/src/java/org/apache/aut/bzip2/CBZip2OutputStream.java
index eb7e8db37..143e9bd6f 100644
--- a/proposal/myrmidon/src/java/org/apache/aut/bzip2/CBZip2OutputStream.java
+++ b/proposal/myrmidon/src/java/org/apache/aut/bzip2/CBZip2OutputStream.java
@@ -12,19 +12,20 @@ import java.io.OutputStream;
/**
* An output stream that compresses into the BZip2 format (without the file
- * header chars) into another stream.
+ * header chars) into another stream. TODO: Update to BZip2 1.0.1
*
- * @author Keiron Liddle TODO: Update to
- * BZip2 1.0.1
+ * @author Keiron Liddle
*/
-public class CBZip2OutputStream extends OutputStream implements BZip2Constants
+public class CBZip2OutputStream
+ extends OutputStream
+ implements BZip2Constants
{
- protected final static int SETMASK = ( 1 << 21 );
- protected final static int CLEARMASK = ( ~SETMASK );
- protected final static int GREATER_ICOST = 15;
- protected final static int LESSER_ICOST = 0;
- protected final static int SMALL_THRESH = 20;
- protected final static int DEPTH_THRESH = 10;
+ private final static int SETMASK = ( 1 << 21 );
+ private final static int CLEARMASK = ( ~SETMASK );
+ private final static int GREATER_ICOST = 15;
+ private final static int LESSER_ICOST = 0;
+ private final static int SMALL_THRESH = 20;
+ private final static int DEPTH_THRESH = 10;
/*
* If you are ever unlucky/improbable enough
@@ -34,18 +35,19 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
* stack go above 27 elems, so the following
* limit seems very generous.
*/
- protected final static int QSORT_STACK_SIZE = 1000;
- CRC mCrc = new CRC();
+ private final static int QSORT_STACK_SIZE = 1000;
- private boolean inUse[] = new boolean[ 256 ];
+ private CRC m_crc = new CRC();
- private char seqToUnseq[] = new char[ 256 ];
- private char unseqToSeq[] = new char[ 256 ];
+ private boolean[] m_inUse = new boolean[ 256 ];
- private char selector[] = new char[ MAX_SELECTORS ];
- private char selectorMtf[] = new char[ MAX_SELECTORS ];
+ private char[] seqToUnseq = new char[ 256 ];
+ private char[] unseqToSeq = new char[ 256 ];
- private int mtfFreq[] = new int[ MAX_ALPHA_SIZE ];
+ private char[] selector = new char[ MAX_SELECTORS ];
+ private char[] selectorMtf = new char[ MAX_SELECTORS ];
+
+ private int[] mtfFreq = new int[ MAX_ALPHA_SIZE ];
private int currentChar = -1;
private int runLength = 0;
@@ -58,9 +60,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
* because the number of elems to sort is
* usually small, typically <= 20.
*/
- private int incs[] = {1, 4, 13, 40, 121, 364, 1093, 3280,
- 9841, 29524, 88573, 265720,
- 797161, 2391484};
+ private int[] incs = new int[]
+ {
+ 1, 4, 13, 40, 121, 364, 1093, 3280,
+ 9841, 29524, 88573, 265720,
+ 797161, 2391484
+ };
boolean blockRandomised;
@@ -88,19 +93,19 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
private int allowableBlockSize;
- private char block[];
+ private char[] block;
private int blockCRC, combinedCRC;
private OutputStream bsStream;
private boolean firstAttempt;
- private int ftab[];
+ private int[] ftab;
private int nBlocksRandomised;
private int nInUse;
private int nMTF;
- private int quadrant[];
- private short szptr[];
+ private int[] quadrant;
+ private short[] szptr;
private int workDone;
/*
@@ -110,7 +115,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
*/
private int workFactor;
private int workLimit;
- private int zptr[];
+ private int[] zptr;
public CBZip2OutputStream( OutputStream inStream )
throws IOException
@@ -183,11 +188,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
int k;
boolean tooLong;
- int heap[] = new int[ MAX_ALPHA_SIZE + 2 ];
- int weight[] = new int[ MAX_ALPHA_SIZE * 2 ];
- int parent[] = new int[ MAX_ALPHA_SIZE * 2 ];
+ int[] heap = new int[ MAX_ALPHA_SIZE + 2 ];
+ 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;
}
@@ -218,7 +224,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
heap[ zz ] = tmp;
}
}
- if( !( nHeap < ( MAX_ALPHA_SIZE + 2 ) ) ) {
+ if( !( nHeap < ( MAX_ALPHA_SIZE + 2 ) ) )
+ {
panic();
}
@@ -236,14 +243,17 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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 ];
@@ -263,14 +273,17 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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 ];
@@ -304,7 +317,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
heap[ zz ] = tmp;
}
}
- if( !( nNodes < ( MAX_ALPHA_SIZE * 2 ) ) ) {
+ if( !( nNodes < ( MAX_ALPHA_SIZE * 2 ) ) )
+ {
panic();
}
@@ -319,12 +333,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;
}
@@ -346,11 +362,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;
@@ -533,7 +551,8 @@ 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;
@@ -542,7 +561,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
}
;
- if( origPtr == -1 ) {
+ if( origPtr == -1 )
+ {
panic();
}
}
@@ -550,7 +570,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
private void endBlock()
throws IOException
{
- blockCRC = mCrc.getFinalCRC();
+ blockCRC = m_crc.getFinalCRC();
combinedCRC = ( combinedCRC << 1 ) | ( combinedCRC >>> 31 );
combinedCRC ^= blockCRC;
@@ -635,7 +655,8 @@ 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++;
@@ -643,7 +664,8 @@ 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++;
@@ -651,7 +673,8 @@ 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++;
@@ -659,7 +682,8 @@ 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++;
@@ -667,7 +691,8 @@ 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++;
@@ -675,7 +700,8 @@ 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++;
@@ -687,12 +713,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
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++;
@@ -700,12 +728,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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++;
@@ -713,12 +743,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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++;
@@ -726,12 +758,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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++;
@@ -759,7 +793,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
private void generateMTFValues()
{
- char yy[] = new char[ 256 ];
+ char[] yy = new char[ 256 ];
int i;
int j;
char tmp;
@@ -771,13 +805,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;
}
@@ -824,7 +860,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
break;
}
;
- if( zPend < 2 ) {
+ if( zPend < 2 )
+ {
break;
}
zPend = ( zPend - 2 ) / 2;
@@ -856,7 +893,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
mtfFreq[ RUNB ]++;
break;
}
- if( zPend < 2 ) {
+ if( zPend < 2 )
+ {
break;
}
zPend = ( zPend - 2 ) / 2;
@@ -880,7 +918,8 @@ 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;
@@ -895,12 +934,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
private void initBlock()
{
// blockNo++;
- mCrc.initialiseCRC();
+ m_crc.initialiseCRC();
last = -1;
// ch = 0;
- for( int i = 0; i < 256; i++ ) {
- inUse[ i ] = false;
+ for( int i = 0; i < 256; i++ )
+ {
+ m_inUse[ i ] = false;
}
/*
@@ -932,9 +972,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
int j;
int ss;
int sb;
- int runningOrder[] = new int[ 256 ];
- int copy[] = new int[ 256 ];
- boolean bigDone[] = new boolean[ 256 ];
+ int[] runningOrder = new int[ 256 ];
+ int[] copy = new int[ 256 ];
+ boolean[] bigDone = new boolean[ 256 ];
int c1;
int c2;
int numQSorted;
@@ -945,10 +985,12 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
* set up the overshoot area for block.
*/
// 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;
}
@@ -960,7 +1002,8 @@ 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;
@@ -970,11 +1013,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
else
{
numQSorted = 0;
- for( i = 0; i <= 255; i++ ) {
+ for( i = 0; i <= 255; i++ )
+ {
bigDone[ i ] = false;
}
- for( i = 0; i <= 65536; i++ ) {
+ for( i = 0; i <= 65536; i++ )
+ {
ftab[ i ] = 0;
}
@@ -986,7 +1031,8 @@ 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 ];
}
@@ -1009,16 +1055,17 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
* Calculate the running order, from smallest to largest
* 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 );
+ } while( h <= 256 );
do
{
h = h / 3;
@@ -1032,7 +1079,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
runningOrder[ j ] = runningOrder[ j - h ];
j = j - h;
- if( j <= ( h - 1 ) ) {
+ if( j <= ( h - 1 ) )
+ {
break;
}
}
@@ -1070,7 +1118,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
qSort3( lo, hi, 2 );
numQSorted += ( hi - lo + 1 );
- if( workDone > workLimit && firstAttempt ) {
+ if( workDone > workLimit && firstAttempt )
+ {
return;
}
}
@@ -1094,7 +1143,8 @@ 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++;
}
@@ -1103,12 +1153,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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();
}
}
@@ -1117,7 +1169,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
* 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;
}
@@ -1132,7 +1185,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
}
}
- for( j = 0; j <= 255; j++ ) {
+ for( j = 0; j <= 255; j++ )
+ {
ftab[ ( j << 8 ) + ss ] |= SETMASK;
}
}
@@ -1143,8 +1197,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
int i;
nInUse = 0;
- for( i = 0; i < 256; i++ ) {
- if( inUse[ i ] )
+ for( i = 0; i < 256; i++ )
+ {
+ if( m_inUse[ i ] )
{
seqToUnseq[ nInUse ] = (char)i;
unseqToSeq[ i ] = (char)nInUse;
@@ -1168,7 +1223,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
b = c;
c = t;
}
- if( a > b ) {
+ if( a > b )
+ {
b = a;
}
return b;
@@ -1196,7 +1252,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
int hi;
int 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();
}
@@ -1209,7 +1266,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
while( sp > 0 )
{
- if( sp >= QSORT_STACK_SIZE ) {
+ if( sp >= QSORT_STACK_SIZE )
+ {
panic();
}
@@ -1221,7 +1279,8 @@ 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;
@@ -1238,7 +1297,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
while( true )
{
- if( unLo > unHi ) {
+ if( unLo > unHi )
+ {
break;
}
n = ( (int)block[ zptr[ unLo ] + d + 1 ] ) - med;
@@ -1253,14 +1313,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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;
@@ -1275,12 +1337,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
continue;
}
;
- if( n < 0 ) {
+ if( n < 0 )
+ {
break;
}
unHi--;
}
- if( unLo > unHi ) {
+ if( unLo > unHi )
+ {
break;
}
int temp = 0;
@@ -1330,8 +1394,9 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
int i;
int rNToGo = 0;
int rTPos = 0;
- for( i = 0; i < 256; i++ ) {
- inUse[ i ] = false;
+ for( i = 0; i < 256; i++ )
+ {
+ m_inUse[ i ] = false;
}
for( i = 0; i <= last; i++ )
@@ -1340,7 +1405,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
rNToGo = (char)RAND_NUMS[ rTPos ];
rTPos++;
- if( rTPos == 512 ) {
+ if( rTPos == 512 )
+ {
rTPos = 0;
}
}
@@ -1349,14 +1415,14 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
// handle 16 bit signed numbers
block[ i + 1 ] &= 0xFF;
- inUse[ block[ i + 1 ] ] = true;
+ m_inUse[ block[ i + 1 ] ] = true;
}
}
private void sendMTFValues()
throws IOException
{
- char len[][] = new char[ N_GROUPS ][ MAX_ALPHA_SIZE ];
+ char[][] len = new char[ N_GROUPS ][ MAX_ALPHA_SIZE ];
int v;
@@ -1386,8 +1452,10 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
int 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;
}
}
@@ -1395,21 +1463,31 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
/*
* 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
@@ -1440,10 +1518,14 @@ 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;
}
}
@@ -1454,20 +1536,23 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
}
}
- int rfreq[][] = new int[ N_GROUPS ][ MAX_ALPHA_SIZE ];
- int fave[] = new int[ N_GROUPS ];
- short cost[] = new short[ N_GROUPS ];
+ int[][] rfreq = new int[ N_GROUPS ][ MAX_ALPHA_SIZE ];
+ int[] fave = new int[ N_GROUPS ];
+ short[] cost = new short[ N_GROUPS ];
/*
* 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( t = 0; t < nGroups; t++ )
+ {
+ for( v = 0; v < alphaSize; v++ )
+ {
rfreq[ t ][ v ] = 0;
}
}
@@ -1481,11 +1566,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
/*
* 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;
}
@@ -1493,7 +1580,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
* Calculate the cost of this group as coded
* by each of the coding tables.
*/
- for( t = 0; t < nGroups; t++ ) {
+ for( t = 0; t < nGroups; t++ )
+ {
cost[ t ] = 0;
}
@@ -1528,7 +1616,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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 ];
}
}
@@ -1540,7 +1629,8 @@ 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 ];
@@ -1556,7 +1646,8 @@ 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 ] ]++;
}
@@ -1566,7 +1657,8 @@ 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 );
}
}
@@ -1575,21 +1667,24 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
fave = null;
cost = null;
- if( !( nGroups < 8 ) ) {
+ 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[] pos = new char[ N_GROUPS ];
char ll_i;
char tmp2;
char tmp;
- for( i = 0; i < nGroups; i++ ) {
+ for( i = 0; i < nGroups; i++ )
+ {
pos[ i ] = (char)i;
}
for( i = 0; i < nSelectors; i++ )
@@ -1609,7 +1704,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
}
}
- int code[][] = new int[ N_GROUPS ][ MAX_ALPHA_SIZE ];
+ int[][] code = new int[ N_GROUPS ][ MAX_ALPHA_SIZE ];
/*
* Assign actual codes for the tables.
@@ -1620,17 +1715,21 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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 );
@@ -1639,32 +1738,44 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
/*
* Transmit the mapping table.
*/
- boolean inUse16[] = new boolean[ 16 ];
+ 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( m_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( m_inUse[ i * 16 + j ] )
+ {
bsW( 1, 1 );
- } else {
+ }
+ else
+ {
bsW( 1, 0 );
}
}
@@ -1681,7 +1792,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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 );
@@ -1726,11 +1838,13 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
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++ )
@@ -1742,7 +1856,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
gs = ge + 1;
selCtr++;
}
- if( !( selCtr == nSelectors ) ) {
+ if( !( selCtr == nSelectors ) )
+ {
panic();
}
}
@@ -1757,12 +1872,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--;
@@ -1777,7 +1894,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
/*
* copy 1
*/
- if( i > hi ) {
+ if( i > hi )
+ {
break;
}
v = zptr[ i ];
@@ -1786,7 +1904,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
zptr[ j ] = zptr[ j - h ];
j = j - h;
- if( j <= ( lo + h - 1 ) ) {
+ if( j <= ( lo + h - 1 ) )
+ {
break;
}
}
@@ -1796,7 +1915,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
/*
* copy 2
*/
- if( i > hi ) {
+ if( i > hi )
+ {
break;
}
v = zptr[ i ];
@@ -1805,7 +1925,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
zptr[ j ] = zptr[ j - h ];
j = j - h;
- if( j <= ( lo + h - 1 ) ) {
+ if( j <= ( lo + h - 1 ) )
+ {
break;
}
}
@@ -1815,7 +1936,8 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
/*
* copy 3
*/
- if( i > hi ) {
+ if( i > hi )
+ {
break;
}
v = zptr[ i ];
@@ -1824,14 +1946,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
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;
}
}
@@ -1857,10 +1981,10 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
{
if( last < allowableBlockSize )
{
- inUse[ currentChar ] = true;
+ m_inUse[ currentChar ] = true;
for( int i = 0; i < runLength; i++ )
{
- mCrc.updateCRC( (char)currentChar );
+ m_crc.updateCRC( (char)currentChar );
}
switch( runLength )
{
@@ -1883,7 +2007,7 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants
block[ last + 1 ] = (char)currentChar;
break;
default:
- inUse[ runLength - 4 ] = true;
+ m_inUse[ runLength - 4 ] = true;
last++;
block[ last + 1 ] = (char)currentChar;
last++;