javax.imageio.stream.MemoryCacheImageInputStream Java Examples

The following examples show how to use javax.imageio.stream.MemoryCacheImageInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MJPGImageReader.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
/** Reads the image header.
 * Does nothing if the header has already been loaded.
 */
private void readHeader() throws IOException {
    if (image == null) {
        ImageReader r = new JPEGImageReader(getOriginatingProvider());
        Object in = getInput();
        /*if (in instanceof Buffer) {
            Buffer buffer = (Buffer) in;
            in=buffer.getData();
        }*/
        if (in instanceof byte[]) {
            r.setInput(new MemoryCacheImageInputStream(AVIBMPDIB.prependDHTSeg((byte[]) in)));
        } else if (in instanceof ImageInputStream) {
            r.setInput(AVIBMPDIB.prependDHTSeg((ImageInputStream) in));
        } else {
            r.setInput(AVIBMPDIB.prependDHTSeg((InputStream) in));
        }
        image = r.read(0);
    }
}
 
Example #2
Source File: InputStreamImageInputStreamSpi.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #3
Source File: InputStreamImageInputStreamSpi.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #4
Source File: InputStreamImageInputStreamSpi.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #5
Source File: InputStreamImageInputStreamSpi.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #6
Source File: InputStreamImageInputStreamSpi.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #7
Source File: InputStreamImageInputStreamSpi.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #8
Source File: InputStreamImageInputStreamSpi.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #9
Source File: InputStreamImageInputStreamSpi.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #10
Source File: InputStreamImageInputStreamSpi.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #11
Source File: InputStreamImageInputStreamSpi.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #12
Source File: InputStreamImageInputStreamSpi.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #13
Source File: GetElementsByTagNameTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
    // Generate some trivial image and save it to a temporary array
    ByteArrayOutputStream tmp = new ByteArrayOutputStream();
    ImageIO.write(new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB),
            "gif", tmp);

    // Read the stream
    ImageInputStream in = new MemoryCacheImageInputStream(
            new ByteArrayInputStream(tmp.toByteArray()));
    ImageReader reader = ImageIO.getImageReaders(in).next();
    reader.setInput(in);

    // Retrieve standard image metadata tree
    IIOMetadata meta = reader.getImageMetadata(0);
    if (meta == null || !meta.isStandardMetadataFormatSupported()) {
        throw new Error("Test failure: Missing metadata");
    }
    Element root = (Element) meta.
            getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);

    // Test getElementsByTagName("*")
    if (root.getElementsByTagName("*").getLength() == 0) {
        throw new RuntimeException("getElementsByTagName(\"*\") returns"
                + " nothing");
    }
}
 
Example #14
Source File: InputStreamImageInputStreamSpi.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #15
Source File: InputStreamImageInputStreamSpi.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #16
Source File: InputStreamImageInputStreamSpi.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #17
Source File: InputStreamImageInputStreamSpi.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #18
Source File: InputStreamImageInputStreamSpi.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public ImageInputStream createInputStreamInstance(Object input,
                                                  boolean useCache,
                                                  File cacheDir)
    throws IOException {
    if (input instanceof InputStream) {
        InputStream is = (InputStream)input;

        if (useCache) {
            return new FileCacheImageInputStream(is, cacheDir);
        } else {
            return new MemoryCacheImageInputStream(is);
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #19
Source File: TIFFDecompressor.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Reformats bit-discontiguous data into the {@code DataBuffer}
 * of the supplied {@code WritableRaster}.
 */
private static void reformatDiscontiguousData(byte[] buf,
                                              int[] bitsPerSample,
                                              int stride,
                                              int w,
                                              int h,
                                              WritableRaster raster)
    throws IOException {

    // Get SampleModel info.
    SampleModel sm = raster.getSampleModel();
    int numBands = sm.getNumBands();

    // Initialize input stream.
    ByteArrayInputStream is = new ByteArrayInputStream(buf);
    ImageInputStream iis = new MemoryCacheImageInputStream(is);

    // Reformat.
    long iisPosition = 0L;
    int y = raster.getMinY();
    for(int j = 0; j < h; j++, y++) {
        iis.seek(iisPosition);
        int x = raster.getMinX();
        for(int i = 0; i < w; i++, x++) {
            for(int b = 0; b < numBands; b++) {
                long bits = iis.readBits(bitsPerSample[b]);
                raster.setSample(x, y, b, (int)bits);
            }
        }
        iisPosition += stride;
    }
}
 
Example #20
Source File: JAIIIOServiceImpl.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public BufferedImage readImage(final InputStream in,
	final JPEG2000CodecOptions options) throws IOException, ServiceException
{
	final J2KImageReader reader = getReader();
	final MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream(
		in);
	reader.setInput(mciis, false, true);
	final J2KImageReadParam param = (J2KImageReadParam) reader
		.getDefaultReadParam();
	if (options.resolution != null) {
		param.setResolution(options.resolution.intValue());
	}
	return reader.read(0, param);
}
 
Example #21
Source File: NthItemNodeListTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    // Generate some trivial image and save it to a temporary array
    ByteArrayOutputStream tmp = new ByteArrayOutputStream();
    ImageIO.write(new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB),
            "gif", tmp);

    // Read it back in
    ImageInputStream in = new MemoryCacheImageInputStream(
            new ByteArrayInputStream(tmp.toByteArray()));
    ImageReader reader = ImageIO.getImageReaders(in).next();
    reader.setInput(in);

    // Retrieve standard image metadata tree
    IIOMetadata meta = reader.getImageMetadata(0);
    if (meta == null || !meta.isStandardMetadataFormatSupported()) {
        throw new Error("Test failure: Missing metadata");
    }
    Element root = (Element) meta.
            getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);

    NodeList nodeList = root.
            getElementsByTagName(root.getFirstChild().getNodeName());
    /*
     * Accessing the nth node should return null and not throw
     * IndexOutOfBoundsException.
     */
    Node n = (nodeList.item(nodeList.getLength()));
}
 
Example #22
Source File: TestSIMPPlugin.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    Iterator<ImageReader> readers = ImageIO.getImageReadersBySuffix("simp");
    ImageReader simpReader = null;
    if (readers.hasNext()) {
        simpReader = readers.next();
        System.out.println("reader="+simpReader);
    }
    if (simpReader == null) {
        throw new RuntimeException("Reader not found.");
    }

    ImageReaderSpi spi = simpReader.getOriginatingProvider();
    IIOMetadataFormat spiFmt =
        spi.getImageMetadataFormat("simp_metadata_1.0");
    System.out.println("fmt from SPI=" + spiFmt);

    ByteArrayInputStream bais = new ByteArrayInputStream(simpData);
    ImageInputStream iis = new MemoryCacheImageInputStream(bais);
    simpReader.setInput(iis);
    BufferedImage bi = simpReader.read(0);
    System.out.println(bi);
    IIOMetadata metadata = simpReader.getImageMetadata(0);
    System.out.println("Image metadata="+metadata);
    IIOMetadataFormat format =
        metadata.getMetadataFormat("simp_metadata_1.0");
    System.out.println("Image metadata format="+format);
    if (format == null) {
        throw new RuntimeException("MetadataFormat not found.");
    }
}
 
Example #23
Source File: Images.java    From basic-tools with MIT License 5 votes vote down vote up
public static String getImageType(byte[] mapObj) throws IOException {
    String type = "";
    try (ByteArrayInputStream bais = new ByteArrayInputStream(mapObj);
         MemoryCacheImageInputStream mcis = new MemoryCacheImageInputStream(bais)) {
        Iterator<ImageReader> itr = ImageIO.getImageReaders(mcis);
        while (itr.hasNext()) {
            ImageReader reader = itr.next();
            String imageName = reader.getClass().getSimpleName();
            if (imageName != null) {
                if ("GIFImageReader".equals(imageName)) {
                    type = "gif";
                } else if ("JPEGImageReader".equals(imageName)) {
                    type = "jpg";
                } else if ("PNGImageReader".equals(imageName)) {
                    type = "png";
                } else if ("BMPImageReader".equals(imageName)) {
                    type = "bmp";
                } else {
                    type = "noPic";
                }
            }
        }
    } catch (Exception e) {
        type = "noPic";
    }
    return type;
}
 
Example #24
Source File: LZWFilter.java    From sambox with Apache License 2.0 5 votes vote down vote up
private static void checkIndexBounds(List<byte[]> codeTable, long index,
        MemoryCacheImageInputStream in) throws IOException
{
    if (index < 0)
    {
        throw new IOException(
                "negative array index: " + index + " near offset " + in.getStreamPosition());
    }
    if (index >= codeTable.size())
    {
        throw new IOException("array index overflow: " + index + " >= " + codeTable.size()
                + " near offset " + in.getStreamPosition());
    }
}
 
Example #25
Source File: PDFunctionType0.java    From sambox with Apache License 2.0 5 votes vote down vote up
/**
 * Get all sample values of this function.
 *
 * @return an array with all samples.
 */
private int[][] getSamples()
{
    if (samples == null)
    {
        int arraySize = 1;
        int nIn = getNumberOfInputParameters();
        int nOut = getNumberOfOutputParameters();
        COSArray sizes = getSize();
        for (int i = 0; i < nIn; i++)
        {
            arraySize *= sizes.getInt(i);
        }
        samples = new int[arraySize][nOut];
        int bitsPerSample = getBitsPerSample();
        int index = 0;
        try
        {
            // PDF spec 1.7 p.171:
            // Each sample value is represented as a sequence of BitsPerSample bits. 
            // Successive values are adjacent in the bit stream; there is no padding at byte boundaries.
            ImageInputStream mciis = new MemoryCacheImageInputStream(getPDStream().createInputStream());
            for (int i = 0; i < arraySize; i++)
            {
                for (int k = 0; k < nOut; k++)
                {
                    // TODO will this cast work properly for 32 bitsPerSample or should we use long[]?
                    samples[index][k] = (int) mciis.readBits(bitsPerSample);
                }
                index++;
            }
            mciis.close();
        }
        catch (IOException exception)
        {
            LOG.error("IOException while reading the sample values of this function.", exception);
        }
    }
    return samples;
}
 
Example #26
Source File: PDFunctionType0.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Get all sample values of this function.
 *
 * @return an array with all samples.
 */
private int[][] getSamples()
{
    if (samples == null)
    {
        int arraySize = 1;
        int nIn = getNumberOfInputParameters();
        int nOut = getNumberOfOutputParameters();
        COSArray sizes = getSize();
        for (int i = 0; i < nIn; i++)
        {
            arraySize *= sizes.getInt(i);
        }
        samples = new int[arraySize][nOut];
        int bitsPerSample = getBitsPerSample();
        int index = 0;
        try
        {
            // PDF spec 1.7 p.171:
            // Each sample value is represented as a sequence of BitsPerSample bits. 
            // Successive values are adjacent in the bit stream; there is no padding at byte boundaries.
            ImageInputStream mciis = new MemoryCacheImageInputStream(getPDStream().createInputStream());
            for (int i = 0; i < arraySize; i++)
            {
                for (int k = 0; k < nOut; k++)
                {
                    // TODO will this cast work properly for 32 bitsPerSample or should we use long[]?
                    samples[index][k] = (int) mciis.readBits(bitsPerSample);
                }
                index++;
            }
            mciis.close();
        }
        catch (IOException exception)
        {
            LOG.error("IOException while reading the sample values of this function.", exception);
        }
    }
    return samples;
}
 
Example #27
Source File: LZWFilter.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void checkIndexBounds(List<byte[]> codeTable, long index, MemoryCacheImageInputStream in)
        throws IOException
{
    if (index < 0)
    {
        throw new IOException("negative array index: " + index + " near offset "
                + in.getStreamPosition());
    }
    if (index >= codeTable.size())
    {
        throw new IOException("array index overflow: " + index +
                " >= " + codeTable.size() + " near offset "
                + in.getStreamPosition());
    }
}
 
Example #28
Source File: BufferedImageHttpMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private ImageInputStream createImageInputStream(InputStream is) throws IOException {
	if (this.cacheDir != null) {
		return new FileCacheImageInputStream(is, this.cacheDir);
	}
	else {
		return new MemoryCacheImageInputStream(is);
	}
}
 
Example #29
Source File: BufferedImageHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private ImageInputStream createImageInputStream(InputStream is) throws IOException {
	if (this.cacheDir != null) {
		return new FileCacheImageInputStream(is, cacheDir);
	}
	else {
		return new MemoryCacheImageInputStream(is);
	}
}
 
Example #30
Source File: BufferedImageHttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private ImageInputStream createImageInputStream(InputStream is) throws IOException {
	if (this.cacheDir != null) {
		return new FileCacheImageInputStream(is, cacheDir);
	}
	else {
		return new MemoryCacheImageInputStream(is);
	}
}