Merge branch 'bugfix/PDFBOX-4014_Malformed_pathological_malicious_input_can_lead_to_infinite_looping'
diff --git a/README.md b/README.md
index 475ce72..1459e3b 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@
This component is part of the [Apache PDFBox® project](https://pdfbox.apache.org/)
## Status
-[![Build Status](https://travis-ci.org/levigo/jbig2-imageio.svg?branch=master)](https://travis-ci.org/levigo/jbig2-imageio)
+[![Build Status](https://travis-ci.org/apache/pdfbox-jbig2.svg?branch=master)](https://travis-ci.org/apache/pdfbox-jbig2)
## Features
The key features of the plugin are:
diff --git a/pom.xml b/pom.xml
index 21b73ec..f8ee995 100644
--- a/pom.xml
+++ b/pom.xml
@@ -229,65 +229,91 @@
</dependency>
</dependencies>
- <build>
- <plugins>
+ <!-- enable the usage of external testfiles with -Dskip-external-testfiles=false -->
+ <properties>
+ <skip-external-testfiles>true</skip-external-testfiles>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <debug>false</debug>
+ <optimize>true</optimize>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <autoVersionSubmodules>true</autoVersionSubmodules>
+ <!-- Keep changes in the local repo, push will be done afterwards -->
+ <pushChanges>false</pushChanges>
+ <localCheckout>true</localCheckout>
+ <!-- Use a better name for the tag -->
+ <tagNameFormat>${project.artifactId}-${project.version}</tagNameFormat>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.scm</groupId>
+ <artifactId>maven-scm-provider-gitexe</artifactId>
+ <version>1.9</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- <debug>false</debug>
- <optimize>true</optimize>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-release-plugin</artifactId>
- <configuration>
- <autoVersionSubmodules>true</autoVersionSubmodules>
- <!-- Keep changes in the local repo, push will be done afterwards -->
- <pushChanges>false</pushChanges>
- <localCheckout>true</localCheckout>
- <!-- Use a better name for the tag -->
- <tagNameFormat>${project.artifactId}-${project.version}</tagNameFormat>
- </configuration>
- <dependencies>
- <dependency>
- <groupId>org.apache.maven.scm</groupId>
- <artifactId>maven-scm-provider-gitexe</artifactId>
- <version>1.9</version>
- </dependency>
- </dependencies>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
+ <groupId>com.googlecode.maven-download-plugin</groupId>
+ <artifactId>download-maven-plugin</artifactId>
+ <version>1.3.0</version>
<executions>
- <execution>
- <id>attach-sources</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
+ <execution>
+ <id>Testfiles</id>
+ <phase>generate-test-resources</phase>
+ <goals>
+ <goal>wget</goal>
+ </goals>
+ <configuration>
+ <skip>${skip-external-testfiles}</skip>
+ <url>https://github.com/apache/pdfbox-testfiles/raw/master/jbig2/build-files/build-testfiles.zip</url>
+ <unpack>true</unpack>
+ <outputDirectory>${project.build.directory}/images</outputDirectory>
+ <sha512>5185b59b4117d830a05a225e7e4b3a8239f249c78f6133204d62d510991daf769d287cd704ba91895964ff3df8722fb304d1e571f3b4d250e663a064c53a3091</sha512>
+ </configuration>
+ </execution>
</executions>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <version>0.11</version>
- <configuration>
- <excludes>
- <exclude>src/test/resources/images/*</exclude>
- <exclude>src/test/resources/images/arith/*</exclude>
- <exclude>src/test/resources/com/levigo/jbig2/github/*</exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
+ </plugin>
+ </plugins>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>0.11</version>
+ <configuration>
+ <excludes>
+ <exclude>src/test/resources/images/*</exclude>
+ <exclude>src/test/resources/images/arith/*</exclude>
+ <exclude>src/test/resources/org/apache/pdfbox/jbig2/github/*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
<profiles>
<profile>
@@ -324,38 +350,6 @@
</plugins>
</build>
</profile>
- <profile>
- <id>release-sign-artifacts</id>
- <activation>
- <property>
- <name>performRelease</name>
- <value>true</value>
- </property>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-gpg-plugin</artifactId>
- <version>1.1</version>
- <configuration>
- <homedir>${levigo-jbig2-imageio.gpg.homedir}</homedir>
- <keyname>${levigo-jbig2-imageio.gpg.keyname}</keyname>
- <passphrase>${levigo-jbig2-imageio.gpg.passphrase}</passphrase>
- </configuration>
- <executions>
- <execution>
- <id>sign-artifacts</id>
- <phase>verify</phase>
- <goals>
- <goal>sign</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
</profiles>
</project>
diff --git a/src/main/java/org/apache/pdfbox/jbig2/Dictionary.java b/src/main/java/org/apache/pdfbox/jbig2/Dictionary.java
index 89fa888..3598f09 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/Dictionary.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/Dictionary.java
@@ -33,9 +33,9 @@
*
* @return A list of {@link Bitmap}s as a result of the decoding process of dictionary segments.
*
- * @throws IOException
- * @throws InvalidHeaderValueException
- * @throws IntegerMaxValueException
+ * @throws IOException if an underlying IO operation fails
+ * @throws InvalidHeaderValueException if the segment header value is invalid
+ * @throws IntegerMaxValueException if the maximum value limit of an integer is exceeded
*/
public ArrayList<Bitmap> getDictionary() throws IOException, InvalidHeaderValueException, IntegerMaxValueException;
}
diff --git a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReader.java b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReader.java
index db706ab..2f053b3 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReader.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReader.java
@@ -274,9 +274,10 @@
* Simply sets the globals.
*
* @param globals - The globals to set.
- * @throws IOException
+ * @throws IOException if an error occurs
*/
public void setGlobals(JBIG2Globals globals) throws IOException {
+ // TODO remove throws IOException as there isn't any chance to trigger it
this.globals = globals;
this.document = null;
}
diff --git a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderSpi.java b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderSpi.java
index 04ec211..297cea4 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderSpi.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderSpi.java
@@ -31,7 +31,7 @@
*/
public class JBIG2ImageReaderSpi extends ImageReaderSpi {
- private static final String VENDOR = "levigo solutions gmbh";
+ private static final String VENDOR = "Apache Software Foundation";
private static final String VERSION = "1.4.1";
private static final String READER_CLASS_NAME = "org.apache.pdfbox.jbig2.JBIG2ImageReader";
private static final String[] NAMES = {
diff --git a/src/main/java/org/apache/pdfbox/jbig2/Region.java b/src/main/java/org/apache/pdfbox/jbig2/Region.java
index dd30dcd..87f431a 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/Region.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/Region.java
@@ -33,9 +33,9 @@
*
* @return The decoded region as {@link Bitmap}.
*
- * @throws IOException
- * @throws IntegerMaxValueException
- * @throws InvalidHeaderValueException
+ * @throws IOException if an underlying IO operation fails
+ * @throws IntegerMaxValueException if the maximum value limit of an integer is exceeded
+ * @throws InvalidHeaderValueException if the segment header value is invalid
*/
public Bitmap getRegionBitmap() throws IOException, IntegerMaxValueException, InvalidHeaderValueException;
diff --git a/src/main/java/org/apache/pdfbox/jbig2/SegmentData.java b/src/main/java/org/apache/pdfbox/jbig2/SegmentData.java
index 8efca74..d2aaef5 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/SegmentData.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/SegmentData.java
@@ -34,9 +34,9 @@
* @param header - The segments' header (to make referred-to segments available in data part).
* @param sis - Wrapped {@code ImageInputStream} into {@code SubInputStream}.
*
- * @throws InvalidHeaderValueException
- * @throws IntegerMaxValueException
- * @throws IOException
+ * @throws InvalidHeaderValueException if the segment header value is invalid
+ * @throws IntegerMaxValueException if the maximum value limit of an integer is exceeded
+ * @throws IOException if an underlying IO operation fails
*/
public void init(SegmentHeader header, SubInputStream sis) throws InvalidHeaderValueException, IntegerMaxValueException,
IOException;
diff --git a/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoder.java b/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoder.java
index 0f9fa7c..d4f1c99 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoder.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/decoder/arithmetic/ArithmeticIntegerDecoder.java
@@ -35,8 +35,9 @@
/**
* Arithmetic Integer Decoding Procedure, Annex A.2.
*
+ * @param cxIAx to be decoded value
* @return Decoded value.
- * @throws IOException
+ * @throws IOException if an underlying IO operation fails
*/
public long decode(CX cxIAx) throws IOException {
int v = 0;
@@ -137,7 +138,7 @@
*
* @return The decoded value.
*
- * @throws IOException
+ * @throws IOException if an underlying IO operation fails
*/
public int decodeIAID(CX cxIAID, long symCodeLen) throws IOException {
// A.3 1)
diff --git a/src/main/java/org/apache/pdfbox/jbig2/image/Bitmaps.java b/src/main/java/org/apache/pdfbox/jbig2/image/Bitmaps.java
index d73f2f8..af4a26a 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/image/Bitmaps.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/image/Bitmaps.java
@@ -34,20 +34,41 @@
public class Bitmaps {
- public static WritableRaster asRaster(final Bitmap bitmap) {
- return asRaster(bitmap, FilterType.Gaussian);
- }
+ /**
+ * Returns the given bitmap as writable raster.
+ *
+ * @param bitmap the given bitmap
+ * @return the raster representation of the bitmap
+ */
+ public static WritableRaster asRaster(final Bitmap bitmap) {
+ return asRaster(bitmap, FilterType.Gaussian);
+ }
- public static WritableRaster asRaster(final Bitmap bitmap, final FilterType filterType) {
- if (bitmap == null)
- throw new IllegalArgumentException("bitmap must not be null");
+ /**
+ * Returns the given bitmap as writable raster.
+ *
+ * @param bitmap the given bitmap
+ * @param filterType type of filter which is used when creating the writable raster
+ * @return the raster representation of the bitmap
+ */
+ public static WritableRaster asRaster(final Bitmap bitmap, final FilterType filterType) {
+ if (bitmap == null)
+ throw new IllegalArgumentException("bitmap must not be null");
+
+ final JBIG2ReadParam param = new JBIG2ReadParam(1, 1, 0, 0, new Rectangle(0, 0, bitmap.getWidth(),
+ bitmap.getHeight()), new Dimension(bitmap.getWidth(), bitmap.getHeight()));
+
+ return asRaster(bitmap, param, filterType);
+ }
- final JBIG2ReadParam param = new JBIG2ReadParam(1, 1, 0, 0, new Rectangle(0, 0, bitmap.getWidth(),
- bitmap.getHeight()), new Dimension(bitmap.getWidth(), bitmap.getHeight()));
-
- return asRaster(bitmap, param, filterType);
- }
-
+ /**
+ * Returns the given bitmap as writable raster.
+ *
+ * @param bitmap the given bitmap
+ * @param param ImageReadParam to be used when creating the writable raster
+ * @param filterType type of filter which is used when creating the writable raster
+ * @return the raster representation of the bitmap
+ */
public static WritableRaster asRaster(Bitmap bitmap, final ImageReadParam param, final FilterType filterType) {
if (bitmap == null)
throw new IllegalArgumentException("bitmap must not be null");
@@ -153,10 +174,23 @@
return dst;
}
+ /**
+ * Returns the given bitmap as buffered image.
+ *
+ * @param bitmap the given bitmap
+ * @return the image representation of the bitmap
+ */
public static BufferedImage asBufferedImage(Bitmap bitmap) {
return asBufferedImage(bitmap, FilterType.Gaussian);
}
+ /**
+ * Returns the given bitmap as buffered image.
+ *
+ * @param bitmap the given bitmap
+ * @param filterType type of filter which is used when creating the buffered image
+ * @return the image representation of the bitmap
+ */
public static BufferedImage asBufferedImage(Bitmap bitmap, FilterType filterType) {
if (bitmap == null)
throw new IllegalArgumentException("bitmap must not be null");
@@ -167,6 +201,14 @@
return asBufferedImage(bitmap, param, filterType);
}
+ /**
+ * Returns the given bitmap as buffered image.
+ *
+ * @param bitmap the given bitmap
+ * @param param ImageReadParam to be used when creating the buffered image
+ * @param filterType type of filter which is used when creating the buffered image
+ * @return the image representation of the bitmap
+ */
public static BufferedImage asBufferedImage(Bitmap bitmap, ImageReadParam param, FilterType filterType) {
if (bitmap == null)
throw new IllegalArgumentException("bitmap must not be null");
@@ -217,6 +259,7 @@
* Returns the specified rectangle area of the bitmap.
*
* @param roi - A {@link Rectangle} that specifies the requested image section.
+ * @param src the given bitmap
* @return A {@code Bitmap} that represents the requested image section.
*/
public static Bitmap extract(final Rectangle roi, final Bitmap src) {
@@ -399,6 +442,7 @@
* Parts of the bitmap to blit that are outside of the target bitmap will be ignored.
*
* @param src - The bitmap that should be combined with the one of the current instance.
+ * @param dst - The destination bitmap.
* @param x - The x coordinate where the upper left corner of the bitmap to blit should be
* positioned.
* @param y - The y coordinate where the upper left corner of the bitmap to blit should be
diff --git a/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRefinementRegion.java b/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRefinementRegion.java
index af59e7d..c36c736 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRefinementRegion.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRefinementRegion.java
@@ -173,9 +173,9 @@
/**
* Decode using a template and arithmetic coding, as described in 6.3.5.6
*
- * @throws IOException
- * @throws InvalidHeaderValueException
- * @throws IntegerMaxValueException
+ * @throws IOException if an underlying IO operation fails
+ * @throws InvalidHeaderValueException if a segment header value is invalid
+ * @throws IntegerMaxValueException if the maximum value limit of an integer is exceeded
*/
public Bitmap getRegionBitmap() throws IOException, IntegerMaxValueException, InvalidHeaderValueException {
if (null == regionBitmap) {
diff --git a/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRegion.java b/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRegion.java
index 9c42f04..a799f73 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRegion.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/segments/GenericRegion.java
@@ -152,7 +152,7 @@
/**
* The procedure is described in 6.2.5.7, page 17.
*
- * @returns The decoded {@link Bitmap} of this region.
+ * @return The decoded {@link Bitmap} of this region.
*/
public Bitmap getRegionBitmap() throws IOException {
if (null == regionBitmap) {
@@ -807,6 +807,12 @@
/**
* Used by {@link SymbolDictionary}.
+ *
+ * @param isMMREncoded the data is MMR encoded
+ * @param dataOffset the offset
+ * @param dataLength the length of the data
+ * @param gbh bitmap height
+ * @param gbw bitmap width
*/
protected void setParameters(final boolean isMMREncoded, final long dataOffset, final long dataLength, final int gbh,
final int gbw) {
@@ -821,6 +827,17 @@
}
/**
+ * @param isMMREncoded the data is MMR encoded
+ * @param sdTemplate sd template
+ * @param isTPGDon is TPGDon
+ * @param useSkip use skip
+ * @param sdATX x values gbA pixels
+ * @param sdATY y values gbA pixels
+ * @param symWidth bitmap width
+ * @param hcHeight bitmap height
+ * @param cx context for the arithmetic decoder
+ * @param arithmeticDecoder the arithmetic decode to be used
+ *
* Used by {@link SymbolDictionary}.
*/
protected void setParameters(final boolean isMMREncoded, final byte sdTemplate, final boolean isTPGDon,
@@ -844,6 +861,18 @@
/**
* Used by {@link PatternDictionary} and {@link HalftoneRegion}.
+ *
+ * @param isMMREncoded the data is MMR encoded
+ * @param dataOffset the offset
+ * @param dataLength the length of the data
+ * @param gbh bitmap height
+ * @param gbw bitmap width
+ * @param gbTemplate gb template
+ * @param isTPGDon is TPGDon
+ * @param useSkip use skip
+ * @param gbAtX x values of gbA pixels
+ * @param gbAtY y values of gbA pixels
+ *
*/
protected void setParameters(final boolean isMMREncoded, final long dataOffset, final long dataLength, final int gbh,
final int gbw, final byte gbTemplate, final boolean isTPGDon, final boolean useSkip, final short[] gbAtX,
diff --git a/src/main/java/org/apache/pdfbox/jbig2/segments/HalftoneRegion.java b/src/main/java/org/apache/pdfbox/jbig2/segments/HalftoneRegion.java
index 384f09f..4121d58 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/segments/HalftoneRegion.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/segments/HalftoneRegion.java
@@ -153,7 +153,10 @@
/**
* The procedure is described in JBIG2 ISO standard, 6.6.5.
*
- * @returns The decoded {@link Bitmap} of this region.
+ * @return The decoded {@link Bitmap} of this region.
+ *
+ * @throws IOException if an underlying IO operation fails
+ * @throws InvalidHeaderValueException if a segment header value is invalid
*/
public Bitmap getRegionBitmap() throws IOException, InvalidHeaderValueException {
if (null == halftoneRegionBitmap) {
diff --git a/src/main/java/org/apache/pdfbox/jbig2/util/Utils.java b/src/main/java/org/apache/pdfbox/jbig2/util/Utils.java
index ae2ae7a..daeb3b3 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/util/Utils.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/util/Utils.java
@@ -29,8 +29,8 @@
* <code>enlargeToGrid(r).contains(r) == true</code> holds. This can be depicted as the edges
* being stretched in an outward direction.
*
- * @param r
- * @return
+ * @param r the given rectangle
+ * @return the resulting rectangle
*/
public static Rectangle enlargeRectToGrid(Rectangle2D r) {
final int x0 = floor(r.getMinX());
@@ -44,8 +44,10 @@
* Return a new rectangle which covers the area of the given rectangle with an additional margin
* on the sides.
*
- * @param r
- * @param marginX
+ * @param r the given rectangle
+ * @param marginX horizontal value of the additional margin
+ * @param marginY vertical value of the additional margin
+ * @return the resulting rectangle
*/
public static Rectangle2D dilateRect(Rectangle2D r, double marginX, double marginY) {
return new Rectangle2D.Double(r.getX() - marginX, r.getY() - marginY, r.getWidth() + 2 * marginX, r.getHeight() + 2
@@ -55,9 +57,9 @@
/**
* Clamp the value into the range [min..max].
*
- * @param value
- * @param min
- * @param max
+ * @param value input value
+ * @param min minimal value
+ * @param max maximal value
* @return the clamped value
*/
public static double clamp(double value, double min, double max) {
@@ -72,7 +74,7 @@
* A fast implementation of {@link Math#floor(double)}.
*
* @param x the argument
- * @return
+ * @return resulting floor value
*/
public static int floor(double x) {
return (int) (x + BIG_ENOUGH_FLOOR) - BIG_ENOUGH_INT;
@@ -82,7 +84,7 @@
* A fast implementation of {@link Math#round(double)}.
*
* @param x the argument
- * @return
+ * @return rounded value
*/
public static int round(double x) {
return (int) (x + BIG_ENOUGH_ROUND) - BIG_ENOUGH_INT;
@@ -92,7 +94,7 @@
* A fast implementation of {@link Math#ceil(double)}.
*
* @param x the argument
- * @return
+ * @return resulting ceil value
*/
public static int ceil(double x) {
return BIG_ENOUGH_INT - (int) (BIG_ENOUGH_FLOOR - x);
diff --git a/src/main/java/org/apache/pdfbox/jbig2/util/cache/Cache.java b/src/main/java/org/apache/pdfbox/jbig2/util/cache/Cache.java
index 41038cf..6454784 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/util/cache/Cache.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/util/cache/Cache.java
@@ -21,9 +21,9 @@
/**
*
- * @param key
- * @param value
- * @param sizeEstimate
+ * @param key value to be used as key
+ * @param value value to be stored
+ * @param sizeEstimate estimated size
*
* @return the old object, that was replaced if present. Otherwise {@code null}.
*/
@@ -40,7 +40,7 @@
/**
*
- * @param key
+ * @param key the key of the to be removed object
* @return the removed object, if present. Otherwise {@code null}.
*/
Object remove(Object key);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/ChecksumTest.java b/src/test/java/org/apache/pdfbox/jbig2/ChecksumTest.java
index 5ad235f..77b78bd 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/ChecksumTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/ChecksumTest.java
@@ -19,6 +19,8 @@
import static org.junit.Assume.assumeTrue;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.InputStream;
import java.security.MessageDigest;
import java.util.Arrays;
@@ -43,98 +45,98 @@
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{
- "/images/042_1.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_1.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_2.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_2.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_3.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_3.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_4.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_4.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_5.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_5.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_6.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_6.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_7.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_7.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_8.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_8.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_9.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_9.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_10.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_10.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_11.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_11.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_12.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_12.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
},
// { "/images/042_13.jb2",
// "69-26-6629-1793-107941058147-58-79-37-31-79" },
// { "/images/042_14.jb2",
// "69-26-6629-1793-107941058147-58-79-37-31-79" },
{
- "/images/042_15.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_15.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_16.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_16.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_17.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_17.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_18.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_18.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_19.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_19.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_20.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_20.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_21.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_21.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_22.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_22.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_23.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_23.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_24.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_24.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/042_25.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
+ "target/images/042_25.jb2", "69-26-6629-1793-107941058147-58-79-37-31-79"
}, {
- "/images/amb_1.jb2", "58311272494-318210035-125100-344625-126-79"
+ "target/images/amb_1.jb2", "58311272494-318210035-125100-344625-126-79"
}, {
- "/images/amb_2.jb2", "58311272494-318210035-125100-344625-126-79"
+ "target/images/amb_2.jb2", "58311272494-318210035-125100-344625-126-79"
}, {
- "/images/002.jb2", "-12713-4587-92-651657111-57121-1582564895"
+ "src/test/resources/images/002.jb2", "-12713-4587-92-651657111-57121-1582564895"
}, {
- "/images/003.jb2", "-37-108-89-33-78-5019-966-96-124-9675-1-108-24"
+ "src/test/resources/images/003.jb2", "-37-108-89-33-78-5019-966-96-124-9675-1-108-24"
}, {
- "/images/004.jb2", "-10709436-24-59-48-217114-37-85-3126-24"
+ "target/images/004.jb2", "-10709436-24-59-48-217114-37-85-3126-24"
}, {
- "/images/005.jb2", "712610586-1224021396100112-102-77-1177851"
+ "src/test/resources/images/005.jb2", "712610586-1224021396100112-102-77-1177851"
}, {
- "/images/006.jb2", "-8719-116-83-83-35-3425-64-528667602154-25"
+ "src/test/resources/images/006.jb2", "-8719-116-83-83-35-3425-64-528667602154-25"
}, {
- "/images/007.jb2", "6171-125-109-20-128-71925295955793-127-41-122"
+ "target/images/007.jb2", "6171-125-109-20-128-71925295955793-127-41-122"
}, {
- "/images/sampledata_page1.jb2", "104-68-555325117-4757-48527676-9775-8432"
+ "target/images/sampledata_page1.jb2", "104-68-555325117-4757-48527676-9775-8432"
}, {
- "/images/sampledata_page2.jb2", "104-68-555325117-4757-48527676-9775-8432"
+ "target/images/sampledata_page2.jb2", "104-68-555325117-4757-48527676-9775-8432"
}, {
- "/images/sampledata_page3.jb2", "-7825-56-41-30-19-719536-3678580-61-2586"
+ "target/images/sampledata_page3.jb2", "-7825-56-41-30-19-719536-3678580-61-2586"
}, {
- "/images/20123110001.jb2", "60-96-101-2458-3335024-5468-5-11068-78-80"
+ "src/test/resources/images/20123110001.jb2", "60-96-101-2458-3335024-5468-5-11068-78-80"
}, {
- "/images/20123110002.jb2", "-28-921048181-117-48-96126-110-9-2865611113"
+ "src/test/resources/images/20123110002.jb2", "-28-921048181-117-48-96126-110-9-2865611113"
}, {
- "/images/20123110003.jb2", "-3942-239351-28-56-729169-5839122-439231"
+ "src/test/resources/images/20123110003.jb2", "-3942-239351-28-56-729169-5839122-439231"
}, {
- "/images/20123110004.jb2", "-49-101-28-20-57-4-24-17-9352104-106-118-122-122"
+ "src/test/resources/images/20123110004.jb2", "-49-101-28-20-57-4-24-17-9352104-106-118-122-122"
}, {
- "/images/20123110005.jb2", "-48221261779-94-838820-127-114110-2-88-80-106"
+ "src/test/resources/images/20123110005.jb2", "-48221261779-94-838820-127-114110-2-88-80-106"
}, {
- "/images/20123110006.jb2", "81-11870-63-30124-1614-45838-53-123-41639"
+ "src/test/resources/images/20123110006.jb2", "81-11870-63-30124-1614-45838-53-123-41639"
}, {
- "/images/20123110007.jb2", "12183-49124728346-29-124-9-10775-63-44116103"
+ "src/test/resources/images/20123110007.jb2", "12183-49124728346-29-124-9-10775-63-44116103"
}, {
- "/images/20123110008.jb2", "15-74-49-45958458-67-2545-96-119-122-60100-35"
+ "src/test/resources/images/20123110008.jb2", "15-74-49-45958458-67-2545-96-119-122-60100-35"
}, {
- "/images/20123110009.jb2", "36115-114-28-123-3-70-87-113-4197-8512396113-65"
+ "src/test/resources/images/20123110009.jb2", "36115-114-28-123-3-70-87-113-4197-8512396113-65"
}, {
- "/images/20123110010.jb2", "-109-1069-61-1576-67-43122406037-75-1091115"
+ "src/test/resources/images/20123110010.jb2", "-109-1069-61-1576-67-43122406037-75-1091115"
}
});
}
@@ -151,20 +153,18 @@
public void compareChecksum() throws Throwable {
int imageIndex = 1;
- InputStream inputStream = getClass().getResourceAsStream(filepath);
+ final File inputFile = new File(filepath);
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
- System.out.println("####################################");
- System.out.println("File: " + filepath);
+ final InputStream inputStream = new FileInputStream(inputFile);
+
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
JBIG2Document doc = new JBIG2Document(iis);
- long time = System.currentTimeMillis();
Bitmap b = doc.getPage(imageIndex).getBitmap();
- long duration = System.currentTimeMillis() - time;
byte[] digest = MessageDigest.getInstance("MD5").digest(b.getByteArray());
@@ -173,8 +173,6 @@
{
stringBuilder.append(toAppend);
}
- System.out.println("Completed decoding in " + duration + " ms");
- System.out.println("####################################\n");
Assert.assertEquals(checksum, stringBuilder.toString());
}
diff --git a/src/test/java/org/apache/pdfbox/jbig2/GithubIssuesTest.java b/src/test/java/org/apache/pdfbox/jbig2/GithubIssuesTest.java
index 96aa2a2..abee340 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/GithubIssuesTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/GithubIssuesTest.java
@@ -46,8 +46,8 @@
83, 74, -69, -60, -122, -99, 21, 126, -115, 13, 9, 107, -31, -109, 77, -119
};
- final InputStream imageStream = getClass().getResourceAsStream("/com/levigo/jbig2/github/21.jb2");
- final InputStream globalsStream = getClass().getResourceAsStream("/com/levigo/jbig2/github/21.glob");
+ final InputStream imageStream = getClass().getResourceAsStream("/org/apache/pdfbox/jbig2/github/21.jb2");
+ final InputStream globalsStream = getClass().getResourceAsStream("/org/apache/pdfbox/jbig2/github/21.glob");
final ImageInputStream globalsIIS = ImageIO.createImageInputStream(globalsStream);
final ImageInputStream imageIIS = ImageIO.createImageInputStream(imageStream);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderTest.java b/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderTest.java
index 3e75e8d..f4a087f 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderTest.java
@@ -21,6 +21,8 @@
import java.awt.image.BufferedImage;
import java.awt.image.Raster;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -56,12 +58,14 @@
@Test
public void testRead() throws IOException, InvalidHeaderValueException, IntegerMaxValueException {
- String filepath = "/images/042_1.jb2";
+
int imageIndex = 0;
- InputStream inputStream = getClass().getResourceAsStream(filepath);
+ final File inputFile = new File("target/images/042_1.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream imageInputStream = disf.getInputStream(inputStream);
@@ -79,12 +83,14 @@
@Test
public void testReadRaster() throws IOException, InvalidHeaderValueException, IntegerMaxValueException {
- String filepath = "/images/042_1.jb2";
+
int imageIndex = 0;
- InputStream inputStream = getClass().getResourceAsStream(filepath);
+ final File inputFile = new File("target/images/042_1.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream imageInputStream = disf.getInputStream(inputStream);
@@ -98,12 +104,14 @@
@Test
public void testReadImageReadParamNull() throws IOException, InvalidHeaderValueException, IntegerMaxValueException {
- String filepath = "/images/042_1.jb2";
- int imageIndex = 0;
- InputStream inputStream = getClass().getResourceAsStream(filepath);
+ int imageIndex = 0;
+
+ final File inputFile = new File("target/images/042_1.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream imageInputStream = disf.getInputStream(inputStream);
@@ -117,12 +125,14 @@
@Test
public void testReadRasterImageReadParamNull() throws IOException, InvalidHeaderValueException,
IntegerMaxValueException {
- String filepath = "/images/042_1.jb2";
- int imageIndex = 0;
- InputStream inputStream = getClass().getResourceAsStream(filepath);
+ int imageIndex = 0;
+
+ final File inputFile = new File("target/images/042_1.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream imageInputStream = disf.getInputStream(inputStream);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/JBIG2PageTest.java b/src/test/java/org/apache/pdfbox/jbig2/JBIG2PageTest.java
index 1fb6ae5..6c23b60 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/JBIG2PageTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/JBIG2PageTest.java
@@ -17,8 +17,12 @@
package org.apache.pdfbox.jbig2;
+import static org.junit.Assume.assumeTrue;
+
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -44,10 +48,13 @@
@Test
public void composeDisplayTest() throws IOException, JBIG2Exception {
- String filepath = "/images/amb_1.jb2";
+ final File inputFile = new File("target/images/amb_1.jb2");
+ // skip test if input stream isn't available
+ assumeTrue(inputFile.exists());
+
int pageNumber = 1;
- InputStream is = getClass().getResourceAsStream(filepath);
+ InputStream is = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(is);
JBIG2Document doc = new JBIG2Document(iis);
@@ -64,12 +71,13 @@
int runs = 40;
long avg = 0;
- String path = "/images/042_8.jb2";
+ final File inputFile = new File("target/images/042_8.jb2");
+ // skip test if input stream isn't available
+ assumeTrue(inputFile.exists());
+
int pageNumber = 1;
- System.out.println("File: " + path);
-
- InputStream is = getClass().getResourceAsStream(path);
+ InputStream is = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(is);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressorTest.java b/src/test/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressorTest.java
index 6931479..f8da8de 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressorTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/decoder/mmr/MMRDecompressorTest.java
@@ -20,6 +20,8 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assume.assumeTrue;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -33,32 +35,30 @@
public class MMRDecompressorTest {
- @Test
+ @Test
public void mmrDecodingTest() throws IOException, InvalidHeaderValueException
{
- final byte[] expected = new byte[]{
- 0, 0, 2, 34, 38, 102, -17, -1, 2, 102, 102, //
- -18, -18, -17, -1, -1, 0, 2, 102, 102, 127, //
- -1, -1, -1, 0, 0, 0, 4, 68, 102, 102, 127
- };
- final String filepath = "/images/sampledata.jb2";
+ final byte[] expected = new byte[] { 0, 0, 2, 34, 38, 102, -17, -1, 2, 102, 102, //
+ -18, -18, -17, -1, -1, 0, 2, 102, 102, 127, //
+ -1, -1, -1, 0, 0, 0, 4, 68, 102, 102, 127 };
- final InputStream inputStream = getClass().getResourceAsStream(filepath);
- // skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ final File inputFile = new File("target/images/sampledata.jb2");
+ // skip test if input stream isn't available
+ assumeTrue(inputFile.exists());
- final DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
- final ImageInputStream iis = disf.getInputStream(inputStream);
+ final InputStream inputStream = new FileInputStream(inputFile);
- // Sixth Segment (number 5)
- final SubInputStream sis = new SubInputStream(iis, 252, 38);
-
- final MMRDecompressor mmrd = new MMRDecompressor(16 * 4, 4, sis);
-
- final Bitmap b = mmrd.uncompress();
- final byte[] actual = b.getByteArray();
+ final DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
+ final ImageInputStream iis = disf.getInputStream(inputStream);
- assertArrayEquals(expected, actual);
- // new TestImage(b.getByteArray(), (int) b.getWidth(), (int) b.getHeight(), b.getRowStride());
- }
+ // Sixth Segment (number 5)
+ final SubInputStream sis = new SubInputStream(iis, 252, 38);
+
+ final MMRDecompressor mmrd = new MMRDecompressor(16 * 4, 4, sis);
+
+ final Bitmap b = mmrd.uncompress();
+ final byte[] actual = b.getByteArray();
+
+ assertArrayEquals(expected, actual);
+ }
}
diff --git a/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsBlitTest.java b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsBlitTest.java
index f6fe072..8e074fe 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsBlitTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsBlitTest.java
@@ -21,6 +21,8 @@
import static org.junit.Assume.assumeTrue;
import java.awt.Rectangle;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -38,10 +40,13 @@
@Test
public void testCompleteBitmapTransfer() throws IOException, JBIG2Exception {
- final InputStream inputStream = getClass().getResourceAsStream("/images/042_1.jb2");
- // skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ final File inputFile = new File("target/images/042_1.jb2");
+ // skip test if input stream isn't available
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
+
final DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
final ImageInputStream iis = disf.getInputStream(inputStream);
@@ -59,9 +64,12 @@
@Test
public void test() throws IOException, JBIG2Exception {
- final InputStream inputStream = getClass().getResourceAsStream("/images/042_1.jb2");
+
+ final File inputFile = new File("target/images/042_1.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
final DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
final ImageInputStream iis = disf.getInputStream(inputStream);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsChecksumTest.java b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsChecksumTest.java
index 3f8ff01..1752341 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsChecksumTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/image/BitmapsChecksumTest.java
@@ -28,7 +28,6 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@@ -39,7 +38,6 @@
import org.apache.pdfbox.jbig2.Bitmap;
import org.apache.pdfbox.jbig2.JBIG2DocumentFacade;
-import org.apache.pdfbox.jbig2.JBIG2ImageReaderDemo;
import org.apache.pdfbox.jbig2.PreconfiguredImageReadParam;
import org.apache.pdfbox.jbig2.err.JBIG2Exception;
import org.apache.pdfbox.jbig2.image.Bitmaps;
@@ -65,48 +63,48 @@
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{
- "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(500, 500)), FilterType.Bessel,
+ "target/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(500, 500)), FilterType.Bessel,
"101-6467-126-3534108-8927-58-26-37248672"
},
{
- "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(500, 800)), FilterType.Box,
+ "target/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(500, 800)), FilterType.Box,
"-748135-126-6412111-11925-1038826-95-32-6-104"
},
{
- "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(4000, 5500)), FilterType.Box,
+ "target/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(4000, 5500)), FilterType.Box,
"-646510160-466410970-77-1031184396-8-23-18"
},
{
- "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(600, 300)), FilterType.Bessel,
+ "target/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Dimension(600, 300)), FilterType.Bessel,
"-69-11478-721003586-100-72-85-1559101-118-24-94"
},
{
- "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(2, 2, 0, 0), FilterType.Bessel,
+ "target/images/042_1.jb2", 1, new PreconfiguredImageReadParam(2, 2, 0, 0), FilterType.Bessel,
"-4979-94-68-125645751-2111712617-59-295"
},
{
- "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(2, 2, 0, 0), FilterType.Lanczos,
+ "target/images/042_1.jb2", 1, new PreconfiguredImageReadParam(2, 2, 0, 0), FilterType.Lanczos,
"-4979-94-68-125645751-2111712617-59-295"
},
{
- "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(3, 3, 1, 1), FilterType.Lanczos,
+ "target/images/042_1.jb2", 1, new PreconfiguredImageReadParam(3, 3, 1, 1), FilterType.Lanczos,
"84-1069410599-9575-7934-1279-80-85127-18-128"
},
{
- "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Rectangle(100, 100, 500, 500)),
+ "target/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Rectangle(100, 100, 500, 500)),
FilterType.Lanczos, "1245-23-127954634-1232173-109-5739-303-48"
},
{
- "/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Rectangle(500, 500, 2000, 2000)),
+ "target/images/042_1.jb2", 1, new PreconfiguredImageReadParam(new Rectangle(500, 500, 2000, 2000)),
FilterType.Lanczos, "-60-45-117-90-6596-11556-47-30-112-741138412082"
},
{
- "/images/042_1.jb2", 1,
+ "target/images/042_1.jb2", 1,
new PreconfiguredImageReadParam(new Rectangle(500, 500, 2000, 2000), new Dimension(678, 931)),
FilterType.Lanczos, "-17-95-5543-12062-625054-94-88-31-4-120-1971"
},
{
- "/images/042_1.jb2", 1,
+ "target/images/042_1.jb2", 1,
new PreconfiguredImageReadParam(new Rectangle(500, 500, 2000, 2000), new Dimension(678, 931), 3, 3, 1, 1),
FilterType.Lanczos, "-109-60118-41999255-94113-5019-2818-10-39-71"
}
@@ -124,43 +122,44 @@
@Test
public void test() throws IOException, JBIG2Exception, NoSuchAlgorithmException {
- final InputStream inputStream = JBIG2ImageReaderDemo.class.getResourceAsStream(resourcePath);
- // skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
- final InputStreamFactory disf = new DefaultInputStreamFactory();
- final ImageInputStream iis = disf.getInputStream(inputStream);
+ final File inputFile = new File(resourcePath);
+ // skip test if input stream isn't available
+ assumeTrue(inputFile.exists());
- final JBIG2DocumentFacade doc = new JBIG2DocumentFacade(iis);
- final Bitmap b = doc.getPageBitmap(pageNumber);
- final WritableRaster raster = Bitmaps.asRaster(b, param, filterType);
-
- final DataBufferByte dataBufferByte = (DataBufferByte) raster.getDataBuffer();
- final byte[] bytes = dataBufferByte.getData();
-
- final MessageDigest md = MessageDigest.getInstance("MD5");
-
- final byte[] digest = md.digest(bytes);
- final StringBuilder sb = new StringBuilder();
- for (byte toAppend : digest) {
- sb.append(toAppend);
- }
-
- assertArrayEquals(checksum.getBytes(), sb.toString().getBytes());
-
+ final InputStream inputStream = new FileInputStream(inputFile);
+
+ final InputStreamFactory disf = new DefaultInputStreamFactory();
+ final ImageInputStream iis = disf.getInputStream(inputStream);
+
+ final JBIG2DocumentFacade doc = new JBIG2DocumentFacade(iis);
+ final Bitmap b = doc.getPageBitmap(pageNumber);
+ final WritableRaster raster = Bitmaps.asRaster(b, param, filterType);
+
+ final DataBufferByte dataBufferByte = (DataBufferByte) raster.getDataBuffer();
+ final byte[] bytes = dataBufferByte.getData();
+
+ final MessageDigest md = MessageDigest.getInstance("MD5");
+
+ final byte[] digest = md.digest(bytes);
+ final StringBuilder sb = new StringBuilder();
+ for (byte toAppend : digest) {
+ sb.append(toAppend);
+ }
+
+ assertArrayEquals(checksum.getBytes(), sb.toString().getBytes());
}
static class RasterChecksumCalculator {
public static void main(String[] args) throws IOException, JBIG2Exception, NoSuchAlgorithmException {
- final String resourcePath = "/images/042_1.jb2";
+
+ final File inputFile = new File("target/images/042_1.jb2");
+ // skip test if input stream isn't available
+ assumeTrue(inputFile.exists());
final int pageNumber = 1;
- final URL imageUrl = JBIG2ImageReaderDemo.class.getResource(resourcePath);
-
- final InputStream inputStream = new FileInputStream(new File(imageUrl.getPath()));
- // skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ final InputStream inputStream = new FileInputStream(inputFile);
final InputStreamFactory disf = new DefaultInputStreamFactory();
final ImageInputStream iis = disf.getInputStream(inputStream);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/GenericRegionTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/GenericRegionTest.java
index 86251f1..ade800f 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/segments/GenericRegionTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/GenericRegionTest.java
@@ -19,6 +19,8 @@
import static org.junit.Assume.assumeTrue;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -40,9 +42,11 @@
@Test
public void parseHeaderTest() throws IOException, InvalidHeaderValueException {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
+ final File inputFile = new File("target/images/sampledata.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
@@ -81,9 +85,11 @@
@Ignore
@Test
public void decodeTemplate0Test() throws Throwable {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
+ final File inputFile = new File("target/images/sampledata.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
@@ -99,9 +105,11 @@
@Test
public void decodeWithArithmetichCoding() throws Throwable {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
+ final File inputFile = new File("target/images/sampledata.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
@@ -116,9 +124,12 @@
@Ignore
@Test
public void decodeWithMMR() throws Throwable {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
+
+ final File inputFile = new File("target/images/sampledata.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/HalftoneRegionTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/HalftoneRegionTest.java
index 71cbfcb..7559259 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/segments/HalftoneRegionTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/HalftoneRegionTest.java
@@ -19,6 +19,8 @@
import static org.junit.Assume.assumeTrue;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -37,9 +39,12 @@
@Test
public void parseHeaderTest() throws IOException, InvalidHeaderValueException {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
+
+ final File inputFile = new File("target/images/sampledata.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/PageInformationTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/PageInformationTest.java
index 35e43c3..700a6ad 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/segments/PageInformationTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/PageInformationTest.java
@@ -19,6 +19,8 @@
import static org.junit.Assume.assumeTrue;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -37,9 +39,12 @@
@Test
public void parseHeaderCompleteTest() throws IOException,
InvalidHeaderValueException {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
+
+ final File inputFile = new File("target/images/sampledata.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/PatternDictionaryTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/PatternDictionaryTest.java
index 7329cf0..63b333c 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/segments/PatternDictionaryTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/PatternDictionaryTest.java
@@ -19,6 +19,8 @@
import static org.junit.Assume.assumeTrue;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -36,9 +38,12 @@
public class PatternDictionaryTest {
@Test
public void parseHeaderTest() throws IOException, InvalidHeaderValueException {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
+
+ final File inputFile = new File("target/images/sampledata.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
@@ -59,11 +64,14 @@
@Ignore
@Test
public void decodeTestWithOutput() throws Throwable {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
- DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
- // skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ final File inputFile = new File("target/images/sampledata.jb2");
+ // skip test if input stream isn't available
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
+
+ DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
// Sixth Segment (number 5)
SubInputStream sis = new SubInputStream(iis, 245, 45);
@@ -83,9 +91,12 @@
@Ignore
@Test
public void decodeTestWithOutput2() throws Throwable {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
+
+ final File inputFile = new File("target/images/sampledata.jb2");
// skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ assumeTrue(inputFile.exists());
+
+ final InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/RegionSegmentInformationTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/RegionSegmentInformationTest.java
index cca5438..89f86ec 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/segments/RegionSegmentInformationTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/RegionSegmentInformationTest.java
@@ -19,6 +19,8 @@
import static org.junit.Assume.assumeTrue;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -34,10 +36,12 @@
@Test
public void parseHeaderTest() throws IOException {
- InputStream inputStream = getClass().getResourceAsStream("/images/sampledata.jb2");
- // skip test if input stream isn't available
- assumeTrue(inputStream != null && inputStream.available() > 0);
+ final File inputFile = new File("target/images/sampledata.jb2");
+ // skip test if input stream isn't available
+ assumeTrue(inputFile.exists());
+
+ InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
ImageInputStream iis = disf.getInputStream(inputStream);
SubInputStream sis = new SubInputStream(iis, 130, 49);
diff --git a/src/test/java/org/apache/pdfbox/jbig2/segments/TextRegionTest.java b/src/test/java/org/apache/pdfbox/jbig2/segments/TextRegionTest.java
index da6f961..3aefea4 100644
--- a/src/test/java/org/apache/pdfbox/jbig2/segments/TextRegionTest.java
+++ b/src/test/java/org/apache/pdfbox/jbig2/segments/TextRegionTest.java
@@ -17,7 +17,11 @@
package org.apache.pdfbox.jbig2.segments;
+import static org.junit.Assume.assumeTrue;
+
import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -40,12 +44,16 @@
@Ignore
@Test
public void textRegionWith() throws IOException, InvalidHeaderValueException, IntegerMaxValueException {
- String filepath = "/images/042_11.jb2";
+
int pageNumber = 1;
- InputStream is = getClass().getResourceAsStream(filepath);
+ final File inputFile = new File("target/images/042_11.jb2");
+ // skip test if input stream isn't available
+ assumeTrue(inputFile.exists());
+
+ InputStream inputStream = new FileInputStream(inputFile);
DefaultInputStreamFactory disf = new DefaultInputStreamFactory();
- ImageInputStream iis = disf.getInputStream(is);
+ ImageInputStream iis = disf.getInputStream(inputStream);
JBIG2ImageReader jb2 = new JBIG2ImageReader(new JBIG2ImageReaderSpi());
jb2.setInput(iis);
BufferedImage b = jb2.read(pageNumber);
diff --git a/src/test/resources/com/levigo/jbig2/github/21.glob b/src/test/resources/org/apache/pdfbox/jbig2/github/21.glob
similarity index 100%
rename from src/test/resources/com/levigo/jbig2/github/21.glob
rename to src/test/resources/org/apache/pdfbox/jbig2/github/21.glob
Binary files differ
diff --git a/src/test/resources/com/levigo/jbig2/github/21.jb2 b/src/test/resources/org/apache/pdfbox/jbig2/github/21.jb2
similarity index 100%
rename from src/test/resources/com/levigo/jbig2/github/21.jb2
rename to src/test/resources/org/apache/pdfbox/jbig2/github/21.jb2
Binary files differ