PR: 24798 Submitted by: Joerg Wassmer <joerg dot wassmer at web dot de> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278137 13f79535-47bb-0310-9956-ffa450edef68master
@@ -104,6 +104,7 @@ Jerome Lacoste | |||||
Jesse Glick | Jesse Glick | ||||
Jesse Stockall | Jesse Stockall | ||||
Jim Allers | Jim Allers | ||||
Joerg Wassmer | |||||
Jon Dickinson | Jon Dickinson | ||||
Jon S. Stevens | Jon S. Stevens | ||||
Jose Alberto Fernandez | Jose Alberto Fernandez | ||||
@@ -160,6 +161,7 @@ Nick Pellow | |||||
Nicola Ken Barozzi | Nicola Ken Barozzi | ||||
Nico Seessle | Nico Seessle | ||||
Nigel Magnay | Nigel Magnay | ||||
Oliver Merkel | |||||
Oliver Rossmueller | Oliver Rossmueller | ||||
Patrick C. Beard | Patrick C. Beard | ||||
Patrick Chanezon | Patrick Chanezon | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001,2004 The Apache Software Foundation | |||||
* Copyright 2001,2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -26,7 +26,10 @@ package org.apache.tools.bzip2; | |||||
/** | /** | ||||
* Base class for both the compress and decompress classes. | * Base class for both the compress and decompress classes. | ||||
* Holds common arrays, and static data. | * Holds common arrays, and static data. | ||||
* | |||||
* <p> | |||||
* This interface is public for historical purposes. | |||||
* You should have no need to use it. | |||||
* </p> | |||||
*/ | */ | ||||
public interface BZip2Constants { | public interface BZip2Constants { | ||||
@@ -41,6 +44,13 @@ public interface BZip2Constants { | |||||
int MAX_SELECTORS = (2 + (900000 / G_SIZE)); | int MAX_SELECTORS = (2 + (900000 / G_SIZE)); | ||||
int NUM_OVERSHOOT_BYTES = 20; | int NUM_OVERSHOOT_BYTES = 20; | ||||
/** | |||||
* This array really shouldn't be here. | |||||
* Again, for historical purposes it is. | |||||
* | |||||
* <p>FIXME: This array should be in a private or package private | |||||
* location, since it could be modified by malicious code.</p> | |||||
*/ | |||||
int[] rNums = { | int[] rNums = { | ||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247, | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247, | ||||
985, 724, 205, 454, 863, 491, 741, 242, 949, 214, | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214, | ||||
@@ -1,5 +1,5 @@ | |||||
/* | /* | ||||
* Copyright 2001-2002,2004 The Apache Software Foundation | |||||
* Copyright 2001-2002,2004-2005 The Apache Software Foundation | |||||
* | * | ||||
* Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
* you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
@@ -28,8 +28,8 @@ package org.apache.tools.bzip2; | |||||
* of the data. | * of the data. | ||||
* | * | ||||
*/ | */ | ||||
class CRC { | |||||
public static int crc32Table[] = { | |||||
final class CRC { | |||||
static final int crc32Table[] = { | |||||
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, | 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, | ||||
0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, | 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, | ||||
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, | 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, | ||||
@@ -96,7 +96,7 @@ class CRC { | |||||
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 | 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 | ||||
}; | }; | ||||
public CRC() { | |||||
CRC() { | |||||
initialiseCRC(); | initialiseCRC(); | ||||
} | } | ||||
@@ -124,6 +124,17 @@ class CRC { | |||||
globalCrc = (globalCrc << 8) ^ CRC.crc32Table[temp]; | globalCrc = (globalCrc << 8) ^ CRC.crc32Table[temp]; | ||||
} | } | ||||
void updateCRC(int inCh, int repeat) { | |||||
int globalCrc = this.globalCrc; | |||||
while (repeat-- > 0) { | |||||
int temp = (globalCrc >> 24) ^ inCh; | |||||
globalCrc = (globalCrc << 8) ^ crc32Table[(temp >= 0) | |||||
? temp | |||||
: (temp + 256)]; | |||||
} | |||||
this.globalCrc = globalCrc; | |||||
} | |||||
int globalCrc; | int globalCrc; | ||||
} | } | ||||
@@ -19,7 +19,12 @@ package org.apache.tools.ant.taskdefs; | |||||
import org.apache.tools.ant.BuildFileTest; | import org.apache.tools.ant.BuildFileTest; | ||||
import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
import org.apache.tools.bzip2.CBZip2InputStream; | |||||
import java.io.BufferedInputStream; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.InputStream; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
/** | /** | ||||
@@ -44,9 +49,50 @@ public class BZip2Test extends BuildFileTest { | |||||
public void testRealTest() throws IOException { | public void testRealTest() throws IOException { | ||||
executeTarget("realTest"); | executeTarget("realTest"); | ||||
assertTrue("File content mismatch", | |||||
FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar.bz2"), | |||||
project.resolveFile("asf-logo-huge.tar.bz2"))); | |||||
// doesn't work: Depending on the compression engine used, | |||||
// compressed bytes may differ. False errors would be | |||||
// reported. | |||||
// assertTrue("File content mismatch", | |||||
// FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar.bz2"), | |||||
// project.resolveFile("asf-logo-huge.tar.bz2"))); | |||||
// We have to compare the decompressed content instead: | |||||
File originalFile = | |||||
project.resolveFile("expected/asf-logo-huge.tar.bz2"); | |||||
File actualFile = project.resolveFile("asf-logo-huge.tar.bz2"); | |||||
InputStream originalIn = | |||||
new BufferedInputStream(new FileInputStream(originalFile)); | |||||
assertEquals((byte) 'B', originalIn.read()); | |||||
assertEquals((byte) 'Z', originalIn.read()); | |||||
InputStream actualIn = | |||||
new BufferedInputStream(new FileInputStream(actualFile)); | |||||
assertEquals((byte) 'B', actualIn.read()); | |||||
assertEquals((byte) 'Z', actualIn.read()); | |||||
originalIn = new CBZip2InputStream(originalIn); | |||||
actualIn = new CBZip2InputStream(actualIn); | |||||
while (true) { | |||||
int expected = originalIn.read(); | |||||
int actual = actualIn.read(); | |||||
if (expected >= 0) { | |||||
if (expected != actual) { | |||||
fail("File content mismatch"); | |||||
} | |||||
} else { | |||||
if (actual >= 0) { | |||||
fail("File content mismatch"); | |||||
} | |||||
break; | |||||
} | |||||
} | |||||
originalIn.close(); | |||||
actualIn.close(); | |||||
} | } | ||||
public void testDateCheck(){ | public void testDateCheck(){ | ||||