PDFBOX-4098: reformat the source code, introduce an eclipse formatter definition


Project: http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/repo
Commit: http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/commit/30839c32
Tree: http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/tree/30839c32
Diff: http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/diff/30839c32

Branch: refs/heads/master
Commit: 30839c32a60c9a1012bb992046cc0bdae3b38ba8
Parents: ec61ccc
Author: Andreas Lehmkühler <andr...@lehmi.de>
Authored: Fri Feb 9 18:03:36 2018 +0100
Committer: Andreas Lehmkühler <andr...@lehmi.de>
Committed: Fri Feb 9 18:03:36 2018 +0100

----------------------------------------------------------------------
 .../java/org/apache/pdfbox/jbig2/Bitmap.java    |  357 ++--
 .../org/apache/pdfbox/jbig2/Dictionary.java     |   24 +-
 .../org/apache/pdfbox/jbig2/JBIG2Document.java  |  572 +++---
 .../org/apache/pdfbox/jbig2/JBIG2Globals.java   |   52 +-
 .../apache/pdfbox/jbig2/JBIG2ImageMetadata.java |  134 +-
 .../pdfbox/jbig2/JBIG2ImageMetadataFormat.java  |   54 +-
 .../apache/pdfbox/jbig2/JBIG2ImageReader.java   |  548 +++---
 .../pdfbox/jbig2/JBIG2ImageReaderSpi.java       |  174 +-
 .../java/org/apache/pdfbox/jbig2/JBIG2Page.java |  652 ++++---
 .../org/apache/pdfbox/jbig2/JBIG2ReadParam.java |   43 +-
 .../java/org/apache/pdfbox/jbig2/Region.java    |   36 +-
 .../org/apache/pdfbox/jbig2/SegmentData.java    |   27 +-
 .../org/apache/pdfbox/jbig2/SegmentHeader.java  |  735 +++----
 .../java/org/apache/pdfbox/jbig2/TestImage.java |  345 ++--
 .../decoder/arithmetic/ArithmeticDecoder.java   |  386 ++--
 .../arithmetic/ArithmeticIntegerDecoder.java    |  241 ++-
 .../pdfbox/jbig2/decoder/arithmetic/CX.java     |   86 +-
 .../jbig2/decoder/huffman/EncodedTable.java     |  104 +-
 .../jbig2/decoder/huffman/FixedSizeTable.java   |   10 +-
 .../jbig2/decoder/huffman/HuffmanTable.java     |  156 +-
 .../jbig2/decoder/huffman/InternalNode.java     |  194 +-
 .../pdfbox/jbig2/decoder/huffman/Node.java      |    5 +-
 .../jbig2/decoder/huffman/OutOfBandNode.java    |   22 +-
 .../jbig2/decoder/huffman/StandardTables.java   |  493 ++---
 .../pdfbox/jbig2/decoder/huffman/ValueNode.java |   61 +-
 .../pdfbox/jbig2/decoder/mmr/MMRConstants.java  |  992 +++-------
 .../jbig2/decoder/mmr/MMRDecompressor.java      | 1106 ++++++-----
 .../jbig2/err/IntegerMaxValueException.java     |   31 +-
 .../jbig2/err/InvalidHeaderValueException.java  |   31 +-
 .../apache/pdfbox/jbig2/err/JBIG2Exception.java |   31 +-
 .../pdfbox/jbig2/image/BitmapScanline.java      |  201 +-
 .../org/apache/pdfbox/jbig2/image/Bitmaps.java  | 1013 +++++-----
 .../org/apache/pdfbox/jbig2/image/Filter.java   |  943 ++++-----
 .../apache/pdfbox/jbig2/image/FilterType.java   |   38 +-
 .../pdfbox/jbig2/image/ParameterizedFilter.java |   83 +-
 .../org/apache/pdfbox/jbig2/image/Resizer.java  |  696 +++----
 .../org/apache/pdfbox/jbig2/image/Scanline.java |  986 +++++-----
 .../apache/pdfbox/jbig2/image/Weighttab.java    |  175 +-
 .../jbig2/io/DefaultInputStreamFactory.java     |   19 +-
 .../pdfbox/jbig2/io/InputStreamFactory.java     |    5 +-
 .../apache/pdfbox/jbig2/io/SubInputStream.java  |  237 +--
 .../pdfbox/jbig2/segments/EndOfStripe.java      |   41 +-
 .../jbig2/segments/GenericRefinementRegion.java | 1449 ++++++++------
 .../pdfbox/jbig2/segments/GenericRegion.java    | 1680 ++++++++--------
 .../pdfbox/jbig2/segments/HalftoneRegion.java   |  701 +++----
 .../pdfbox/jbig2/segments/PageInformation.java  |  315 +--
 .../jbig2/segments/PatternDictionary.java       |  328 ++--
 .../apache/pdfbox/jbig2/segments/Profiles.java  |    8 +-
 .../segments/RegionSegmentInformation.java      |  162 +-
 .../pdfbox/jbig2/segments/SymbolDictionary.java | 1575 ++++++++-------
 .../org/apache/pdfbox/jbig2/segments/Table.java |  108 +-
 .../pdfbox/jbig2/segments/TextRegion.java       | 1836 ++++++++++--------
 .../pdfbox/jbig2/util/CombinationOperator.java  |   33 +-
 .../pdfbox/jbig2/util/DictionaryViewer.java     |   54 +-
 .../apache/pdfbox/jbig2/util/ServiceLookup.java |   33 +-
 .../org/apache/pdfbox/jbig2/util/Utils.java     |  159 +-
 .../apache/pdfbox/jbig2/util/cache/Cache.java   |   49 +-
 .../pdfbox/jbig2/util/cache/CacheBridge.java    |    5 +-
 .../pdfbox/jbig2/util/cache/CacheFactory.java   |   58 +-
 .../jbig2/util/cache/SoftReferenceCache.java    |   60 +-
 .../util/cache/SoftReferenceCacheBridge.java    |   12 +-
 .../apache/pdfbox/jbig2/util/log/JDKLogger.java |  149 +-
 .../pdfbox/jbig2/util/log/JDKLoggerBridge.java  |   10 +-
 .../apache/pdfbox/jbig2/util/log/Logger.java    |  227 ++-
 .../pdfbox/jbig2/util/log/LoggerBridge.java     |    5 +-
 .../pdfbox/jbig2/util/log/LoggerFactory.java    |   55 +-
 .../org/apache/pdfbox/jbig2/BitmapTest.java     |  147 +-
 .../apache/pdfbox/jbig2/ChecksumCalculator.java |   48 +-
 .../org/apache/pdfbox/jbig2/ChecksumTest.java   |  224 +--
 .../apache/pdfbox/jbig2/GithubIssuesTest.java   |   63 +-
 .../pdfbox/jbig2/JBIG2DocumentFacade.java       |   51 +-
 .../pdfbox/jbig2/JBIG2ImageReaderDemo.java      |   59 +-
 .../pdfbox/jbig2/JBIG2ImageReaderTest.java      |  194 +-
 .../org/apache/pdfbox/jbig2/JBIG2PageTest.java  |  148 +-
 .../jbig2/PreconfiguredImageReadParam.java      |   71 +-
 .../arithmetic/ArithmeticDecoderTest.java       |  697 ++-----
 .../ArithmeticIntegerDecoderTest.java           |   24 +-
 .../jbig2/decoder/mmr/MMRDecompressorTest.java  |    7 +-
 .../pdfbox/jbig2/image/BitmapsBlitTest.java     |   75 +-
 .../jbig2/image/BitmapsByteCombinationTest.java |   63 +-
 .../pdfbox/jbig2/image/BitmapsChecksumTest.java |  244 ++-
 .../jbig2/segments/GenericRegionTest.java       |  207 +-
 .../jbig2/segments/HalftoneRegionTest.java      |   52 +-
 .../jbig2/segments/PageInformationTest.java     |  125 +-
 .../jbig2/segments/PatternDictionaryTest.java   |  162 +-
 .../segments/RegionSegmentInformationTest.java  |   44 +-
 .../jbig2/segments/SymbolDictionaryTest.java    |    5 +-
 .../pdfbox/jbig2/segments/TextRegionTest.java   |   39 +-
 .../pdfbox/jbig2/util/CacheFactoryTest.java     |   30 +-
 .../pdfbox/jbig2/util/LoggerFactoryTest.java    |   28 +-
 .../pdfbox/jbig2/util/ServiceLookupTest.java    |   59 +-
 .../apache/pdfbox/jbig2/util/TestService.java   |    5 +-
 .../pdfbox/jbig2/util/TestServiceImpl.java      |    5 +-
 93 files changed, 12492 insertions(+), 11594 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java 
b/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
index 7dbc38d..96c2250 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/Bitmap.java
@@ -22,177 +22,188 @@ import java.awt.Rectangle;
 /**
  * This class represents a bi-level image that is organized like a bitmap.
  */
-public class Bitmap {
-
-
-  /** The height of the bitmap in pixels. */
-  private final int height;
-
-  /** The width of the bitmap in pixels. */
-  private final int width;
-
-  /** The amount of bytes used per row. */
-  private final int rowStride;
-
-  /** 8 pixels per byte, 0 for white, 1 for black */
-  private byte[] bitmap;
-
-  /**
-   * Creates an instance of a blank image.<br>
-   * The image data is stored in a byte array. Each pixels is stored as one 
bit, so that each byte
-   * contains 8 pixel. A pixel has by default the value {@code 0} for white 
and {@code 1} for black. <br>
-   * Row stride means the amount of bytes per line. It is computed 
automatically and fills the pad
-   * bits with 0.<br>
-   * 
-   * @param height - The real height of the bitmap in pixels.
-   * @param width - The real width of the bitmap in pixels.
-   */
-  public Bitmap(int width, int height) {
-    this.height = height;
-    this.width = width;
-    this.rowStride = (width + 7) >> 3;
-
-    bitmap = new byte[this.height * this.rowStride];
-  }
-
-  /**
-   * Returns the value of a pixel specified by the given coordinates.
-   * <p>
-   * By default, the value is {@code 0} for a white pixel and {@code 1} for a 
black pixel. The value
-   * is placed in the rightmost bit in the byte.
-   * 
-   * @param x - The x coordinate of the pixel.
-   * @param y - The y coordinate of the pixel.
-   * @return The value of a pixel.
-   */
-  public byte getPixel(int x, int y) {
-    int byteIndex = this.getByteIndex(x, y);
-    int bitOffset = this.getBitOffset(x);
-
-    int toShift = 7 - bitOffset;
-    return (byte) ((this.getByte(byteIndex) >> toShift) & 0x01);
-  }
-  
-  public void setPixel(int x, int y, byte pixelValue) {
-    final int byteIndex = getByteIndex(x, y);
-    final int bitOffset = getBitOffset(x);
-    
-    final int shift = 7 - bitOffset;
-    
-    final byte src = bitmap[byteIndex];
-    final byte result = (byte) (src | (pixelValue << shift));
-    bitmap[byteIndex] = result;
-  }
-
-  /**
-   * 
-   * <p>
-   * Returns the index of the byte that contains the pixel, specified by the 
pixel's x and y
-   * coordinates.
-   * 
-   * @param x - The pixel's x coordinate.
-   * @param y - The pixel's y coordinate.
-   * @return The index of the byte that contains the specified pixel.
-   */
-  public int getByteIndex(int x, int y) {
-    return y * this.rowStride + (x >> 3);
-  }
-
-  /**
-   * Simply returns the byte array of this bitmap.
-   * 
-   * @return The byte array of this bitmap.
-   */
-  public byte[] getByteArray() {
-    return bitmap;
-  }
-
-  /**
-   * Simply returns a byte from the bitmap byte array. Throws an {@link 
IndexOutOfBoundsException}
-   * if the given index is out of bound.
-   * 
-   * @param index - The array index that specifies the position of the wanted 
byte.
-   * @return The byte at the {@code index}-position.
-   * 
-   * @throws IndexOutOfBoundsException if the index is out of bound.
-   */
-  public byte getByte(int index) {
-    return this.bitmap[index];
-  }
-
-  /**
-   * Simply sets the given value at the given array index position. Throws an
-   * {@link IndexOutOfBoundsException} if the given index is out of bound.
-   * 
-   * @param index - The array index that specifies the position of a byte.
-   * @param value - The byte that should be set.
-   * 
-   * @throws IndexOutOfBoundsException if the index is out of bound.
-   */
-  public void setByte(int index, byte value) {
-    this.bitmap[index] = value;
-  }
-
-  /**
-   * Converts the byte at specified index into an integer and returns the 
value. Throws an
-   * {@link IndexOutOfBoundsException} if the given index is out of bound.
-   * 
-   * @param index - The array index that specifies the position of the wanted 
byte.
-   * @return The converted byte at the {@code index}-position as an integer.
-   * 
-   * @throws IndexOutOfBoundsException if the index is out of bound.
-   */
-  public int getByteAsInteger(int index) {
-    return (this.bitmap[index] & 0xff);
-  }
-
-
-  /**
-   * Computes the offset of the given x coordinate in its byte. The method 
uses optimized modulo
-   * operation for a better performance.
-   * 
-   * @param x - The x coordinate of a pixel.
-   * @return The bit offset of a pixel in its byte.
-   */
-  public int getBitOffset(int x) {
-    // The same like x % 8.
-    // The rightmost three bits are 1. The value masks all bits upon the value 
"7".
-    return (x & 0x07);
-  }
-
-  /**
-   * Simply returns the height of this bitmap.
-   * 
-   * @return The height of this bitmap.
-   */
-  public int getHeight() {
-    return height;
-  }
-
-  /**
-   * Simply returns the width of this bitmap.
-   * 
-   * @return The width of this bitmap.
-   */
-  public int getWidth() {
-    return width;
-  }
-
-  /**
-   * Simply returns the row stride of this bitmap. <br>
-   * (Row stride means the amount of bytes per line.)
-   * 
-   * @return The row stride of this bitmap.
-   */
-  public int getRowStride() {
-    return rowStride;
-  }
-
-  public Rectangle getBounds() {
-    return new Rectangle(0, 0, width, height);
-  }
-
-  public int getMemorySize() {
-    return bitmap.length;
-  }
+public class Bitmap
+{
+
+    /** The height of the bitmap in pixels. */
+    private final int height;
+
+    /** The width of the bitmap in pixels. */
+    private final int width;
+
+    /** The amount of bytes used per row. */
+    private final int rowStride;
+
+    /** 8 pixels per byte, 0 for white, 1 for black */
+    private byte[] bitmap;
+
+    /**
+     * Creates an instance of a blank image.<br>
+     * The image data is stored in a byte array. Each pixels is stored as one 
bit, so that each byte contains 8 pixel. A
+     * pixel has by default the value {@code 0} for white and {@code 1} for 
black. <br>
+     * Row stride means the amount of bytes per line. It is computed 
automatically and fills the pad bits with 0.<br>
+     * 
+     * @param height - The real height of the bitmap in pixels.
+     * @param width - The real width of the bitmap in pixels.
+     */
+    public Bitmap(int width, int height)
+    {
+        this.height = height;
+        this.width = width;
+        this.rowStride = (width + 7) >> 3;
+
+        bitmap = new byte[this.height * this.rowStride];
+    }
+
+    /**
+     * Returns the value of a pixel specified by the given coordinates.
+     * <p>
+     * By default, the value is {@code 0} for a white pixel and {@code 1} for 
a black pixel. The value is placed in the
+     * rightmost bit in the byte.
+     * 
+     * @param x - The x coordinate of the pixel.
+     * @param y - The y coordinate of the pixel.
+     * @return The value of a pixel.
+     */
+    public byte getPixel(int x, int y)
+    {
+        int byteIndex = this.getByteIndex(x, y);
+        int bitOffset = this.getBitOffset(x);
+
+        int toShift = 7 - bitOffset;
+        return (byte) ((this.getByte(byteIndex) >> toShift) & 0x01);
+    }
+
+    public void setPixel(int x, int y, byte pixelValue)
+    {
+        final int byteIndex = getByteIndex(x, y);
+        final int bitOffset = getBitOffset(x);
+
+        final int shift = 7 - bitOffset;
+
+        final byte src = bitmap[byteIndex];
+        final byte result = (byte) (src | (pixelValue << shift));
+        bitmap[byteIndex] = result;
+    }
+
+    /**
+     * 
+     * <p>
+     * Returns the index of the byte that contains the pixel, specified by the 
pixel's x and y coordinates.
+     * 
+     * @param x - The pixel's x coordinate.
+     * @param y - The pixel's y coordinate.
+     * @return The index of the byte that contains the specified pixel.
+     */
+    public int getByteIndex(int x, int y)
+    {
+        return y * this.rowStride + (x >> 3);
+    }
+
+    /**
+     * Simply returns the byte array of this bitmap.
+     * 
+     * @return The byte array of this bitmap.
+     */
+    public byte[] getByteArray()
+    {
+        return bitmap;
+    }
+
+    /**
+     * Simply returns a byte from the bitmap byte array. Throws an {@link 
IndexOutOfBoundsException} if the given index
+     * is out of bound.
+     * 
+     * @param index - The array index that specifies the position of the 
wanted byte.
+     * @return The byte at the {@code index}-position.
+     * 
+     * @throws IndexOutOfBoundsException if the index is out of bound.
+     */
+    public byte getByte(int index)
+    {
+        return this.bitmap[index];
+    }
+
+    /**
+     * Simply sets the given value at the given array index position. Throws 
an {@link IndexOutOfBoundsException} if the
+     * given index is out of bound.
+     * 
+     * @param index - The array index that specifies the position of a byte.
+     * @param value - The byte that should be set.
+     * 
+     * @throws IndexOutOfBoundsException if the index is out of bound.
+     */
+    public void setByte(int index, byte value)
+    {
+        this.bitmap[index] = value;
+    }
+
+    /**
+     * Converts the byte at specified index into an integer and returns the 
value. Throws an
+     * {@link IndexOutOfBoundsException} if the given index is out of bound.
+     * 
+     * @param index - The array index that specifies the position of the 
wanted byte.
+     * @return The converted byte at the {@code index}-position as an integer.
+     * 
+     * @throws IndexOutOfBoundsException if the index is out of bound.
+     */
+    public int getByteAsInteger(int index)
+    {
+        return (this.bitmap[index] & 0xff);
+    }
+
+    /**
+     * Computes the offset of the given x coordinate in its byte. The method 
uses optimized modulo operation for a
+     * better performance.
+     * 
+     * @param x - The x coordinate of a pixel.
+     * @return The bit offset of a pixel in its byte.
+     */
+    public int getBitOffset(int x)
+    {
+        // The same like x % 8.
+        // The rightmost three bits are 1. The value masks all bits upon the 
value "7".
+        return (x & 0x07);
+    }
+
+    /**
+     * Simply returns the height of this bitmap.
+     * 
+     * @return The height of this bitmap.
+     */
+    public int getHeight()
+    {
+        return height;
+    }
+
+    /**
+     * Simply returns the width of this bitmap.
+     * 
+     * @return The width of this bitmap.
+     */
+    public int getWidth()
+    {
+        return width;
+    }
+
+    /**
+     * Simply returns the row stride of this bitmap. <br>
+     * (Row stride means the amount of bytes per line.)
+     * 
+     * @return The row stride of this bitmap.
+     */
+    public int getRowStride()
+    {
+        return rowStride;
+    }
+
+    public Rectangle getBounds()
+    {
+        return new Rectangle(0, 0, width, height);
+    }
+
+    public int getMemorySize()
+    {
+        return bitmap.length;
+    }
 }

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/Dictionary.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pdfbox/jbig2/Dictionary.java 
b/src/main/java/org/apache/pdfbox/jbig2/Dictionary.java
index 3598f09..5d9365b 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/Dictionary.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/Dictionary.java
@@ -26,16 +26,18 @@ import 
org.apache.pdfbox.jbig2.err.InvalidHeaderValueException;
 /**
  * Interface for all JBIG2 dictionaries segments.
  */
-public interface Dictionary extends SegmentData {
+public interface Dictionary extends SegmentData
+{
 
-  /**
-   * Decodes a dictionary segment and returns the result.
-   * 
-   * @return A list of {@link Bitmap}s as a result of the decoding process of 
dictionary segments.
-   * 
-   * @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;
+    /**
+     * Decodes a dictionary segment and returns the result.
+     * 
+     * @return A list of {@link Bitmap}s as a result of the decoding process 
of dictionary segments.
+     * 
+     * @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;
 }

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/JBIG2Document.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pdfbox/jbig2/JBIG2Document.java 
b/src/main/java/org/apache/pdfbox/jbig2/JBIG2Document.java
index 395c348..41b6657 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/JBIG2Document.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/JBIG2Document.java
@@ -33,312 +33,348 @@ import org.apache.pdfbox.jbig2.util.log.LoggerFactory;
 /**
  * This class represents the document structure with its pages and global 
segments.
  */
-class JBIG2Document {
-  private static final Logger log = 
LoggerFactory.getLogger(JBIG2Document.class);
-
-  /** ID string in file header, see ISO/IEC 14492:2001, D.4.1 */
-  private int[] FILE_HEADER_ID = {
-      0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A
-  };
-
-  /**
-   * This map contains all pages of this document. The key is the number of 
the page.
-   */
-  private final Map<Integer, JBIG2Page> pages = new TreeMap<Integer, 
JBIG2Page>();
-
-
-  /** BASIC INFORMATION ABOUT THE CURRENT JBIG2 DOCUMENT */
-
-  /** The length of the file header if exists */
-  private short fileHeaderLength = 9;
-
-  /**
-   * According to D.4.2 - File header bit 0
-   * <p>
-   * This flag contains information about the file organization:
-   * <ul>
-   * <li>{@code 1} for sequential</li>
-   * <li>{@code 0} for random-access</li>
-   * </ul>
-   * You can use the constants {@link #RANDOM} and {@link 
JBIG2Document#SEQUENTIAL}.
-   */
-  private short organisationType = SEQUENTIAL;
-
-  public static final int RANDOM = 0;
-  public static final int SEQUENTIAL = 1;
-
-  /**
-   * According to D.4.2 - Bit 1<br>
-   * <ul>
-   * <li>{@code true} if amount of pages is unknown, amount of pages field is 
not present</li>
-   * <li>{@code false} if there is a field in the file header where the amount 
of pages can be read</li>
-   * </ul>
-   */
-  private boolean amountOfPagesUnknown = true;
-
-  /**
-   * According to D.4.3 - Number of pages field (4 bytes). Only present if
-   * {@link #amountOfPagesUnknown} is {@code false}.
-   */
-  private int amountOfPages;
-
-  /** Defines whether extended Template is used. */
-  private boolean gbUseExtTemplate;
-
-  /**
-   * This is the source data stream wrapped into a {@link SubInputStream}.
-   */
-  private final SubInputStream subInputStream;
-
-  /**
-   * Flag:
-   * <ul>
-   * <li>{@code true} if stream is embedded in another file format and the 
file header is missing</li>
-   * <li>{@code false} if stream is created of a native jbig2 file and the 
file header should be
-   * present</li>
-   * </ul>
-   */
-
-  /**
-   * Holds a load of segments, that aren't associated with a page.
-   */
-  private JBIG2Globals globalSegments;
-
-  protected JBIG2Document(ImageInputStream input) throws IOException {
-    this(input, null);
-  }
-
-  protected JBIG2Document(ImageInputStream input, JBIG2Globals globals) throws 
IOException {
-    if (input == null)
-      throw new IllegalArgumentException("imageInputStream must not be null");
-
-    this.subInputStream = new SubInputStream(input, 0, Long.MAX_VALUE);
-    this.globalSegments = globals;
-
-    mapStream();
-  }
-
-  /**
-   * Retrieves the segment with the given segment number considering only 
segments that aren't
-   * associated with a page.
-   * 
-   * @param segmentNr - The number of the wanted segment.
-   * @return The requested {@link SegmentHeader}.
-   */
-  SegmentHeader getGlobalSegment(int segmentNr) {
-    if (null != globalSegments) {
-      return globalSegments.getSegment(segmentNr);
-    }
+class JBIG2Document
+{
+    private static final Logger log = 
LoggerFactory.getLogger(JBIG2Document.class);
 
-    if (log.isErrorEnabled()) {
-      log.error("Segment not found. Returning null.");
-    }
+    /** ID string in file header, see ISO/IEC 14492:2001, D.4.1 */
+    private int[] FILE_HEADER_ID = { 0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 
0x0A };
 
-    return null;
-  }
-
-  /**
-   * Retrieves a {@link JBIG2Page} specified by the given page number.
-   * 
-   * @param pageNumber - The page number of the wanted {@link JBIG2Page}.
-   * 
-   * @return The requested {@link JBIG2Page}.
-   */
-  protected JBIG2Page getPage(int pageNumber) {
-    return pages.get(pageNumber);
-  }
-
-  /**
-   * Retrieves the amount of pages in this JBIG2 document. If the pages are 
striped, the document
-   * will be completely parsed and the amount of pages will be gathered.
-   * 
-   * @return The amount of pages in this JBIG2 document.
-   * @throws IOException
-   */
-  protected int getAmountOfPages() throws IOException {
-    if (amountOfPagesUnknown || amountOfPages == 0) {
-      if (pages.size() == 0) {
-        mapStream();
-      }
+    /**
+     * This map contains all pages of this document. The key is the number of 
the page.
+     */
+    private final Map<Integer, JBIG2Page> pages = new TreeMap<Integer, 
JBIG2Page>();
+
+    /** BASIC INFORMATION ABOUT THE CURRENT JBIG2 DOCUMENT */
+
+    /** The length of the file header if exists */
+    private short fileHeaderLength = 9;
+
+    /**
+     * According to D.4.2 - File header bit 0
+     * <p>
+     * This flag contains information about the file organization:
+     * <ul>
+     * <li>{@code 1} for sequential</li>
+     * <li>{@code 0} for random-access</li>
+     * </ul>
+     * You can use the constants {@link #RANDOM} and {@link 
JBIG2Document#SEQUENTIAL}.
+     */
+    private short organisationType = SEQUENTIAL;
 
-      return pages.size();
-    } else {
-      return amountOfPages;
-    }
-  }
+    public static final int RANDOM = 0;
+    public static final int SEQUENTIAL = 1;
 
-  /**
-   * This method maps the stream and stores all segments.
-   */
-  private void mapStream() throws IOException {
-    final List<SegmentHeader> segments = new LinkedList<SegmentHeader>();
+    /**
+     * According to D.4.2 - Bit 1<br>
+     * <ul>
+     * <li>{@code true} if amount of pages is unknown, amount of pages field 
is not present</li>
+     * <li>{@code false} if there is a field in the file header where the 
amount of pages can be read</li>
+     * </ul>
+     */
+    private boolean amountOfPagesUnknown = true;
 
-    long offset = 0;
-    int segmentType = 0;
+    /**
+     * According to D.4.3 - Number of pages field (4 bytes). Only present if 
{@link #amountOfPagesUnknown} is
+     * {@code false}.
+     */
+    private int amountOfPages;
+
+    /** Defines whether extended Template is used. */
+    private boolean gbUseExtTemplate;
 
-    /*
-     * Parse the file header if there is one.
+    /**
+     * This is the source data stream wrapped into a {@link SubInputStream}.
      */
-    if (isFileHeaderPresent()) {
-      parseFileHeader();
-      offset += fileHeaderLength;
-    }
+    private final SubInputStream subInputStream;
+
+    /**
+     * Flag:
+     * <ul>
+     * <li>{@code true} if stream is embedded in another file format and the 
file header is missing</li>
+     * <li>{@code false} if stream is created of a native jbig2 file and the 
file header should be present</li>
+     * </ul>
+     */
+
+    /**
+     * Holds a load of segments, that aren't associated with a page.
+     */
+    private JBIG2Globals globalSegments;
 
-    if (globalSegments == null) {
-      globalSegments = new JBIG2Globals();
+    protected JBIG2Document(ImageInputStream input) throws IOException
+    {
+        this(input, null);
     }
 
-    JBIG2Page page = null;
+    protected JBIG2Document(ImageInputStream input, JBIG2Globals globals) 
throws IOException
+    {
+        if (input == null)
+            throw new IllegalArgumentException("imageInputStream must not be 
null");
 
-    /*
-     * If organisation type is random-access: walk through the segment headers 
until EOF segment
-     * appears (specified with segment number 51)
-     */
-    while (segmentType != 51 && !reachedEndOfStream(offset)) {
-      SegmentHeader segment = new SegmentHeader(this, subInputStream, offset, 
organisationType);
+        this.subInputStream = new SubInputStream(input, 0, Long.MAX_VALUE);
+        this.globalSegments = globals;
 
-      final int associatedPage = segment.getPageAssociation();
-      segmentType = segment.getSegmentType();
+        mapStream();
+    }
 
-      if (associatedPage != 0) {
-        page = getPage(associatedPage);
-        if (page == null) {
-          page = new JBIG2Page(this, associatedPage);
-          pages.put(associatedPage, page);
+    /**
+     * Retrieves the segment with the given segment number considering only 
segments that aren't associated with a page.
+     * 
+     * @param segmentNr - The number of the wanted segment.
+     * @return The requested {@link SegmentHeader}.
+     */
+    SegmentHeader getGlobalSegment(int segmentNr)
+    {
+        if (null != globalSegments)
+        {
+            return globalSegments.getSegment(segmentNr);
         }
-        page.add(segment);
-      } else {
-        globalSegments.addSegment(segment.getSegmentNr(), segment);
-      }
-      segments.add(segment);
-
-      if (JBIG2ImageReader.DEBUG) {
-        if (log.isDebugEnabled()) {
-          log.debug(segment.toString());
+
+        if (log.isErrorEnabled())
+        {
+            log.error("Segment not found. Returning null.");
         }
-      }
 
-      offset = subInputStream.getStreamPosition();
+        return null;
+    }
 
-      // Sequential organization skips data part and sets the offset
-      if (organisationType == SEQUENTIAL) {
-        offset += segment.getSegmentDataLength();
-      }
+    /**
+     * Retrieves a {@link JBIG2Page} specified by the given page number.
+     * 
+     * @param pageNumber - The page number of the wanted {@link JBIG2Page}.
+     * 
+     * @return The requested {@link JBIG2Page}.
+     */
+    protected JBIG2Page getPage(int pageNumber)
+    {
+        return pages.get(pageNumber);
     }
 
-    /*
-     * Random organization: segment headers are finished. Data part starts and 
the offset can be
-     * set.
+    /**
+     * Retrieves the amount of pages in this JBIG2 document. If the pages are 
striped, the document will be completely
+     * parsed and the amount of pages will be gathered.
+     * 
+     * @return The amount of pages in this JBIG2 document.
+     * @throws IOException
      */
-    determineRandomDataOffsets(segments, offset);
-  }
+    protected int getAmountOfPages() throws IOException
+    {
+        if (amountOfPagesUnknown || amountOfPages == 0)
+        {
+            if (pages.size() == 0)
+            {
+                mapStream();
+            }
+
+            return pages.size();
+        }
+        else
+        {
+            return amountOfPages;
+        }
+    }
+
+    /**
+     * This method maps the stream and stores all segments.
+     */
+    private void mapStream() throws IOException
+    {
+        final List<SegmentHeader> segments = new LinkedList<SegmentHeader>();
+
+        long offset = 0;
+        int segmentType = 0;
+
+        /*
+         * Parse the file header if there is one.
+         */
+        if (isFileHeaderPresent())
+        {
+            parseFileHeader();
+            offset += fileHeaderLength;
+        }
 
-  private boolean isFileHeaderPresent() throws IOException {
-    final SubInputStream input = subInputStream;
-    input.mark();
+        if (globalSegments == null)
+        {
+            globalSegments = new JBIG2Globals();
+        }
+
+        JBIG2Page page = null;
+
+        /*
+         * If organisation type is random-access: walk through the segment 
headers until EOF segment appears (specified
+         * with segment number 51)
+         */
+        while (segmentType != 51 && !reachedEndOfStream(offset))
+        {
+            SegmentHeader segment = new SegmentHeader(this, subInputStream, 
offset,
+                    organisationType);
+
+            final int associatedPage = segment.getPageAssociation();
+            segmentType = segment.getSegmentType();
+
+            if (associatedPage != 0)
+            {
+                page = getPage(associatedPage);
+                if (page == null)
+                {
+                    page = new JBIG2Page(this, associatedPage);
+                    pages.put(associatedPage, page);
+                }
+                page.add(segment);
+            }
+            else
+            {
+                globalSegments.addSegment(segment.getSegmentNr(), segment);
+            }
+            segments.add(segment);
+
+            if (JBIG2ImageReader.DEBUG)
+            {
+                if (log.isDebugEnabled())
+                {
+                    log.debug(segment.toString());
+                }
+            }
+
+            offset = subInputStream.getStreamPosition();
+
+            // Sequential organization skips data part and sets the offset
+            if (organisationType == SEQUENTIAL)
+            {
+                offset += segment.getSegmentDataLength();
+            }
+        }
+
+        /*
+         * Random organization: segment headers are finished. Data part starts 
and the offset can be set.
+         */
+        determineRandomDataOffsets(segments, offset);
+    }
+
+    private boolean isFileHeaderPresent() throws IOException
+    {
+        final SubInputStream input = subInputStream;
+        input.mark();
+
+        for (int magicByte : FILE_HEADER_ID)
+        {
+            if (magicByte != input.read())
+            {
+                input.reset();
+                return false;
+            }
+        }
 
-    for (int magicByte : FILE_HEADER_ID) {
-      if (magicByte != input.read()) {
         input.reset();
-        return false;
-      }
+        return true;
     }
 
-    input.reset();
-    return true;
-  }
-
-  /**
-   * Determines the start of the data parts and sets the offset.
-   * 
-   * @param segments
-   * @param offset
-   */
-  private void determineRandomDataOffsets(List<SegmentHeader> segments, long 
offset) {
-    if (organisationType == RANDOM) {
-      for (SegmentHeader s : segments) {
-        s.setSegmentDataStartOffset(offset);
-        offset += s.getSegmentDataLength();
-      }
+    /**
+     * Determines the start of the data parts and sets the offset.
+     * 
+     * @param segments
+     * @param offset
+     */
+    private void determineRandomDataOffsets(List<SegmentHeader> segments, long 
offset)
+    {
+        if (organisationType == RANDOM)
+        {
+            for (SegmentHeader s : segments)
+            {
+                s.setSegmentDataStartOffset(offset);
+                offset += s.getSegmentDataLength();
+            }
+        }
     }
-  }
-
-  /**
-   * This method reads the stream and sets variables for information about 
organization type and
-   * length etc.
-   * 
-   * @return
-   * @throws IOException
-   */
-  private void parseFileHeader() throws IOException {
-    subInputStream.seek(0);
-
-    /* D.4.1 - ID string, read will be skipped */
-    subInputStream.skipBytes(8);
-
-    /*
-     * D.4.2 Header flag (1 byte)
+
+    /**
+     * This method reads the stream and sets variables for information about 
organization type and length etc.
+     * 
+     * @return
+     * @throws IOException
      */
+    private void parseFileHeader() throws IOException
+    {
+        subInputStream.seek(0);
 
-    // Bit 3-7 are reserved and must be 0
-    subInputStream.readBits(5);
+        /* D.4.1 - ID string, read will be skipped */
+        subInputStream.skipBytes(8);
 
-    // Bit 2 - Indicates if extended templates are used
-    if (subInputStream.readBit() == 1) {
-      gbUseExtTemplate = true;
-    }
+        /*
+         * D.4.2 Header flag (1 byte)
+         */
 
-    // Bit 1 - Indicates if amount of pages are unknown
-    if (subInputStream.readBit() != 1) {
-      amountOfPagesUnknown = false;
-    }
+        // Bit 3-7 are reserved and must be 0
+        subInputStream.readBits(5);
+
+        // Bit 2 - Indicates if extended templates are used
+        if (subInputStream.readBit() == 1)
+        {
+            gbUseExtTemplate = true;
+        }
+
+        // Bit 1 - Indicates if amount of pages are unknown
+        if (subInputStream.readBit() != 1)
+        {
+            amountOfPagesUnknown = false;
+        }
 
-    // Bit 0 - Indicates file organisation type
-    organisationType = (short) subInputStream.readBit();
+        // Bit 0 - Indicates file organisation type
+        organisationType = (short) subInputStream.readBit();
 
-    // fileHeaderLength = 9;
+        // fileHeaderLength = 9;
+
+        /*
+         * D.4.3 Number of pages (field is only present if amount of pages are 
'NOT unknown')
+         */
+        if (!amountOfPagesUnknown)
+        {
+            amountOfPages = (int) subInputStream.readUnsignedInt();
+            fileHeaderLength = 13;
+        }
 
-    /*
-     * D.4.3 Number of pages (field is only present if amount of pages are 
'NOT unknown')
-     */
-    if (!amountOfPagesUnknown) {
-      amountOfPages = (int) subInputStream.readUnsignedInt();
-      fileHeaderLength = 13;
     }
 
-  }
-
-  /**
-   * This method checks, if the stream is at its end to avoid {@link 
EOFException}s and reads 32
-   * bits.
-   * 
-   * @param offset
-   * @return <li>{@code true} if end of stream reached <li>{@code false} if 
there are more bytes to
-   *         read
-   * @throws IOException
-   */
-  private boolean reachedEndOfStream(long offset) throws IOException {
-    try {
-      subInputStream.seek(offset);
-      subInputStream.readBits(32);
-      return false;
-    } catch (EOFException e) {
-      return true;
-    } catch (IndexOutOfBoundsException e) {
-      return true;
+    /**
+     * This method checks, if the stream is at its end to avoid {@link 
EOFException}s and reads 32 bits.
+     * 
+     * @param offset
+     * @return
+     * <li>{@code true} if end of stream reached
+     * <li>{@code false} if there are more bytes to read
+     * @throws IOException
+     */
+    private boolean reachedEndOfStream(long offset) throws IOException
+    {
+        try
+        {
+            subInputStream.seek(offset);
+            subInputStream.readBits(32);
+            return false;
+        }
+        catch (EOFException e)
+        {
+            return true;
+        }
+        catch (IndexOutOfBoundsException e)
+        {
+            return true;
+        }
     }
-  }
 
-  protected JBIG2Globals getGlobalSegments() {
-    return globalSegments;
-  }
+    protected JBIG2Globals getGlobalSegments()
+    {
+        return globalSegments;
+    }
 
-  protected boolean isAmountOfPagesUnknown() {
-    return amountOfPagesUnknown;
-  }
+    protected boolean isAmountOfPagesUnknown()
+    {
+        return amountOfPagesUnknown;
+    }
 
-  boolean isGbUseExtTemplate() {
-    return gbUseExtTemplate;
-  }
+    boolean isGbUseExtTemplate()
+    {
+        return gbUseExtTemplate;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/JBIG2Globals.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pdfbox/jbig2/JBIG2Globals.java 
b/src/main/java/org/apache/pdfbox/jbig2/JBIG2Globals.java
index 1f8f0fe..2f1273a 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/JBIG2Globals.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/JBIG2Globals.java
@@ -23,37 +23,39 @@ import java.util.Map;
 import org.apache.pdfbox.jbig2.util.log.Logger;
 import org.apache.pdfbox.jbig2.util.log.LoggerFactory;
 
-
 /**
  * This class stores segments, that aren't associated to a page.
  * 
- * If the data is embedded in another format, for example PDF, this segments 
might be stored
- * separately in the file.
+ * If the data is embedded in another format, for example PDF, this segments 
might be stored separately in the file.
  * 
- * This segments will be decoded on demand and all results are stored in the 
document object and can
- * be retrieved from there.
+ * This segments will be decoded on demand and all results are stored in the 
document object and can be retrieved from
+ * there.
  */
-public class JBIG2Globals {
-  private static final Logger log = 
LoggerFactory.getLogger(JBIG2Globals.class);
-
-  /**
-   * This map contains all segments, that are not associated with a page. The 
key is the segment
-   * number.
-   */
-  private Map<Integer, SegmentHeader> globalSegments = new HashMap<Integer, 
SegmentHeader>();
-
-  protected SegmentHeader getSegment(int segmentNr) {
-    if (globalSegments.size() == 0) {
-      if (log.isErrorEnabled()) {
-        log.error("No global segment added so far. Use 
JBIG2ImageReader.setGlobals().");
-      }
+public class JBIG2Globals
+{
+    private static final Logger log = 
LoggerFactory.getLogger(JBIG2Globals.class);
+
+    /**
+     * This map contains all segments, that are not associated with a page. 
The key is the segment number.
+     */
+    private Map<Integer, SegmentHeader> globalSegments = new HashMap<Integer, 
SegmentHeader>();
+
+    protected SegmentHeader getSegment(int segmentNr)
+    {
+        if (globalSegments.size() == 0)
+        {
+            if (log.isErrorEnabled())
+            {
+                log.error("No global segment added so far. Use 
JBIG2ImageReader.setGlobals().");
+            }
+        }
+
+        return globalSegments.get(segmentNr);
     }
 
-    return globalSegments.get(segmentNr);
-  }
-
-  protected void addSegment(Integer segmentNumber, SegmentHeader segment) {
-    globalSegments.put(segmentNumber, segment);
-  }
+    protected void addSegment(Integer segmentNumber, SegmentHeader segment)
+    {
+        globalSegments.put(segmentNumber, segment);
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadata.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadata.java 
b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadata.java
index a931b10..835db55 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadata.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadata.java
@@ -26,82 +26,98 @@ import org.w3c.dom.Node;
 /**
  * @see IIOMetadata
  */
-public class JBIG2ImageMetadata extends IIOMetadata {
+public class JBIG2ImageMetadata extends IIOMetadata
+{
 
-  static final String IMAGE_METADATA_FORMAT_NAME = "jbig2";
+    static final String IMAGE_METADATA_FORMAT_NAME = "jbig2";
 
-  private final JBIG2Page page;
+    private final JBIG2Page page;
 
-  public JBIG2ImageMetadata(JBIG2Page page) {
-    super(true, IMAGE_METADATA_FORMAT_NAME, 
JBIG2ImageMetadataFormat.class.getName(), null, null);
+    public JBIG2ImageMetadata(JBIG2Page page)
+    {
+        super(true, IMAGE_METADATA_FORMAT_NAME, 
JBIG2ImageMetadataFormat.class.getName(), null,
+                null);
 
-    if (page == null)
-      throw new IllegalArgumentException("page must not be null");
+        if (page == null)
+            throw new IllegalArgumentException("page must not be null");
 
-    this.page = page;
-  }
+        this.page = page;
+    }
 
-  @Override
-  public boolean isReadOnly() {
-    return true;
-  }
+    @Override
+    public boolean isReadOnly()
+    {
+        return true;
+    }
 
-  @Override
-  public Node getAsTree(String formatName) {
-    if (formatName.equals(nativeMetadataFormatName)) {
-      return getNativeTree();
-    } else if 
(formatName.equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
-      return getStandardTree();
-    } else {
-      throw new IllegalArgumentException("Not a recognized format!");
+    @Override
+    public Node getAsTree(String formatName)
+    {
+        if (formatName.equals(nativeMetadataFormatName))
+        {
+            return getNativeTree();
+        }
+        else if 
(formatName.equals(IIOMetadataFormatImpl.standardMetadataFormatName))
+        {
+            return getStandardTree();
+        }
+        else
+        {
+            throw new IllegalArgumentException("Not a recognized format!");
+        }
     }
-  }
 
-  private Node getNativeTree() {
-    IIOMetadataNode root = new IIOMetadataNode(nativeMetadataFormatName);
-    root.appendChild(getStandardDimensionNode());
-    return root;
-  }
+    private Node getNativeTree()
+    {
+        IIOMetadataNode root = new IIOMetadataNode(nativeMetadataFormatName);
+        root.appendChild(getStandardDimensionNode());
+        return root;
+    }
 
-  @Override
-  public IIOMetadataNode getStandardDimensionNode() {
-    IIOMetadataNode dimensionNode = new IIOMetadataNode("Dimension");
-    IIOMetadataNode node = null; // scratch node
+    @Override
+    public IIOMetadataNode getStandardDimensionNode()
+    {
+        IIOMetadataNode dimensionNode = new IIOMetadataNode("Dimension");
+        IIOMetadataNode node = null; // scratch node
 
-    node = new IIOMetadataNode("PixelAspectRatio");
-    node.setAttribute("value", "1.0");
-    dimensionNode.appendChild(node);
+        node = new IIOMetadataNode("PixelAspectRatio");
+        node.setAttribute("value", "1.0");
+        dimensionNode.appendChild(node);
 
-    node = new IIOMetadataNode("ImageOrientation");
-    node.setAttribute("value", "Normal");
-    dimensionNode.appendChild(node);
+        node = new IIOMetadataNode("ImageOrientation");
+        node.setAttribute("value", "Normal");
+        dimensionNode.appendChild(node);
 
-    if (page.getResolutionX() != 0) {
-      String pixelResolution = Float.toString(25.4f / (page.getResolutionX() / 
39.3701f));
+        if (page.getResolutionX() != 0)
+        {
+            String pixelResolution = Float.toString(25.4f / 
(page.getResolutionX() / 39.3701f));
 
-      node = new IIOMetadataNode("HorizontalPixelSize");
-      node.setAttribute("value", pixelResolution);
-      dimensionNode.appendChild(node);
-    }
+            node = new IIOMetadataNode("HorizontalPixelSize");
+            node.setAttribute("value", pixelResolution);
+            dimensionNode.appendChild(node);
+        }
 
-    if (page.getResolutionY() != 0) {
-      String pixelResolution = Float.toString(25.4f / (page.getResolutionY() / 
39.3701f));
+        if (page.getResolutionY() != 0)
+        {
+            String pixelResolution = Float.toString(25.4f / 
(page.getResolutionY() / 39.3701f));
 
-      node = new IIOMetadataNode("VerticalPixelSize");
-      node.setAttribute("value", pixelResolution);
-      dimensionNode.appendChild(node);
-    }
+            node = new IIOMetadataNode("VerticalPixelSize");
+            node.setAttribute("value", pixelResolution);
+            dimensionNode.appendChild(node);
+        }
 
-    return dimensionNode;
-  }
+        return dimensionNode;
+    }
 
-  @Override
-  public void mergeTree(String formatName, Node root) {
-    throw new IllegalStateException("Metadata is read-only!");
-  }
+    @Override
+    public void mergeTree(String formatName, Node root)
+    {
+        throw new IllegalStateException("Metadata is read-only!");
+    }
 
-  @Override
-  public void reset() {
-    throw new IllegalStateException("Metadata is read-only!");
-  }
+    @Override
+    public void reset()
+    {
+        throw new IllegalStateException("Metadata is read-only!");
+    }
 }

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadataFormat.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadataFormat.java 
b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadataFormat.java
index 1dc1ac7..bb012aa 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadataFormat.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageMetadataFormat.java
@@ -25,29 +25,39 @@ import javax.imageio.metadata.IIOMetadataFormatImpl;
  * @see IIOMetadataFormat
  * @see IIOMetadataFormatImpl
  */
-public class JBIG2ImageMetadataFormat extends IIOMetadataFormatImpl {
-
-  private static IIOMetadataFormat instance = null;
-
-  private JBIG2ImageMetadataFormat() {
-    super(JBIG2ImageMetadata.IMAGE_METADATA_FORMAT_NAME, CHILD_POLICY_SOME);
-
-    // root -> ImageDescriptor
-    addElement("ImageDescriptor", 
JBIG2ImageMetadata.IMAGE_METADATA_FORMAT_NAME, CHILD_POLICY_EMPTY);
-    addAttribute("ImageDescriptor", "imageWidth", DATATYPE_INTEGER, true, 
null, "1", "65535", true, true);
-    addAttribute("ImageDescriptor", "imageHeight", DATATYPE_INTEGER, true, 
null, "1", "65535", true, true);
-    addAttribute("ImageDescriptor", "Xdensity", DATATYPE_FLOAT, true, null, 
"1", "65535", true, true);
-    addAttribute("ImageDescriptor", "Ydensity", DATATYPE_FLOAT, true, null, 
"1", "65535", true, true);
-  }
+public class JBIG2ImageMetadataFormat extends IIOMetadataFormatImpl
+{
+
+    private static IIOMetadataFormat instance = null;
+
+    private JBIG2ImageMetadataFormat()
+    {
+        super(JBIG2ImageMetadata.IMAGE_METADATA_FORMAT_NAME, 
CHILD_POLICY_SOME);
+
+        // root -> ImageDescriptor
+        addElement("ImageDescriptor", 
JBIG2ImageMetadata.IMAGE_METADATA_FORMAT_NAME,
+                CHILD_POLICY_EMPTY);
+        addAttribute("ImageDescriptor", "imageWidth", DATATYPE_INTEGER, true, 
null, "1", "65535",
+                true, true);
+        addAttribute("ImageDescriptor", "imageHeight", DATATYPE_INTEGER, true, 
null, "1", "65535",
+                true, true);
+        addAttribute("ImageDescriptor", "Xdensity", DATATYPE_FLOAT, true, 
null, "1", "65535", true,
+                true);
+        addAttribute("ImageDescriptor", "Ydensity", DATATYPE_FLOAT, true, 
null, "1", "65535", true,
+                true);
+    }
 
-  public boolean canNodeAppear(String elementName, ImageTypeSpecifier 
imageType) {
-    return true;
-  }
+    public boolean canNodeAppear(String elementName, ImageTypeSpecifier 
imageType)
+    {
+        return true;
+    }
 
-  public static synchronized IIOMetadataFormat getInstance() {
-    if (instance == null) {
-      instance = new JBIG2ImageMetadataFormat();
+    public static synchronized IIOMetadataFormat getInstance()
+    {
+        if (instance == null)
+        {
+            instance = new JBIG2ImageMetadataFormat();
+        }
+        return instance;
     }
-    return instance;
-  }
 }

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReader.java 
b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReader.java
index 2f053b3..725919f 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReader.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReader.java
@@ -43,275 +43,321 @@ import org.apache.pdfbox.jbig2.util.log.LoggerFactory;
 /**
  * @see ImageReader
  */
-public class JBIG2ImageReader extends ImageReader {
-  private static final Logger log = 
LoggerFactory.getLogger(JBIG2ImageReader.class);
-
-  public static final boolean DEBUG = false;
-  public static final boolean PERFORMANCE_TEST = false;
-
-  /** JBIG2 document to which we delegate current work. */
-  private JBIG2Document document;
-
-  /** Globals are JBIG2 segments for PDF wide use. */
-  private JBIG2Globals globals;
-
-  /**
-   * @see ImageReader#ImageReader(ImageReaderSpi)
-   * 
-   * @param originatingProvider - The {@code ImageReaderSpi} that is invoking 
this constructor, or
-   *          {@code null}.
-   * @throws IOException if something went wrong while reading the provided 
stream.
-   */
-  public JBIG2ImageReader(ImageReaderSpi originatingProvider) throws 
IOException {
-    super(originatingProvider);
-  }
-
-  /**
-   * @see ImageReader#getDefaultReadParam()
-   */
-  @Override
-  public JBIG2ReadParam getDefaultReadParam() {
-    return new JBIG2ReadParam();
-  }
-
-  /**
-   * Returns a default {@linkplain ImageReadParam} object for a specific page.
-   * 
-   * @param imageIndex - The page number.
-   * @return
-   */
-  private JBIG2ReadParam getDefaultReadParam(final int imageIndex) {
-    int width = 1;
-    int height = 1;
-
-    try {
-      final int index = (imageIndex < getDocument().getAmountOfPages()) ? 
imageIndex : 0;
-      width = getWidth(index);
-      height = getHeight(index);
-    } catch (IOException e) {
-      if (log.isInfoEnabled()) {
-        log.info("Dimensions could not be determined. Returning read params 
with size " + width + "x" + height);
-      }
+public class JBIG2ImageReader extends ImageReader
+{
+    private static final Logger log = 
LoggerFactory.getLogger(JBIG2ImageReader.class);
+
+    public static final boolean DEBUG = false;
+    public static final boolean PERFORMANCE_TEST = false;
+
+    /** JBIG2 document to which we delegate current work. */
+    private JBIG2Document document;
+
+    /** Globals are JBIG2 segments for PDF wide use. */
+    private JBIG2Globals globals;
+
+    /**
+     * @see ImageReader#ImageReader(ImageReaderSpi)
+     * 
+     * @param originatingProvider - The {@code ImageReaderSpi} that is 
invoking this constructor, or {@code null}.
+     * @throws IOException if something went wrong while reading the provided 
stream.
+     */
+    public JBIG2ImageReader(ImageReaderSpi originatingProvider) throws 
IOException
+    {
+        super(originatingProvider);
     }
 
-    return new JBIG2ReadParam(1, 1, 0, 0, new Rectangle(0, 0, width, height), 
new Dimension(width, height));
-  }
-
-  /**
-   * Calculates the width of the specified page.
-   * 
-   * @param imageIndex - The image index. In this case it is the page number.
-   * 
-   * @return The width of the specified page.
-   * 
-   * @throws IOException if an error occurs reading the width information from 
the input source.
-   */
-  @Override
-  public int getWidth(int imageIndex) throws IOException {
-    return getDocument().getPage(imageIndex + 1).getWidth();
-  }
-
-  /**
-   * Calculates the height of the specified page.
-   * 
-   * @param imageIndex - The image index. In this case it is the page number.
-   * 
-   * @return The height of the specified page or {@code 0} if an error 
occurred.
-   * 
-   * @throws IOException if an error occurs reading the height information 
from the input source.
-   */
-  @Override
-  public int getHeight(int imageIndex) throws IOException {
-    try {
-      return getDocument().getPage(imageIndex + 1).getHeight();
-    } catch (JBIG2Exception e) {
-      throw new IOException(e.getMessage());
+    /**
+     * @see ImageReader#getDefaultReadParam()
+     */
+    @Override
+    public JBIG2ReadParam getDefaultReadParam()
+    {
+        return new JBIG2ReadParam();
     }
-  }
-
-  /**
-   * Simply returns the {@link JBIG2ImageMetadata}.
-   * 
-   * @return The associated {@link JBIG2ImageMetadata}.
-   * 
-   * @throws IOException if an error occurs reading the height information 
from the input source.
-   */
-  @Override
-  public IIOMetadata getImageMetadata(int imageIndex) throws IOException {
-    return new JBIG2ImageMetadata(getDocument().getPage(imageIndex + 1));
-  }
-
-
-  /**
-   * Returns the iterator for available image types.
-   * 
-   * @param imageIndex - The page number.
-   * 
-   * @return An {@link Iterator} for available image types.
-   * 
-   * @throws IOException if an error occurs reading the height information 
from the input source.
-   */
-  @Override
-  public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws 
IOException {
-    List<ImageTypeSpecifier> l = new ArrayList<ImageTypeSpecifier>();
-
-    
l.add(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_INDEXED));
-
-    return l.iterator();
-  }
-
-  /**
-   * @see ImageReader#getNumImages(boolean)
-   */
-  @Override
-  public int getNumImages(boolean allowSearch) throws IOException {
-    if (allowSearch) {
-      if (getDocument().isAmountOfPagesUnknown()) {
-        log.info("Amount of pages is unknown.");
-      } else {
-        return getDocument().getAmountOfPages();
-      }
-    } else {
-      log.info("Search is not allowed.");
+
+    /**
+     * Returns a default {@linkplain ImageReadParam} object for a specific 
page.
+     * 
+     * @param imageIndex - The page number.
+     * @return
+     */
+    private JBIG2ReadParam getDefaultReadParam(final int imageIndex)
+    {
+        int width = 1;
+        int height = 1;
+
+        try
+        {
+            final int index = (imageIndex < getDocument().getAmountOfPages()) 
? imageIndex : 0;
+            width = getWidth(index);
+            height = getHeight(index);
+        }
+        catch (IOException e)
+        {
+            if (log.isInfoEnabled())
+            {
+                log.info("Dimensions could not be determined. Returning read 
params with size "
+                        + width + "x" + height);
+            }
+        }
+
+        return new JBIG2ReadParam(1, 1, 0, 0, new Rectangle(0, 0, width, 
height),
+                new Dimension(width, height));
     }
-    return -1;
-  }
-
-  /**
-   * This ImageIO plugin doesn't record {@link IIOMetadata}.
-   * 
-   * @return {@code null} at every call.
-   */
-  @Override
-  public IIOMetadata getStreamMetadata() {
-    log.info("No metadata recorded");
-    return null;
-  }
-
-  /**
-   * Returns decoded segments that has been set as globals. Globals are jbig2 
segments that are used
-   * in embedded case for file wide access. They are not assigned to a 
specific page.
-   * 
-   * @return Decoded global segments.
-   * 
-   * @throws IOException if an error occurs reading the height information 
from the input source.
-   */
-  public JBIG2Globals getGlobals() throws IOException {
-    return getDocument().getGlobalSegments();
-  }
-
-  /**
-   * Returns the decoded image of specified page considering the given {@link 
JBIG2ReadParam}s.
-   * 
-   * @see ImageReader#read(int, ImageReadParam)
-   */
-  @Override
-  public BufferedImage read(int imageIndex, ImageReadParam param) throws 
IOException {
-    if (param == null) {
-      log.info("JBIG2ReadParam not specified. Default will be used.");
-      param = (JBIG2ReadParam) getDefaultReadParam(imageIndex);
+
+    /**
+     * Calculates the width of the specified page.
+     * 
+     * @param imageIndex - The image index. In this case it is the page number.
+     * 
+     * @return The width of the specified page.
+     * 
+     * @throws IOException if an error occurs reading the width information 
from the input source.
+     */
+    @Override
+    public int getWidth(int imageIndex) throws IOException
+    {
+        return getDocument().getPage(imageIndex + 1).getWidth();
     }
 
-    JBIG2Page page = getPage(imageIndex);
+    /**
+     * Calculates the height of the specified page.
+     * 
+     * @param imageIndex - The image index. In this case it is the page number.
+     * 
+     * @return The height of the specified page or {@code 0} if an error 
occurred.
+     * 
+     * @throws IOException if an error occurs reading the height information 
from the input source.
+     */
+    @Override
+    public int getHeight(int imageIndex) throws IOException
+    {
+        try
+        {
+            return getDocument().getPage(imageIndex + 1).getHeight();
+        }
+        catch (JBIG2Exception e)
+        {
+            throw new IOException(e.getMessage());
+        }
+    }
 
-    Bitmap pageBitmap = (Bitmap) CacheFactory.getCache().get(page);
+    /**
+     * Simply returns the {@link JBIG2ImageMetadata}.
+     * 
+     * @return The associated {@link JBIG2ImageMetadata}.
+     * 
+     * @throws IOException if an error occurs reading the height information 
from the input source.
+     */
+    @Override
+    public IIOMetadata getImageMetadata(int imageIndex) throws IOException
+    {
+        return new JBIG2ImageMetadata(getDocument().getPage(imageIndex + 1));
+    }
 
-    if (pageBitmap == null) {
-      try {
-        pageBitmap = page.getBitmap();
-        CacheFactory.getCache().put(page, pageBitmap, 
pageBitmap.getMemorySize());
-        page.clearPageData();
-      } catch (JBIG2Exception e) {
-        throw new IOException(e.getMessage());
-      }
+    /**
+     * Returns the iterator for available image types.
+     * 
+     * @param imageIndex - The page number.
+     * 
+     * @return An {@link Iterator} for available image types.
+     * 
+     * @throws IOException if an error occurs reading the height information 
from the input source.
+     */
+    @Override
+    public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) throws 
IOException
+    {
+        List<ImageTypeSpecifier> l = new ArrayList<ImageTypeSpecifier>();
+
+        
l.add(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_INDEXED));
+
+        return l.iterator();
     }
 
-    return Bitmaps.asBufferedImage(pageBitmap, param, FilterType.Gaussian);
-  }
+    /**
+     * @see ImageReader#getNumImages(boolean)
+     */
+    @Override
+    public int getNumImages(boolean allowSearch) throws IOException
+    {
+        if (allowSearch)
+        {
+            if (getDocument().isAmountOfPagesUnknown())
+            {
+                log.info("Amount of pages is unknown.");
+            }
+            else
+            {
+                return getDocument().getAmountOfPages();
+            }
+        }
+        else
+        {
+            log.info("Search is not allowed.");
+        }
+        return -1;
+    }
 
-  public boolean canReadRaster() {
-    return true;
-  }
+    /**
+     * This ImageIO plugin doesn't record {@link IIOMetadata}.
+     * 
+     * @return {@code null} at every call.
+     */
+    @Override
+    public IIOMetadata getStreamMetadata()
+    {
+        log.info("No metadata recorded");
+        return null;
+    }
 
-  @Override
-  public Raster readRaster(int imageIndex, ImageReadParam param) throws 
IOException {
-    if (param == null) {
-      log.info("JBIG2ReadParam not specified. Default will be used.");
-      param = (JBIG2ReadParam) getDefaultReadParam(imageIndex);
+    /**
+     * Returns decoded segments that has been set as globals. Globals are 
jbig2 segments that are used in embedded case
+     * for file wide access. They are not assigned to a specific page.
+     * 
+     * @return Decoded global segments.
+     * 
+     * @throws IOException if an error occurs reading the height information 
from the input source.
+     */
+    public JBIG2Globals getGlobals() throws IOException
+    {
+        return getDocument().getGlobalSegments();
     }
 
-    JBIG2Page page = getPage(imageIndex);
-
-    Bitmap pageBitmap = (Bitmap) CacheFactory.getCache().get(page);
-    if (pageBitmap == null) {
-      try {
-        pageBitmap = page.getBitmap();
-        CacheFactory.getCache().put(page, pageBitmap, 
pageBitmap.getMemorySize());
-        page.clearPageData();
-      } catch (JBIG2Exception e) {
-        throw new IOException(e.getMessage());
-      }
+    /**
+     * Returns the decoded image of specified page considering the given 
{@link JBIG2ReadParam}s.
+     * 
+     * @see ImageReader#read(int, ImageReadParam)
+     */
+    @Override
+    public BufferedImage read(int imageIndex, ImageReadParam param) throws 
IOException
+    {
+        if (param == null)
+        {
+            log.info("JBIG2ReadParam not specified. Default will be used.");
+            param = (JBIG2ReadParam) getDefaultReadParam(imageIndex);
+        }
+
+        JBIG2Page page = getPage(imageIndex);
+
+        Bitmap pageBitmap = (Bitmap) CacheFactory.getCache().get(page);
+
+        if (pageBitmap == null)
+        {
+            try
+            {
+                pageBitmap = page.getBitmap();
+                CacheFactory.getCache().put(page, pageBitmap, 
pageBitmap.getMemorySize());
+                page.clearPageData();
+            }
+            catch (JBIG2Exception e)
+            {
+                throw new IOException(e.getMessage());
+            }
+        }
+
+        return Bitmaps.asBufferedImage(pageBitmap, param, FilterType.Gaussian);
     }
 
-    return Bitmaps.asRaster(pageBitmap, param, FilterType.Gaussian);
-  }
-
-  /**
-   * Decodes and returns the global segments.
-   * 
-   * @param globalsInputStream - The input stream of globals data.
-   * 
-   * @return The decoded {@link JBIG2Globals}.
-   * 
-   * @throws IOException if an error occurs reading the height information 
from the input source.
-   */
-  public JBIG2Globals processGlobals(ImageInputStream globalsInputStream) 
throws IOException {
-    JBIG2Document doc = new JBIG2Document(globalsInputStream);
-    return doc.getGlobalSegments();
-  }
-
-  /**
-   * Simply sets the globals.
-   * 
-   * @param globals - The globals to set.
-   * @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;
-  }
-
-  /**
-   * @see ImageReader#setInput(Object, boolean, boolean)
-   */
-  @Override
-  public void setInput(Object input, boolean seekForwardOnly, boolean 
ignoreMetadata) {
-    super.setInput(input, seekForwardOnly, ignoreMetadata);
-    document = null;
-  }
-
-  private JBIG2Document getDocument() throws IOException {
-    if (this.document == null) {
-      if (this.input == null) {
-        throw new IOException("Input not set.");
-      }
-
-      if (this.globals == null) {
-        log.debug("Globals not set.");
-      }
-
-      this.document = new JBIG2Document((ImageInputStream) this.input, 
this.globals);
+    public boolean canReadRaster()
+    {
+        return true;
     }
-    return this.document;
-  }
 
-  private JBIG2Page getPage(int imageIndex) throws IOException {
-    JBIG2Page page = getDocument().getPage(imageIndex + 1);
+    @Override
+    public Raster readRaster(int imageIndex, ImageReadParam param) throws 
IOException
+    {
+        if (param == null)
+        {
+            log.info("JBIG2ReadParam not specified. Default will be used.");
+            param = (JBIG2ReadParam) getDefaultReadParam(imageIndex);
+        }
+
+        JBIG2Page page = getPage(imageIndex);
+
+        Bitmap pageBitmap = (Bitmap) CacheFactory.getCache().get(page);
+        if (pageBitmap == null)
+        {
+            try
+            {
+                pageBitmap = page.getBitmap();
+                CacheFactory.getCache().put(page, pageBitmap, 
pageBitmap.getMemorySize());
+                page.clearPageData();
+            }
+            catch (JBIG2Exception e)
+            {
+                throw new IOException(e.getMessage());
+            }
+        }
+
+        return Bitmaps.asRaster(pageBitmap, param, FilterType.Gaussian);
+    }
 
-    if (page == null)
-      throw new IndexOutOfBoundsException("Requested page at index=" + 
imageIndex + " does not exist.");
+    /**
+     * Decodes and returns the global segments.
+     * 
+     * @param globalsInputStream - The input stream of globals data.
+     * 
+     * @return The decoded {@link JBIG2Globals}.
+     * 
+     * @throws IOException if an error occurs reading the height information 
from the input source.
+     */
+    public JBIG2Globals processGlobals(ImageInputStream globalsInputStream) 
throws IOException
+    {
+        JBIG2Document doc = new JBIG2Document(globalsInputStream);
+        return doc.getGlobalSegments();
+    }
 
-    return page;
-  }
+    /**
+     * Simply sets the globals.
+     * 
+     * @param globals - The globals to set.
+     * @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;
+    }
+
+    /**
+     * @see ImageReader#setInput(Object, boolean, boolean)
+     */
+    @Override
+    public void setInput(Object input, boolean seekForwardOnly, boolean 
ignoreMetadata)
+    {
+        super.setInput(input, seekForwardOnly, ignoreMetadata);
+        document = null;
+    }
+
+    private JBIG2Document getDocument() throws IOException
+    {
+        if (this.document == null)
+        {
+            if (this.input == null)
+            {
+                throw new IOException("Input not set.");
+            }
+
+            if (this.globals == null)
+            {
+                log.debug("Globals not set.");
+            }
+
+            this.document = new JBIG2Document((ImageInputStream) this.input, 
this.globals);
+        }
+        return this.document;
+    }
+
+    private JBIG2Page getPage(int imageIndex) throws IOException
+    {
+        JBIG2Page page = getDocument().getPage(imageIndex + 1);
+
+        if (page == null)
+            throw new IndexOutOfBoundsException(
+                    "Requested page at index=" + imageIndex + " does not 
exist.");
+
+        return page;
+    }
 }

http://git-wip-us.apache.org/repos/asf/pdfbox-jbig2/blob/30839c32/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderSpi.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderSpi.java 
b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderSpi.java
index 297cea4..c0cd647 100644
--- a/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderSpi.java
+++ b/src/main/java/org/apache/pdfbox/jbig2/JBIG2ImageReaderSpi.java
@@ -29,96 +29,98 @@ import javax.imageio.stream.ImageInputStream;
  * 
  * @see ImageReaderSpi
  */
-public class JBIG2ImageReaderSpi extends ImageReaderSpi {
-
-  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 = {
-      "jbig2", "JBIG2"
-  };
-  private static final String[] SUFFIXES = {
-      "jb2", "jbig2", "JB2", "JBIG2"
-  };
-  private static final String[] MIME_TYPES = {
-      "image/x-jbig2", "image/x-jb2"
-  };
-  private static final Class<?>[] INPUT_TYPES = { ImageInputStream.class };
-
-  /**
-   * According to D.4.1:
-   * <p>
-   * This preamble contains the unique id string for jbig2 files and can be 
used to check if this
-   * reader plugin can decode the given stream. This can only work with native 
jbig2 data. If the
-   * stream is embedded in another file format this preamble might be missing.
-   */
-  private static final int[] FILEHEADER_PREAMBLE = {
-      0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A
-  };
-
-  /* MK: I suppose, there won't be a writer in near future :-) */
-  private static final String[] WRITER_SPI_NAMES = {};
-
-  static final boolean SUPPORTS_STANDARD_STREAM_METADATE_FORMAT = false;
-  static final String NATIVE_STREAM_METADATA_FORMAT_NAME = "JBIG2 Stream 
Metadata";
-  static final String NATIVE_STREAM_METADATA_FORMAT_CLASSNAME = 
"JBIG2Metadata";
-  static final String[] EXTRA_STREAM_METADATA_FORMAT_NAME = null;
-  static final String[] EXTRA_STREAM_METADATA_FORMAT_CLASSNAME = null;
-
-  static final boolean SUPPORTS_STANDARD_IMAGE_METADATA_FORMAT = false;
-  static final String NATIVE_IMAGE_METADATA_FORMAT_NAME = "JBIG2 File 
Metadata";
-  static final String NATIVE_IMAGE_METADATA_FORMAT_CLASSNAME = "JBIG2Metadata";
-  static final String[] EXTRA_IMAGE_METADATA_FORMAT_NAME = null;
-  static final String[] EXTRA_IMAGE_METADATA_FORMAT_CLASSNAME = null;
-
-  public JBIG2ImageReaderSpi() {
-    super(VENDOR, VERSION, NAMES, SUFFIXES, MIME_TYPES, READER_CLASS_NAME, 
INPUT_TYPES, WRITER_SPI_NAMES,
-        SUPPORTS_STANDARD_STREAM_METADATE_FORMAT, 
NATIVE_STREAM_METADATA_FORMAT_NAME,
-        NATIVE_STREAM_METADATA_FORMAT_CLASSNAME, 
EXTRA_STREAM_METADATA_FORMAT_NAME,
-        EXTRA_STREAM_METADATA_FORMAT_CLASSNAME, 
SUPPORTS_STANDARD_IMAGE_METADATA_FORMAT,
-        NATIVE_IMAGE_METADATA_FORMAT_NAME, 
NATIVE_IMAGE_METADATA_FORMAT_CLASSNAME, EXTRA_IMAGE_METADATA_FORMAT_NAME,
-        EXTRA_IMAGE_METADATA_FORMAT_CLASSNAME);
-  }
-
-  /*
-   * Checks, if the file header begins with the preamble id string defined in 
D.4.1, page 100
-   * 
-   * (non-Javadoc)
-   * 
-   * @see javax.imageio.spi.ImageReaderSpi#canDecodeInput(java.lang.Object)
-   */
-  @Override
-  public boolean canDecodeInput(Object source) throws IOException {
-    if (source == null)
-      throw new IllegalArgumentException("source must not be null");
-
-    if (!(source instanceof ImageInputStream)) {
-      System.out.println("source is not an ImageInputStream");
-      return false;
+public class JBIG2ImageReaderSpi extends ImageReaderSpi
+{
+
+    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 = { "jbig2", "JBIG2" };
+    private static final String[] SUFFIXES = { "jb2", "jbig2", "JB2", "JBIG2" 
};
+    private static final String[] MIME_TYPES = { "image/x-jbig2", 
"image/x-jb2" };
+    private static final Class<?>[] INPUT_TYPES = { ImageInputStream.class };
+
+    /**
+     * According to D.4.1:
+     * <p>
+     * This preamble contains the unique id string for jbig2 files and can be 
used to check if this reader plugin can
+     * decode the given stream. This can only work with native jbig2 data. If 
the stream is embedded in another file
+     * format this preamble might be missing.
+     */
+    private static final int[] FILEHEADER_PREAMBLE = { 0x97, 0x4A, 0x42, 0x32, 
0x0D, 0x0A, 0x1A,
+            0x0A };
+
+    /* MK: I suppose, there won't be a writer in near future :-) */
+    private static final String[] WRITER_SPI_NAMES = {};
+
+    static final boolean SUPPORTS_STANDARD_STREAM_METADATE_FORMAT = false;
+    static final String NATIVE_STREAM_METADATA_FORMAT_NAME = "JBIG2 Stream 
Metadata";
+    static final String NATIVE_STREAM_METADATA_FORMAT_CLASSNAME = 
"JBIG2Metadata";
+    static final String[] EXTRA_STREAM_METADATA_FORMAT_NAME = null;
+    static final String[] EXTRA_STREAM_METADATA_FORMAT_CLASSNAME = null;
+
+    static final boolean SUPPORTS_STANDARD_IMAGE_METADATA_FORMAT = false;
+    static final String NATIVE_IMAGE_METADATA_FORMAT_NAME = "JBIG2 File 
Metadata";
+    static final String NATIVE_IMAGE_METADATA_FORMAT_CLASSNAME = 
"JBIG2Metadata";
+    static final String[] EXTRA_IMAGE_METADATA_FORMAT_NAME = null;
+    static final String[] EXTRA_IMAGE_METADATA_FORMAT_CLASSNAME = null;
+
+    public JBIG2ImageReaderSpi()
+    {
+        super(VENDOR, VERSION, NAMES, SUFFIXES, MIME_TYPES, READER_CLASS_NAME, 
INPUT_TYPES,
+                WRITER_SPI_NAMES, SUPPORTS_STANDARD_STREAM_METADATE_FORMAT,
+                NATIVE_STREAM_METADATA_FORMAT_NAME, 
NATIVE_STREAM_METADATA_FORMAT_CLASSNAME,
+                EXTRA_STREAM_METADATA_FORMAT_NAME, 
EXTRA_STREAM_METADATA_FORMAT_CLASSNAME,
+                SUPPORTS_STANDARD_IMAGE_METADATA_FORMAT, 
NATIVE_IMAGE_METADATA_FORMAT_NAME,
+                NATIVE_IMAGE_METADATA_FORMAT_CLASSNAME, 
EXTRA_IMAGE_METADATA_FORMAT_NAME,
+                EXTRA_IMAGE_METADATA_FORMAT_CLASSNAME);
     }
 
-    ImageInputStream iis = (ImageInputStream) source;
-    iis.mark();
-
-    for (int i = 0; i < FILEHEADER_PREAMBLE.length; i++) {
-      int read = (iis.read() & 0xFF);
-      if (read != FILEHEADER_PREAMBLE[i]) {
-        return false;
-      }
+    /*
+     * Checks, if the file header begins with the preamble id string defined 
in D.4.1, page 100
+     * 
+     * (non-Javadoc)
+     * 
+     * @see javax.imageio.spi.ImageReaderSpi#canDecodeInput(java.lang.Object)
+     */
+    @Override
+    public boolean canDecodeInput(Object source) throws IOException
+    {
+        if (source == null)
+            throw new IllegalArgumentException("source must not be null");
+
+        if (!(source instanceof ImageInputStream))
+        {
+            System.out.println("source is not an ImageInputStream");
+            return false;
+        }
+
+        ImageInputStream iis = (ImageInputStream) source;
+        iis.mark();
+
+        for (int i = 0; i < FILEHEADER_PREAMBLE.length; i++)
+        {
+            int read = (iis.read() & 0xFF);
+            if (read != FILEHEADER_PREAMBLE[i])
+            {
+                return false;
+            }
+        }
+
+        iis.reset();
+        return true;
     }
 
-    iis.reset();
-    return true;
-  }
-
-  @Override
-  public ImageReader createReaderInstance(Object extension) throws IOException 
{
-    return new JBIG2ImageReader(this);
-  }
+    @Override
+    public ImageReader createReaderInstance(Object extension) throws 
IOException
+    {
+        return new JBIG2ImageReader(this);
+    }
 
-  @Override
-  public String getDescription(Locale locale) {
-    return "JBIG2 Image Reader";
-  }
+    @Override
+    public String getDescription(Locale locale)
+    {
+        return "JBIG2 Image Reader";
+    }
 
 }

Reply via email to