javax.imageio.spi.ImageWriterSpi Java Examples

The following examples show how to use javax.imageio.spi.ImageWriterSpi. 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: ImageIO.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode images of the given layout (specified using an
 * <code>ImageTypeSpecifier</code>) in the given format.
 *
 * @param type an <code>ImageTypeSpecifier</code> indicating the
 * layout of the image to be written.
 * @param formatName the informal name of the <code>format</code>.
 *
 * @return an <code>Iterator</code> containing <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if any parameter is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#canEncodeImage(ImageTypeSpecifier)
 */
public static Iterator<ImageWriter>
    getImageWriters(ImageTypeSpecifier type, String formatName)
{
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }

    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                             new CanEncodeImageAndFormatFilter(type,
                                                               formatName),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }

    return new ImageWriterIterator(iter);
}
 
Example #2
Source File: ImageIO.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode files with the given suffix.
 *
 * @param fileSuffix a <code>String</code> containing a file
 * suffix (<i>e.g.</i>, "jpg" or "tiff").
 *
 * @return an <code>Iterator</code> containing <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if <code>fileSuffix</code> is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#getFileSuffixes
 */
public static Iterator<ImageWriter>
    getImageWritersBySuffix(String fileSuffix)
{
    if (fileSuffix == null) {
        throw new IllegalArgumentException("fileSuffix == null!");
    }
    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                               new ContainsFilter(writerFileSuffixesMethod,
                                                  fileSuffix),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageWriterIterator(iter);
}
 
Example #3
Source File: ImageIO.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode files with the given suffix.
 *
 * @param fileSuffix a <code>String</code> containing a file
 * suffix (<i>e.g.</i>, "jpg" or "tiff").
 *
 * @return an <code>Iterator</code> containing <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if <code>fileSuffix</code> is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#getFileSuffixes
 */
public static Iterator<ImageWriter>
    getImageWritersBySuffix(String fileSuffix)
{
    if (fileSuffix == null) {
        throw new IllegalArgumentException("fileSuffix == null!");
    }
    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                               new ContainsFilter(writerFileSuffixesMethod,
                                                  fileSuffix),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageWriterIterator(iter);
}
 
Example #4
Source File: ImageIO.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode images of the given layout (specified using an
 * <code>ImageTypeSpecifier</code>) in the given format.
 *
 * @param type an <code>ImageTypeSpecifier</code> indicating the
 * layout of the image to be written.
 * @param formatName the informal name of the <code>format</code>.
 *
 * @return an <code>Iterator</code> containing <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if any parameter is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#canEncodeImage(ImageTypeSpecifier)
 */
public static Iterator<ImageWriter>
    getImageWriters(ImageTypeSpecifier type, String formatName)
{
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }

    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                             new CanEncodeImageAndFormatFilter(type,
                                                               formatName),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }

    return new ImageWriterIterator(iter);
}
 
Example #5
Source File: ImageIO.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an {@code Iterator} containing all currently
 * registered {@code ImageWriter}s that claim to be able to
 * encode images of the given layout (specified using an
 * {@code ImageTypeSpecifier}) in the given format.
 *
 * @param type an {@code ImageTypeSpecifier} indicating the
 * layout of the image to be written.
 * @param formatName the informal name of the {@code format}.
 *
 * @return an {@code Iterator} containing {@code ImageWriter}s.
 *
 * @exception IllegalArgumentException if any parameter is
 * {@code null}.
 *
 * @see javax.imageio.spi.ImageWriterSpi#canEncodeImage(ImageTypeSpecifier)
 */
public static Iterator<ImageWriter>
    getImageWriters(ImageTypeSpecifier type, String formatName)
{
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }

    Iterator<ImageWriterSpi> iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                             new CanEncodeImageAndFormatFilter(type,
                                                               formatName),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }

    return new ImageWriterIterator(iter);
}
 
Example #6
Source File: ImageIO.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode the named format.
 *
 * @param formatName a <code>String</code> containing the informal
 * name of a format (<i>e.g.</i>, "jpeg" or "tiff".
 *
 * @return an <code>Iterator</code> containing
 * <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if <code>formatName</code> is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#getFormatNames
 */
public static Iterator<ImageWriter>
    getImageWritersByFormatName(String formatName)
{
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }
    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                new ContainsFilter(writerFormatNamesMethod,
                                                   formatName),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageWriterIterator(iter);
}
 
Example #7
Source File: ImageIO.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageTranscoder</code>s that claim to be
 * able to transcode between the metadata of the given
 * <code>ImageReader</code> and <code>ImageWriter</code>.
 *
 * @param reader an <code>ImageReader</code>.
 * @param writer an <code>ImageWriter</code>.
 *
 * @return an <code>Iterator</code> containing
 * <code>ImageTranscoder</code>s.
 *
 * @exception IllegalArgumentException if <code>reader</code> or
 * <code>writer</code> is <code>null</code>.
 */
public static Iterator<ImageTranscoder>
    getImageTranscoders(ImageReader reader, ImageWriter writer)
{
    if (reader == null) {
        throw new IllegalArgumentException("reader == null!");
    }
    if (writer == null) {
        throw new IllegalArgumentException("writer == null!");
    }
    ImageReaderSpi readerSpi = reader.getOriginatingProvider();
    ImageWriterSpi writerSpi = writer.getOriginatingProvider();
    ServiceRegistry.Filter filter =
        new TranscoderFilter(readerSpi, writerSpi);

    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageTranscoderSpi.class,
                                        filter, true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageTranscoderIterator(iter);
}
 
Example #8
Source File: ImageIOGreyScale.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently registered <code>ImageWriter</code>s that
 * claim to be able to encode images of the given layout (specified using an
 * <code>ImageTypeSpecifier</code>) in the given format.
 * 
 * @param type
 *            an <code>ImageTypeSpecifier</code> indicating the layout of the image to be written.
 * @param formatName
 *            the informal name of the <code>format</code>.
 * 
 * @return an <code>Iterator</code> containing <code>ImageWriter</code>s.
 * 
 * @exception IllegalArgumentException
 *                if any parameter is <code>null</code>.
 * 
 * @see javax.imageio.spi.ImageWriterSpi#canEncodeImage(ImageTypeSpecifier)
 */
public static Iterator<ImageWriter> getImageWriters(ImageTypeSpecifier type, String formatName) {
	if (type == null) {
		throw new IllegalArgumentException("type == null!");
	}
	if (formatName == null) {
		throw new IllegalArgumentException("formatName == null!");
	}

	Iterator iter;
	// Ensure category is present
	try {
		iter = theRegistry.getServiceProviders(ImageWriterSpi.class, new CanEncodeImageAndFormatFilter(type, formatName), true);
	} catch (IllegalArgumentException e) {
		return new HashSet().iterator();
	}

	return new ImageWriterIterator(iter);
}
 
Example #9
Source File: ImageIO.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageTranscoder</code>s that claim to be
 * able to transcode between the metadata of the given
 * <code>ImageReader</code> and <code>ImageWriter</code>.
 *
 * @param reader an <code>ImageReader</code>.
 * @param writer an <code>ImageWriter</code>.
 *
 * @return an <code>Iterator</code> containing
 * <code>ImageTranscoder</code>s.
 *
 * @exception IllegalArgumentException if <code>reader</code> or
 * <code>writer</code> is <code>null</code>.
 */
public static Iterator<ImageTranscoder>
    getImageTranscoders(ImageReader reader, ImageWriter writer)
{
    if (reader == null) {
        throw new IllegalArgumentException("reader == null!");
    }
    if (writer == null) {
        throw new IllegalArgumentException("writer == null!");
    }
    ImageReaderSpi readerSpi = reader.getOriginatingProvider();
    ImageWriterSpi writerSpi = writer.getOriginatingProvider();
    ServiceRegistry.Filter filter =
        new TranscoderFilter(readerSpi, writerSpi);

    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageTranscoderSpi.class,
                                        filter, true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageTranscoderIterator(iter);
}
 
Example #10
Source File: ImageIO.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode the named format.
 *
 * @param formatName a <code>String</code> containing the informal
 * name of a format (<i>e.g.</i>, "jpeg" or "tiff".
 *
 * @return an <code>Iterator</code> containing
 * <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if <code>formatName</code> is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#getFormatNames
 */
public static Iterator<ImageWriter>
    getImageWritersByFormatName(String formatName)
{
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }
    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                new ContainsFilter(writerFormatNamesMethod,
                                                   formatName),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageWriterIterator(iter);
}
 
Example #11
Source File: ImageIO.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an {@code Iterator} containing all currently
 * registered {@code ImageWriter}s that claim to be able to
 * encode images of the given layout (specified using an
 * {@code ImageTypeSpecifier}) in the given format.
 *
 * @param type an {@code ImageTypeSpecifier} indicating the
 * layout of the image to be written.
 * @param formatName the informal name of the {@code format}.
 *
 * @return an {@code Iterator} containing {@code ImageWriter}s.
 *
 * @exception IllegalArgumentException if any parameter is
 * {@code null}.
 *
 * @see javax.imageio.spi.ImageWriterSpi#canEncodeImage(ImageTypeSpecifier)
 */
public static Iterator<ImageWriter>
    getImageWriters(ImageTypeSpecifier type, String formatName)
{
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }

    Iterator<ImageWriterSpi> iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                             new CanEncodeImageAndFormatFilter(type,
                                                               formatName),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }

    return new ImageWriterIterator(iter);
}
 
Example #12
Source File: ImageIO.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode the named format.
 *
 * @param formatName a <code>String</code> containing the informal
 * name of a format (<i>e.g.</i>, "jpeg" or "tiff".
 *
 * @return an <code>Iterator</code> containing
 * <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if <code>formatName</code> is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#getFormatNames
 */
public static Iterator<ImageWriter>
    getImageWritersByFormatName(String formatName)
{
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }
    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                new ContainsFilter(writerFormatNamesMethod,
                                                   formatName),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageWriterIterator(iter);
}
 
Example #13
Source File: WriteAfterAbort.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws IOException {
    final IIORegistry registry = IIORegistry.getDefaultInstance();
    final Iterator<ImageWriterSpi> iter = registry.getServiceProviders(
            ImageWriterSpi.class, provider -> true, true);

    // Validates all supported ImageWriters
    int numFailures = 0;
    while (iter.hasNext()) {
        final WriteAfterAbort writeAfterAbort = new WriteAfterAbort();
        final ImageWriter writer = iter.next().createWriterInstance();
        System.out.println("ImageWriter = " + writer);
        try {
            writeAfterAbort.test(writer);
        } catch (Exception e) {
            System.err.println("Test failed for \""
                + writer.getOriginatingProvider().getFormatNames()[0]
                + "\" format.");
            numFailures++;
        }
    }
    if (numFailures == 0) {
        System.out.println("Test passed.");
    } else {
        throw new RuntimeException("Test failed.");
    }
}
 
Example #14
Source File: ImageIO.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode files with the given MIME type.
 *
 * @param MIMEType a <code>String</code> containing a file
 * suffix (<i>e.g.</i>, "image/jpeg" or "image/x-bmp").
 *
 * @return an <code>Iterator</code> containing <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if <code>MIMEType</code> is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#getMIMETypes
 */
public static Iterator<ImageWriter>
    getImageWritersByMIMEType(String MIMEType)
{
    if (MIMEType == null) {
        throw new IllegalArgumentException("MIMEType == null!");
    }
    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                  new ContainsFilter(writerMIMETypesMethod,
                                                     MIMEType),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageWriterIterator(iter);
}
 
Example #15
Source File: GifTransparencyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void doTest() {
    File pwd = new File(".");
    try {
        File f = File.createTempFile("transparency_test_", ".gif", pwd);
        System.out.println("file: " + f.getCanonicalPath());

        ImageWriter w = ImageIO.getImageWritersByFormatName("GIF").next();

        ImageWriterSpi spi = w.getOriginatingProvider();

        boolean succeed_write = ImageIO.write(src, "gif", f);

        if (!succeed_write) {
            throw new RuntimeException("Test failed: failed to write src.");
        }

        dst = ImageIO.read(f);

        checkResult(src, dst);

    } catch (IOException e) {
        throw new RuntimeException("Test failed.", e);
    }
}
 
Example #16
Source File: ImageIO.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode images of the given layout (specified using an
 * <code>ImageTypeSpecifier</code>) in the given format.
 *
 * @param type an <code>ImageTypeSpecifier</code> indicating the
 * layout of the image to be written.
 * @param formatName the informal name of the <code>format</code>.
 *
 * @return an <code>Iterator</code> containing <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if any parameter is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#canEncodeImage(ImageTypeSpecifier)
 */
public static Iterator<ImageWriter>
    getImageWriters(ImageTypeSpecifier type, String formatName)
{
    if (type == null) {
        throw new IllegalArgumentException("type == null!");
    }
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }

    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                             new CanEncodeImageAndFormatFilter(type,
                                                               formatName),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }

    return new ImageWriterIterator(iter);
}
 
Example #17
Source File: ImageIO.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageTranscoder</code>s that claim to be
 * able to transcode between the metadata of the given
 * <code>ImageReader</code> and <code>ImageWriter</code>.
 *
 * @param reader an <code>ImageReader</code>.
 * @param writer an <code>ImageWriter</code>.
 *
 * @return an <code>Iterator</code> containing
 * <code>ImageTranscoder</code>s.
 *
 * @exception IllegalArgumentException if <code>reader</code> or
 * <code>writer</code> is <code>null</code>.
 */
public static Iterator<ImageTranscoder>
    getImageTranscoders(ImageReader reader, ImageWriter writer)
{
    if (reader == null) {
        throw new IllegalArgumentException("reader == null!");
    }
    if (writer == null) {
        throw new IllegalArgumentException("writer == null!");
    }
    ImageReaderSpi readerSpi = reader.getOriginatingProvider();
    ImageWriterSpi writerSpi = writer.getOriginatingProvider();
    ServiceRegistry.Filter filter =
        new TranscoderFilter(readerSpi, writerSpi);

    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageTranscoderSpi.class,
                                        filter, true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageTranscoderIterator(iter);
}
 
Example #18
Source File: ImageIO.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an {@code Iterator} containing all currently
 * registered {@code ImageWriter}s that claim to be able to
 * encode files with the given MIME type.
 *
 * @param MIMEType a {@code String} containing a file
 * suffix (<i>e.g.</i>, "image/jpeg" or "image/x-bmp").
 *
 * @return an {@code Iterator} containing {@code ImageWriter}s.
 *
 * @exception IllegalArgumentException if {@code MIMEType} is
 * {@code null}.
 *
 * @see javax.imageio.spi.ImageWriterSpi#getMIMETypes
 */
public static Iterator<ImageWriter>
    getImageWritersByMIMEType(String MIMEType)
{
    if (MIMEType == null) {
        throw new IllegalArgumentException("MIMEType == null!");
    }
    Iterator<ImageWriterSpi> iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                  new ContainsFilter(writerMIMETypesMethod,
                                                     MIMEType),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageWriterIterator(iter);
}
 
Example #19
Source File: ImageIO.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode files with the given MIME type.
 *
 * @param MIMEType a <code>String</code> containing a file
 * suffix (<i>e.g.</i>, "image/jpeg" or "image/x-bmp").
 *
 * @return an <code>Iterator</code> containing <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if <code>MIMEType</code> is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#getMIMETypes
 */
public static Iterator<ImageWriter>
    getImageWritersByMIMEType(String MIMEType)
{
    if (MIMEType == null) {
        throw new IllegalArgumentException("MIMEType == null!");
    }
    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                  new ContainsFilter(writerMIMETypesMethod,
                                                     MIMEType),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageWriterIterator(iter);
}
 
Example #20
Source File: ImageIO.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageWriter</code>s that claim to be able to
 * encode the named format.
 *
 * @param formatName a <code>String</code> containing the informal
 * name of a format (<i>e.g.</i>, "jpeg" or "tiff".
 *
 * @return an <code>Iterator</code> containing
 * <code>ImageWriter</code>s.
 *
 * @exception IllegalArgumentException if <code>formatName</code> is
 * <code>null</code>.
 *
 * @see javax.imageio.spi.ImageWriterSpi#getFormatNames
 */
public static Iterator<ImageWriter>
    getImageWritersByFormatName(String formatName)
{
    if (formatName == null) {
        throw new IllegalArgumentException("formatName == null!");
    }
    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                new ContainsFilter(writerFormatNamesMethod,
                                                   formatName),
                                        true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageWriterIterator(iter);
}
 
Example #21
Source File: ImageIO.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageTranscoder</code>s that claim to be
 * able to transcode between the metadata of the given
 * <code>ImageReader</code> and <code>ImageWriter</code>.
 *
 * @param reader an <code>ImageReader</code>.
 * @param writer an <code>ImageWriter</code>.
 *
 * @return an <code>Iterator</code> containing
 * <code>ImageTranscoder</code>s.
 *
 * @exception IllegalArgumentException if <code>reader</code> or
 * <code>writer</code> is <code>null</code>.
 */
public static Iterator<ImageTranscoder>
    getImageTranscoders(ImageReader reader, ImageWriter writer)
{
    if (reader == null) {
        throw new IllegalArgumentException("reader == null!");
    }
    if (writer == null) {
        throw new IllegalArgumentException("writer == null!");
    }
    ImageReaderSpi readerSpi = reader.getOriginatingProvider();
    ImageWriterSpi writerSpi = writer.getOriginatingProvider();
    ServiceRegistry.Filter filter =
        new TranscoderFilter(readerSpi, writerSpi);

    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageTranscoderSpi.class,
                                        filter, true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageTranscoderIterator(iter);
}
 
Example #22
Source File: ImageIO.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an <code>Iterator</code> containing all currently
 * registered <code>ImageTranscoder</code>s that claim to be
 * able to transcode between the metadata of the given
 * <code>ImageReader</code> and <code>ImageWriter</code>.
 *
 * @param reader an <code>ImageReader</code>.
 * @param writer an <code>ImageWriter</code>.
 *
 * @return an <code>Iterator</code> containing
 * <code>ImageTranscoder</code>s.
 *
 * @exception IllegalArgumentException if <code>reader</code> or
 * <code>writer</code> is <code>null</code>.
 */
public static Iterator<ImageTranscoder>
    getImageTranscoders(ImageReader reader, ImageWriter writer)
{
    if (reader == null) {
        throw new IllegalArgumentException("reader == null!");
    }
    if (writer == null) {
        throw new IllegalArgumentException("writer == null!");
    }
    ImageReaderSpi readerSpi = reader.getOriginatingProvider();
    ImageWriterSpi writerSpi = writer.getOriginatingProvider();
    ServiceRegistry.Filter filter =
        new TranscoderFilter(readerSpi, writerSpi);

    Iterator iter;
    // Ensure category is present
    try {
        iter = theRegistry.getServiceProviders(ImageTranscoderSpi.class,
                                        filter, true);
    } catch (IllegalArgumentException e) {
        return Collections.emptyIterator();
    }
    return new ImageTranscoderIterator(iter);
}
 
Example #23
Source File: ImageUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** Checks that the provided <code>ImageWriter</code> can encode
 * the provided <code>ImageTypeSpecifier</code> or not.  If not, an
 * <code>IIOException</code> will be thrown.
 * @param writer The provided <code>ImageWriter</code>.
 * @param type The image to be tested.
 * @throws IIOException If the writer cannot encoded the provided image.
 */
public static final void canEncodeImage(ImageWriter writer,
                                        ImageTypeSpecifier type)
    throws IIOException {
    ImageWriterSpi spi = writer.getOriginatingProvider();

    if(type != null && spi != null && !spi.canEncodeImage(type))  {
        throw new IIOException(I18N.getString("ImageUtil2")+" "+
                               writer.getClass().getName());
    }
}
 
Example #24
Source File: OutputImageTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void initIIOWriteFormats() {
    List spis = new ArrayList();
    List shortNames = new ArrayList();

    ImageIO.scanForPlugins();
    IIORegistry registry = IIORegistry.getDefaultInstance();
    java.util.Iterator writerspis =
        registry.getServiceProviders(ImageWriterSpi.class, false);
    while (writerspis.hasNext()) {
        // REMIND: there could be more than one non-core plugin for
        // a particular format, as is the case for JPEG2000 in the JAI
        // IIO Tools package, so we should support that somehow
        ImageWriterSpi spi = (ImageWriterSpi)writerspis.next();
        String klass = spi.getClass().getName();
        String format = spi.getFormatNames()[0].toLowerCase();
        String suffix = spi.getFileSuffixes()[0].toLowerCase();
        if (suffix == null || suffix.equals("")) {
            suffix = format;
        }
        String shortName;
        if (klass.startsWith("com.sun.imageio.plugins")) {
            shortName = "core-" + suffix;
        } else {
            shortName = "ext-" + suffix;
        }
        spis.add(spi);
        shortNames.add(shortName);
    }

    imageioWriterSpis = new ImageWriterSpi[spis.size()];
    imageioWriterSpis = (ImageWriterSpi[])spis.toArray(imageioWriterSpis);
    imageioWriteFormatShortNames = new String[shortNames.size()];
    imageioWriteFormatShortNames =
        (String[])shortNames.toArray(imageioWriteFormatShortNames);
}
 
Example #25
Source File: WriteAfterAbort.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws IOException {
    final IIORegistry registry = IIORegistry.getDefaultInstance();
    final Iterator<ImageWriterSpi> iter = registry.getServiceProviders(
            ImageWriterSpi.class, provider -> true, true);

    // Validates all supported ImageWriters
    while (iter.hasNext()) {
        final WriteAfterAbort writeAfterAbort = new WriteAfterAbort();
        final ImageWriter writer = iter.next().createWriterInstance();
        System.out.println("ImageWriter = " + writer);
        writeAfterAbort.test(writer);
    }
    System.out.println("Test passed");
}
 
Example #26
Source File: WriteAfterAbort.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws IOException {
    final IIORegistry registry = IIORegistry.getDefaultInstance();
    final Iterator<ImageWriterSpi> iter = registry.getServiceProviders(
            ImageWriterSpi.class, provider -> true, true);

    // Validates all supported ImageWriters
    while (iter.hasNext()) {
        final WriteAfterAbort writeAfterAbort = new WriteAfterAbort();
        final ImageWriter writer = iter.next().createWriterInstance();
        System.out.println("ImageWriter = " + writer);
        writeAfterAbort.test(writer);
    }
    System.out.println("Test passed");
}
 
Example #27
Source File: CanWriteSequence.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final IIORegistry registry = IIORegistry.getDefaultInstance();
    final Iterator<ImageWriterSpi> iter =
            registry.getServiceProviders(ImageWriterSpi.class,
                    provider -> true, true);
    // Validates all supported ImageWriters
    while (iter.hasNext()) {
        final ImageWriter writer = iter.next().createWriterInstance();
        System.out.println("ImageWriter = " + writer);
        test(writer);
    }
    System.out.println("Test passed");
}
 
Example #28
Source File: OutputImageTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void initIIOWriteFormats() {
    List spis = new ArrayList();
    List shortNames = new ArrayList();

    ImageIO.scanForPlugins();
    IIORegistry registry = IIORegistry.getDefaultInstance();
    java.util.Iterator writerspis =
        registry.getServiceProviders(ImageWriterSpi.class, false);
    while (writerspis.hasNext()) {
        // REMIND: there could be more than one non-core plugin for
        // a particular format, as is the case for JPEG2000 in the JAI
        // IIO Tools package, so we should support that somehow
        ImageWriterSpi spi = (ImageWriterSpi)writerspis.next();
        String klass = spi.getClass().getName();
        String format = spi.getFormatNames()[0].toLowerCase();
        String suffix = spi.getFileSuffixes()[0].toLowerCase();
        if (suffix == null || suffix.equals("")) {
            suffix = format;
        }
        String shortName;
        if (klass.startsWith("com.sun.imageio.plugins")) {
            shortName = "core-" + suffix;
        } else {
            shortName = "ext-" + suffix;
        }
        spis.add(spi);
        shortNames.add(shortName);
    }

    imageioWriterSpis = new ImageWriterSpi[spis.size()];
    imageioWriterSpis = (ImageWriterSpi[])spis.toArray(imageioWriterSpis);
    imageioWriteFormatShortNames = new String[shortNames.size()];
    imageioWriteFormatShortNames =
        (String[])shortNames.toArray(imageioWriteFormatShortNames);
}
 
Example #29
Source File: CanWriteSequence.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final IIORegistry registry = IIORegistry.getDefaultInstance();
    final Iterator<ImageWriterSpi> iter =
            registry.getServiceProviders(ImageWriterSpi.class,
                    provider -> true, true);
    // Validates all supported ImageWriters
    while (iter.hasNext()) {
        final ImageWriter writer = iter.next().createWriterInstance();
        System.out.println("ImageWriter = " + writer);
        test(writer);
    }
    System.out.println("Test passed");
}
 
Example #30
Source File: CanWriteSequence.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final IIORegistry registry = IIORegistry.getDefaultInstance();
    final Iterator<ImageWriterSpi> iter =
            registry.getServiceProviders(ImageWriterSpi.class,
                    provider -> true, true);
    // Validates all supported ImageWriters
    while (iter.hasNext()) {
        final ImageWriter writer = iter.next().createWriterInstance();
        System.out.println("ImageWriter = " + writer);
        test(writer);
    }
    System.out.println("Test passed");
}