Examples of ImageInputStream


Examples of javax.imageio.stream.ImageInputStream

    public ImageInfo preloadImage(String uri, Source src, ImageContext context)
            throws IOException, ImageException {
        if (!ImageUtil.hasImageInputStream(src)) {
            return null;
        }
        ImageInputStream in = ImageUtil.needImageInputStream(src);
        byte[] header = getHeader(in, TIFF_SIG_LENGTH);
        boolean supported = false;

        // first 2 bytes = II (little endian encoding)
        if (header[0] == (byte) 0x49 && header[1] == (byte) 0x49) {
View Full Code Here

Examples of javax.imageio.stream.ImageInputStream

        long stripOffset;
        long stripLength;
        TIFFDirectory dir;

        Source src = session.needSource(info.getOriginalURI());
        ImageInputStream in = ImageUtil.needImageInputStream(src);
        in.mark();
        try {
            SeekableStream seekable = new SeekableStreamAdapter(in);
            dir = new TIFFDirectory(seekable, 0);
            TIFFField fld;

            fld = dir.getField(TIFFImageDecoder.TIFF_COMPRESSION);
            if (fld != null) {
                compression = fld.getAsInt(0);
                switch (compression) {
                case COMPRESSION_CCITT_1D:
                case COMPRESSION_FAX_GROUP4:
                    break;
                case COMPRESSION_FAX_GROUP3:
                    //Note: the TIFFImage compression constants seem to be a bit misleading!
                    compression = TIFFImage.COMP_FAX_G3_1D; //1D is the default for Group3
                    fld = dir.getField(TIFFImageDecoder.TIFF_T4_OPTIONS);
                    if (fld != null) {
                        long t4Options = fld.getAsLong(0);
                        if ((t4Options & 0x01) != 0) {
                            compression = TIFFImage.COMP_FAX_G3_2D; //"Abusing" for 2D signalling
                        }
                    }
                    break;
                default:
                    log.debug("Unsupported compression " + compression);
                    throw new ImageException(
                            "ImageLoader doesn't support TIFF compression: " + compression);
                }
            }
            //Read information used for raw embedding
            fld = dir.getField(TIFFImageDecoder.TIFF_FILL_ORDER);
            if (fld != null) {
                fillOrder = fld.getAsInt(0);
            }

            int stripCount;
            fld = dir.getField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP);
            if (fld == null) {
                stripCount = 1;
            } else {
                stripCount = (int)(info.getSize().getHeightPx() / fld.getAsLong(0));
            }
            if (stripCount > 1) {
                log.debug("More than one strip found in TIFF image.");
                throw new ImageException(
                        "ImageLoader doesn't support multiple strips");
            }
            stripOffset = dir.getField(TIFFImageDecoder.TIFF_STRIP_OFFSETS).getAsLong(0);
            stripLength = dir.getField(TIFFImageDecoder.TIFF_STRIP_BYTE_COUNTS).getAsLong(0);
        } finally {
            in.reset();
        }

        in.seek(stripOffset);
        InputStream subin = new SubInputStream(ImageUtil.needInputStream(src), stripLength, true);
        if (fillOrder == 2) {
            //Decorate to flip bit order
            subin = new FillOrderChangeInputStream(subin);
        }
View Full Code Here

Examples of javax.imageio.stream.ImageInputStream

      logger.debug(importFileName + " ext = " + getFileExtensionForImageReader(importFileName));
      Iterator readers = ImageIO.getImageReadersBySuffix(getFileExtensionForImageReader(importFileName));
      ImageReader reader = (ImageReader) readers.next();
  
       try {
          ImageInputStream iis = ImageIO.createImageInputStream(importFile.getInputStream());
          reader.setInput(iis, true);
          int width = reader.getWidth(0);
          int height = reader.getHeight(0);
          logger.debug(importFile.getFileName() + ": width=" + width + ", height=" + height);
          if (width > maxWidth || height >  maxHeight){
View Full Code Here

Examples of javax.imageio.stream.ImageInputStream

              logger.debug(fileName + " ext = " + getFileExtensionForImageReader(fileName));
              Iterator readers = ImageIO.getImageReadersBySuffix(getFileExtensionForImageReader(fileName));
              ImageReader reader = (ImageReader) readers.next();
          
               try {
                  ImageInputStream iis = ImageIO.createImageInputStream(uploadedFile.getInputStream());
                  reader.setInput(iis, true);
                  int width = reader.getWidth(0);
                  int height = reader.getHeight(0);
                  logger.debug(uploadedFile.getFileName() + ": width=" + width + ", height=" + height);
                 
View Full Code Here

Examples of javax.imageio.stream.ImageInputStream

    @Override
    public final DecodeResult decode(InputStream encoded, OutputStream decoded,
                                         COSDictionary parameters, int index) throws IOException
    {
        ImageReader reader = findImageReader("JPEG", "a suitable JAI I/O image filter is not installed");
        ImageInputStream iis = null;
        try
        {
            iis = ImageIO.createImageInputStream(encoded);
            reader.setInput(iis);

            // get the raster using horrible JAI workarounds
            ImageIO.setUseCache(false);
            Raster raster;
            try
            {
                // I'd like to use ImageReader#readRaster but it is buggy and can't read RGB correctly
                BufferedImage image = reader.read(0);
                raster = image.getRaster();
            }
            catch (IIOException e)
            {
                // JAI can't read CMYK JPEGs using ImageReader#read or ImageIO.read but
                // fortunately ImageReader#readRaster isn't buggy when reading 4-channel files
                raster = reader.readRaster(0, null);
            }

            // special handling for 4-component images
            if (raster.getNumBands() == 4)
            {
                // get APP14 marker
                Integer transform;
                try
                {
                    transform = getAdobeTransform(reader.getImageMetadata(0));
                }
                catch (IIOException e)
                {
                    // catches the error "Inconsistent metadata read from stream"
                    // which seems to be present indicate a YCCK image, but who knows?
                    LOG.warn("Inconsistent metadata read from JPEG stream");
                    transform = 2; // YCCK
                }
                int colorTransform = transform != null ? transform : 0;

                // 0 = Unknown (RGB or CMYK), 1 = YCbCr, 2 = YCCK
                switch (colorTransform)
                {
                    case 0: break; // already CMYK
                    case 1: LOG.warn("YCbCr JPEGs not implemented"); break; // TODO YCbCr
                    case 2: raster = fromYCCKtoCMYK(raster); break;
                }
            }
            else if (raster.getNumBands() == 3)
            {
                // BGR to RGB
                raster = fromBGRtoRGB(raster);
            }

            DataBufferByte dataBuffer = (DataBufferByte)raster.getDataBuffer();
            decoded.write(dataBuffer.getData());
        }
        finally
        {
            if (iis != null)
            {
                iis.close();
            }
            reader.dispose();
        }
        return new DecodeResult(parameters);
    }
View Full Code Here

Examples of javax.imageio.stream.ImageInputStream

        if (params != null)
        {
            globals = (COSStream) params.getDictionaryObject(COSName.JBIG2_GLOBALS);
        }

        ImageInputStream iis = null;
        try
        {
            if (globals != null)
            {
                iis = ImageIO.createImageInputStream(
                        new SequenceInputStream(globals.getUnfilteredStream(), encoded));
                reader.setInput(iis);
            }
            else
            {
                iis = ImageIO.createImageInputStream(encoded);
                reader.setInput(iis);
            }

            BufferedImage image;
            try
            {
                image = reader.read(0);
            }
            catch (Exception e)
            {
                // wrap and rethrow any exceptions
                throw new IOException("Could not read JBIG2 image", e);
            }

            // I am assuming since JBIG2 is always black and white
            // depending on your renderer this might or might be needed
            if (image.getColorModel().getPixelSize() != bits.intValue())
            {
                if (bits.intValue() != 1)
                {
                    LOG.warn("Attempting to handle a JBIG2 with more than 1-bit depth");
                }
                BufferedImage packedImage = new BufferedImage(image.getWidth(), image.getHeight(),
                        BufferedImage.TYPE_BYTE_BINARY);
                Graphics graphics = packedImage.getGraphics();
                graphics.drawImage(image, 0, 0, null);
                graphics.dispose();
                image = packedImage;
            }

            DataBuffer dBuf = image.getData().getDataBuffer();
            if (dBuf.getDataType() == DataBuffer.TYPE_BYTE)
            {
                decoded.write(((DataBufferByte) dBuf).getData());
            }
            else
            {
                throw new IOException("Unexpected image buffer type");
            }
        }
        finally
        {
            if (iis != null)
            {
                iis.close();
            }
            reader.dispose();
        }

        // repair missing color space
View Full Code Here

Examples of javax.imageio.stream.ImageInputStream

    // try to read using JAI Image I/O
    private BufferedImage readJPX(InputStream input, DecodeResult result) throws IOException
    {
        ImageReader reader = findImageReader("JPEG2000", "Java Advanced Imaging (JAI) Image I/O Tools are not installed");
        ImageInputStream iis = null;
        try
        {
            iis = ImageIO.createImageInputStream(input);
            reader.setInput(iis, true, true);

            BufferedImage image;
            try
            {
                image = reader.read(0);
            }
            catch (Exception e)
            {
                // wrap and rethrow any exceptions
                throw new IOException("Could not read JPEG 2000 (JPX) image", e);
            }

            COSDictionary parameters = result.getParameters();

            // "If the image stream uses the JPXDecode filter, this entry is optional
            // and shall be ignored if present"
            parameters.setInt(COSName.BITS_PER_COMPONENT, image.getColorModel().getComponentSize(0));

            // "Decode shall be ignored, except in the case where the image is treated as a mask"
            if (!parameters.getBoolean(COSName.IMAGE_MASK, false))
            {
                parameters.setItem(COSName.DECODE, null);
            }

            // override dimensions, see PDFBOX-1735
            parameters.setInt(COSName.WIDTH, image.getWidth());
            parameters.setInt(COSName.HEIGHT, image.getHeight());

            // extract embedded color space
            if (!parameters.containsKey(COSName.COLORSPACE))
            {
                result.setColorSpace(new PDJPXColorSpace(image.getColorModel().getColorSpace()));
            }

            return image;
        }
        finally
        {
            if (iis != null)
            {
                iis.close();
            }
            reader.dispose();
        }
    }
View Full Code Here

Examples of javax.imageio.stream.ImageInputStream

    public boolean canDecodeInput(Object input) throws IOException {
        if (!(input instanceof ImageInputStream))
            return false;

        ImageInputStream in = (ImageInputStream) input;
        boolean retval;

        in.mark();
        try {
            //todo implement a less expensive canDecode()
            new JPEGDecoderAdapter(in).decode();
            retval = true;
        } catch (JPEGException e) {
            retval = false;
        }
        in.reset();

        return retval;
    }
View Full Code Here

Examples of javax.imageio.stream.ImageInputStream

            (byte) 0x3b,
            (byte) 0x67
          };

        ByteArrayInputStream bs = new ByteArrayInputStream(b);
        ImageInputStream i = new MemoryCacheImageInputStream(bs);

        // Test ByteOrder.BIG_ENDIAN, the default.

        h.check(i.getByteOrder() == ByteOrder.BIG_ENDIAN);

        h.check(i.read() == 114);
        i.seek(0);
        h.check(i.readBoolean() == true);
        i.seek(0);
        h.check(i.readByte() == 114);
        i.seek(0);
        h.check(i.readChar() == '\u7270');
        i.seek(0);
        h.check(Double.compare(i.readDouble(), 1.709290273164385E243) == 0);
        i.seek(0);
        h.check(Float.compare(i.readFloat(), 4.7541126E30f) == 0);
        i.seek(0);
        h.check(i.readInt() == 1919944055);
        i.seek(0);
        h.check(i.readLong() == 8246096929276181351L);
        i.seek(0);
        h.check(i.readShort() == 29296);
        i.seek(0);
        h.check(i.readUnsignedByte() == 114);
        i.seek(0);
        h.check(i.readUnsignedInt() == 1919944055);
        i.seek(0);
        h.check(i.readUnsignedShort() == 29296);

        // Test ByteOrder.LITTLE_ENDIAN.
        i.setByteOrder(ByteOrder.LITTLE_ENDIAN);

        h.check(i.getByteOrder() == ByteOrder.LITTLE_ENDIAN);
        i.seek(0);
        h.check(i.read() == 114);
        i.seek(0);
        h.check(i.readBoolean() == true);
        i.seek(0);
        h.check(i.readByte() == 114);
        i.seek(0);
        h.check(i.readChar() == '\u7072');
        i.seek(0);
        h.check(Double.compare(i.readDouble(), 1.9456609400629563E189) == 0);
        i.seek(0);
        h.check(Float.compare(i.readFloat(), 2.7064693E33f) == 0);
        i.seek(0);
        h.check(i.readInt() == 1996845170);
        i.seek(0);
        h.check(i.readLong() == 7438806032077647986L);
        i.seek(0);
        h.check(i.readShort() == 28786);
        i.seek(0);
        h.check(i.readUnsignedByte() == 114);
        i.seek(0);
        h.check(i.readUnsignedInt() == 1996845170);
        i.seek(0);
        h.check(i.readUnsignedShort() == 28786);

        // Test unsigned values.
        b = new byte[]
          {
            (byte) 0x92,
            (byte) 0x80,
            (byte) 0x05,
            (byte) 0x77,
            (byte) 0xac,
            (byte) 0xf2,
            (byte) 0x8b,
            (byte) 0xa7
          };

        bs = new ByteArrayInputStream(b);
        i = new MemoryCacheImageInputStream(bs);

        // Test ByteOrder.BIG_ENDIAN, the default.
        h.check(i.read() == 146);
        i.seek(0);
        h.check(i.readBoolean() == true);
        i.seek(0);
        h.check(i.readByte() == -110);
        i.seek(0);
        h.check(i.readChar() == '\u9280');
        i.seek(0);
        h.check(Double.compare(i.readDouble(), -1.4183142849706364E-219) == 0);
        i.seek(0);
        h.check(Float.compare(i.readFloat(), -8.079283E-28f) == 0);
        i.seek(0);
        h.check(i.readInt() == -1837103753);
        i.seek(0);
        h.check(i.readLong() == -7890300535592285273L);
        i.seek(0);
        h.check(i.readShort() == -28032);
        i.seek(0);
        h.check(i.readUnsignedByte() == 146);
        i.seek(0);
        h.check(i.readUnsignedInt() == 2457863543L);
        i.seek(0);
        h.check(i.readUnsignedShort() == 37504);

        // Test ByteOrder.LITTLE_ENDIAN.
        i.setByteOrder(ByteOrder.LITTLE_ENDIAN);
        i.seek(0);
        h.check(i.read() == 146);
        i.seek(0);
        h.check(i.readBoolean() == true);
        i.seek(0);
        h.check(i.readByte() == -110);
        i.seek(0);
        h.check(i.readChar() == '\u8092');
        i.seek(0);
        h.check(Double.compare(i.readDouble(), -3.463391436203922E-118) == 0);
        i.seek(0);
        h.check(Float.compare(i.readFloat(), 2.707747E33f) == 0);
        i.seek(0);
        h.check(i.readInt() == 1996849298);
        i.seek(0);
        h.check(i.readLong() == -6373734025067659118L);
        i.seek(0);
        h.check(i.readShort() == -32622);
        i.seek(0);
        h.check(i.readUnsignedByte() == 146);
        i.seek(0);
        h.check(i.readUnsignedInt() == 1996849298);
        i.seek(0);
        h.check(i.readUnsignedShort() == 32914);

        // Test flush().

        i.seek(4);

        h.check(i.getStreamPosition() == 4);

        i.flush();

        h.check(i.getFlushedPosition() == 4);
       
        boolean exceptionThrown = false;
        try
          {
            i.flushBefore(3);
          }
        catch (IndexOutOfBoundsException e)
          {
            exceptionThrown = true;
          }
        h.check(exceptionThrown);

        exceptionThrown = false;
        try
          {
            i.flushBefore(5);
          }
        catch (IndexOutOfBoundsException e)
          {
            exceptionThrown = true;
          }
        h.check(exceptionThrown);

        exceptionThrown = false;
        try
          {
            i.seek(2);
          }
        catch (IndexOutOfBoundsException e)
          {
            exceptionThrown = true;
          }
        h.check(exceptionThrown);

        exceptionThrown = false;
        try
          {
            i.seek(3);
          }
        catch (IndexOutOfBoundsException e)
          {
            exceptionThrown = true;
          }
        h.check(exceptionThrown);

        exceptionThrown = false;
        try
          {
            i.setBitOffset(-1);
          }
        catch (IllegalArgumentException e)
          {
            exceptionThrown = true;
          }
        h.check(exceptionThrown);

        exceptionThrown = false;
        try
          {
            i.setBitOffset(8);
          }
        catch (IllegalArgumentException e)
          {
            exceptionThrown = true;
          }
        h.check(exceptionThrown);

        i.setBitOffset(4);
        h.check(i.getBitOffset() == 4);

        // A MemoryCacheImageInputStream is cached in memory.
        h.check(i.isCached() == true);
        h.check(i.isCachedFile() == false);
        h.check(i.isCachedMemory() == true);

        h.check(i.length() == -1);

        // Test mark() and reset().
        i.seek(4);
        i.mark();

        i.read();
        i.read();

        i.reset();
        h.check(i.getStreamPosition() == 4);

        // Test readBit().
        // We're currently at b[4], byte 0xac.
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 0);
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 0);
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 0);

        // Check that the bit offset is incremented.
        h.check(i.getBitOffset() == 7);

        // Roll back the bit offset within the same byte.
        i.setBitOffset(2);

        // R-read some bits within the same byte.
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 0);
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 0);

        // Check that the stream position is still 4.
        h.check(i.getStreamPosition() == 4);

        // Read the final bit in b[4].
        h.check(i.readBit() == 0);

        // Check that readBit on the 8th bit increments the stream
        // position.
        h.check(i.getStreamPosition() == 5);

        // Read the bits from b[5], byte 0xf2.
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 1);

        h.check(i.getBitOffset() == 4);

        h.check(i.readBit() == 0);
        h.check(i.readBit() == 0);
        h.check(i.readBit() == 1);
        h.check(i.readBit() == 0);

        // Check that the bit offset is reset and the position
        // incremented.
        h.check(i.getBitOffset() == 0);
        h.check(i.getStreamPosition() == 6);

        h.check(i.length() == -1);

        // Test close().
        i.close();

        // Test checkClosed().
        exceptionThrown = false;
        try
          {
            i.close();
          }
        catch (IOException e)
          {
            exceptionThrown = true;
          }
        h.check(exceptionThrown);

        // 64 bytes of data.
        b = new byte[]
          {
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
            (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
            (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
            (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
            (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
            (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
            (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
            (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
            (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
            (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
            (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
            (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
            (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
          };

        bs = new ByteArrayInputStream(b);
        i = new MemoryCacheImageInputStream(bs);

        // Test readBits().
        i.seek(5);
        i.setBitOffset(6);

        exceptionThrown = false;
        try
          {
            i.readBits(-1);
          }
        catch (IllegalArgumentException e)
          {
            exceptionThrown = true;
          }
        h.check(exceptionThrown);

        exceptionThrown = false;
        try
          {
            i.readBits(65);
          }
        catch (IllegalArgumentException e)
          {
            exceptionThrown = true;
          }
        h.check(exceptionThrown);

        h.check(i.readBits(59) == 366848453836545810L);

        i.seek(5);
        i.setBitOffset(6);
        h.check(i.readBits(58) == 183424226918272905L);

        b = new byte[]
          {
            (byte) 0xa2, (byte) 0xe9, (byte) 0xd7, (byte) 0x34,
            (byte) 0x2a, (byte) 0x83, (byte) 0xe2, (byte) 0x40
          };
        bs = new ByteArrayInputStream(b);
        i = new MemoryCacheImageInputStream(bs);
        h.check(i.readBits(59) == 366848453836545810L);

        b = new byte[]
          {
            (byte) 0xa2, (byte) 0x02
          };
        bs = new ByteArrayInputStream(b);
        i = new MemoryCacheImageInputStream(bs);

        long[] res = new long[8];

        i.seek(0);

        h.check(i.readBits(0) == 0);
        i.seek(0);

        for (k = 0; k < 8; k++)
          {
            i.setBitOffset(k);
            res[k] = i.readBits(8);
            i.seek(0);
          }
        i.seek(0);
        h.check(Arrays.equals(res, new long[] { 162, 68, 136, 16,
                                                32, 64, 128, 1 }));

        // 64 bytes of data.
        b = new byte[]
          {
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
            (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
            (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
            // Here is a two-character-long UTF String to be read by
            // DataInputStream.
            (byte) 0x00, (byte) 0x02, (byte) 0x12, (byte) 0x21,
            (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
            (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
            (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
            (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
            (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
            (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
            (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
            (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
            (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
          };

        bs = new ByteArrayInputStream(b);
        i = new MemoryCacheImageInputStream(bs);

        // Test mark() and reset().
        i.seek(17);
        h.check(i.getStreamPosition() == 17);
        i.mark();
        i.seek(49);
        h.check(i.getStreamPosition() == 49);
        i.reset();
        h.check(i.getStreamPosition() == 17);

        // Test skipBytes().
        i.setBitOffset(3);
        i.skipBytes(20);
        h.check(i.getStreamPosition() == 37);
        h.check(i.getBitOffset() == 0);

        // Test readUTF().
        i.seek(12);
        String str = i.readUTF();
        h.check(str.codePointAt(0) == 18);
        h.check(str.codePointAt(1) == 33);

        b = new byte[]
          { (byte) 0x47, (byte) 0x4e, (byte) 0x55,
            '\r',
            (byte) 0x43, (byte) 0x6c, (byte) 0x61, (byte) 0x73, (byte) 0x73,
            (byte) 0x70, (byte) 0x61, (byte) 0x74, (byte) 0x68,
            '\r', '\n',
            (byte) 0x52, (byte) 0x75, (byte) 0x6c,
            (byte) 0x65, (byte) 0x7a,
            '\n',
            (byte) 0x44, (byte) 0x75, (byte) 0x64, (byte) 0x65, (byte) 0x7a,
            (byte) 0x21,
            '\r'
          };

        bs = new ByteArrayInputStream(b);
        i = new MemoryCacheImageInputStream(bs);

        h.check(i.readLine().equals("GNU"));
        h.check(i.readLine().equals("Classpath"));
        h.check(i.readLine().equals("Rulez"));
        h.check(i.readLine().equals("Dudez!"));
        h.check(i.readLine() == null);

        // 64 bytes of data.
        b = new byte[]
          {
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
            (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
            (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
            (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
            (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
            (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
            (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
            (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
            (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
            (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
            (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
            (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
            (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
            (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
          };

        bs = new ByteArrayInputStream(b);
        i = new MemoryCacheImageInputStream(bs);

        byte[] fullB = new byte[26];
        i.seek(0);
        i.readFully(fullB);
        h.check(Arrays.equals(fullB,
                              new byte[]
            {
              (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
              (byte) 0xac, (byte) 0xf2, (byte) 0x8b, (byte) 0xa7,
              (byte) 0x5c, (byte) 0xd0, (byte) 0xaa, (byte) 0x0f,
              (byte) 0x89, (byte) 0x00, (byte) 0x12, (byte) 0xf1,
              (byte) 0xa1, (byte) 0xef, (byte) 0x82, (byte) 0x00,
              (byte) 0x92, (byte) 0x80, (byte) 0x05, (byte) 0x77,
              (byte) 0xac, (byte) 0xf2
            }));

        for (k = 0; k < fullB.length; k++)
          fullB[k] = 0;

        i.seek(0);
        i.readFully(fullB, 5, 13);

        h.check(Arrays.equals(fullB, new byte[]
            {
              (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
              (byte) 0x00, (byte) 0x92, (byte) 0x80, (byte) 0x05,
              (byte) 0x77, (byte) 0xac, (byte) 0xf2, (byte) 0x8b,
              (byte) 0xa7, (byte) 0x5c, (byte) 0xd0, (byte) 0xaa,
              (byte) 0x0f, (byte) 0x89, (byte) 0x00, (byte) 0x00,
              (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
              (byte) 0x00, (byte) 0x00
            }));

        char[] fullC = new char[15];
        i.seek(0);
        i.readFully(fullC, 0, 15);

        h.check(Arrays.equals(fullC, new char[]
            {
              (char) 37504, (char) 1399, (char) 44274,
              (char) 35751, (char) 23760, (char) 43535,
              (char) 35072, (char) 4849, (char) 41455,
              (char) 33280, (char) 37504, (char) 1399,
              (char) 44274, (char) 35751, (char) 23760
            }));

        double[] fullD = new double[8];
        i.seek(0);
        i.readFully(fullD, 0, 8);

        h.check(Arrays.equals(fullD, new double[] {
                                -1.4183142849706364E-219,
                                1.2402952421911034E139,
                                -3.154063812740471E-145,
                                -3.556316535750171E-92,
                                -2.4925149951304603E-265,
                                -1.4183142849706364E-219,
                                1.2402952421911034E139,
                                -3.154063812740471E-145
                              }));

        float[] fullF = new float[16];
        i.seek(0);
        i.readFully(fullF, 0, 16);

        h.check(Arrays.equals(fullF, new float[] {
                                -8.079283E-28f,
                                -6.893558E-12f,
                                4.69870212E17f,
                                -1.5416346E-33f,
                                -1.6229681E-18f,
                                -8.079283E-28f,
                                -6.893558E-12f,
                                4.69870212E17f,
                                -1.5416346E-33f,
                                -1.6229681E-18f,
                                -8.079283E-28f,
                                -6.893558E-12f,
                                4.69870212E17f,
                                -1.5416346E-33f,
                                -1.6229681E-18f,
                                -8.079283E-28f
                              }));

        int[] fullI = new int[16];
        i.seek(0);
        i.readFully(fullI, 0, 16);

        h.check(Arrays.equals(fullI, new int[] {
                                -1837103753,
                                -1393390681,
                                1557178895,
                                -1996483855,
                                -1578139136,
                                -1837103753,
                                -1393390681,
                                1557178895,
                                -1996483855,
                                -1578139136,
                                -1837103753,
                                -1393390681,
                                1557178895,
                                -1996483855,
                                -1578139136,
                                -1837103753,
                              }));

        long[] fullL = new long[8];
        i.seek(0);
        i.readFully(fullL, 0, 8);

        h.check(Arrays.equals(fullL, new long[] {
                                -7890300535592285273L,
                                6688032430344901361L,
                                -6778055975199832713L,
                                -5984567403888989681L,
                                -8574832861500177920L,
                                -7890300535592285273L,
                                6688032430344901361L,
                                -6778055975199832713L,
                              }));

        short[] fullS = new short[32];
        i.seek(0);
        i.readFully(fullS, 0, 32);

        h.check(Arrays.equals(fullS, new short[] {
                                -28032,
                                1399,
                                -21262,
View Full Code Here

Examples of javax.imageio.stream.ImageInputStream

            return;
        }
        Iterator readers = ImageIO.getImageReadersBySuffix(suffix);
        assertTrue("No image reader found for suffix " + suffix, readers.hasNext());
        ImageReader reader = (ImageReader) readers.next();
        ImageInputStream iis = ImageIO.createImageInputStream(new File(filename));
        assertNotNull("No ImageInputStream created for file " + filename, iis);
        reader.setInput(iis);
        IIOMetadata imageMetadata = reader.getImageMetadata(0);
        Element root = (Element) imageMetadata.getAsTree(STANDARD_METADATA_FORMAT);
        NodeList dimensionNodes = root.getElementsByTagName("Dimension");
        assertTrue("No resolution found in image file " + filename, dimensionNodes.getLength() > 0);
        Element dimensionElement = (Element) dimensionNodes.item(0);

        NodeList pixelSizeNodes = dimensionElement.getElementsByTagName("HorizontalPixelSize");
        assertTrue("No X resolution found in image file " + filename, pixelSizeNodes.getLength() > 0);
        Node pixelSizeNode = pixelSizeNodes.item(0);
        String val = pixelSizeNode.getAttributes().getNamedItem("value").getNodeValue();
        int actualResolution = (int) Math.round(25.4 / Double.parseDouble(val));
        assertEquals("X resolution doesn't match in image file " + filename, expectedResolution, actualResolution);

        pixelSizeNodes = dimensionElement.getElementsByTagName("VerticalPixelSize");
        assertTrue("No Y resolution found in image file " + filename, pixelSizeNodes.getLength() > 0);
        pixelSizeNode = pixelSizeNodes.item(0);
        val = pixelSizeNode.getAttributes().getNamedItem("value").getNodeValue();
        actualResolution = (int) Math.round(25.4 / Double.parseDouble(val));
        assertEquals("Y resolution doesn't match", expectedResolution, actualResolution);

        iis.close();
        reader.dispose();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.