本文整理汇总了Java中javax.imageio.spi.ServiceRegistry类的典型用法代码示例。如果您正苦于以下问题:Java ServiceRegistry类的具体用法?Java ServiceRegistry怎么用?Java ServiceRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceRegistry类属于javax.imageio.spi包,在下文中一共展示了ServiceRegistry类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTiff
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
/**
* Writes a buffered image to a TIFF output stream.
* @param image buffered image to write out as a TIFF
* @param output output stream to write to
* @throws IOException If there is an error writing to
* <code>output</code>.
*/
private void writeTiff(BufferedImage image, OutputStream output)
throws IOException {
try (ImageOutputStream ios =
ImageIO.createImageOutputStream(output)) {
IIORegistry registry = IIORegistry.getDefaultInstance();
registry.registerServiceProviders(
ServiceRegistry.lookupProviders(
TIFFImageWriterSpi.class));
TIFFImageWriterSpi spi = registry.getServiceProviderByClass(
TIFFImageWriterSpi.class);
TIFFImageWriter writer = new TIFFImageWriter(spi);
writer.setOutput(ios);
writer.write(null, new IIOImage(image, null, null), null);
}
}
示例2: getImageTranscoders
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
/**
* 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);
}
示例3: getImageTranscoders
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
/**
* Returns an {@code Iterator} containing all currently
* registered {@code ImageTranscoder}s that claim to be
* able to transcode between the metadata of the given
* {@code ImageReader} and {@code ImageWriter}.
*
* @param reader an {@code ImageReader}.
* @param writer an {@code ImageWriter}.
*
* @return an {@code Iterator} containing
* {@code ImageTranscoder}s.
*
* @exception IllegalArgumentException if {@code reader} or
* {@code writer} is {@code null}.
*/
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<ImageTranscoderSpi> iter;
// Ensure category is present
try {
iter = theRegistry.getServiceProviders(ImageTranscoderSpi.class,
filter, true);
} catch (IllegalArgumentException e) {
return Collections.emptyIterator();
}
return new ImageTranscoderIterator(iter);
}
示例4: OrderingTest
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
public OrderingTest() {
ServiceRegistry reg = IIORegistry.getDefaultInstance();
ImageReaderSpi gifSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.gif.GIFImageReaderSpi.class);
ImageReaderSpi pngSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.png.PNGImageReaderSpi.class);
boolean ordered = reg.setOrdering(ImageReaderSpi.class, gifSpi, pngSpi);
ordered = reg.setOrdering(ImageReaderSpi.class, pngSpi, gifSpi);
boolean unordered = reg.unsetOrdering(ImageReaderSpi.class, gifSpi,
pngSpi);
boolean unordered1 = reg.unsetOrdering(ImageReaderSpi.class, gifSpi,
pngSpi);
if (unordered1) {
throw new RuntimeException("FAIL: Ordering 2 spi objects in the "
+ "reverse direction does not remove the previous ordering "
+ "set between the spi objects and hence unsetOrdering() "
+ "returns true for the same spi objects when called consecutively");
} else {
System.out.println("PASS");
}
}
示例5: SpiTest
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
public SpiTest() {
testImageReaderSpiConstructor();
testImageWriterSpiConstructor();
ServiceRegistry registry = IIORegistry.getDefaultInstance();
Iterator readers = registry.getServiceProviders(ImageReaderSpi.class,
false);
while (readers.hasNext()) {
ImageReaderSpi rspi = (ImageReaderSpi)readers.next();
System.out.println("*** Testing " + rspi.getClass().getName());
testSpi(rspi);
}
Iterator writers = registry.getServiceProviders(ImageWriterSpi.class,
false);
while (writers.hasNext()) {
ImageWriterSpi wspi = (ImageWriterSpi)writers.next();
System.out.println("*** Testing " + wspi.getClass().getName());
testSpi(wspi);
}
}
示例6: DeregisterOrderedSpiTest
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
public DeregisterOrderedSpiTest() {
try {
ServiceRegistry reg = IIORegistry.getDefaultInstance();
ImageReaderSpi gifSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.gif.GIFImageReaderSpi.class);
ImageReaderSpi pngSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.png.PNGImageReaderSpi.class);
ImageReaderSpi jpgSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi.class);
ImageReaderSpi bmpSpi = (ImageReaderSpi) reg.getServiceProviderByClass(com.sun.imageio.plugins.bmp.BMPImageReaderSpi.class);
boolean ordered = reg.setOrdering(ImageReaderSpi.class, pngSpi,
gifSpi);
ordered = reg.setOrdering(ImageReaderSpi.class, gifSpi, jpgSpi);
ordered = reg.setOrdering(ImageReaderSpi.class, bmpSpi, gifSpi);
reg.deregisterServiceProvider(gifSpi);
System.out.println("PASS");
} catch (Exception e) {
System.out.println("FAIL");
throw new RuntimeException("Deregistering a spi object involved in some "
+ "ordering throws the following exception: " + e.toString());
}
}
示例7: load
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
public void load() {
Iterator<JobValidatorService> loadedFactories = ServiceRegistry.lookupProviders(JobValidatorService.class);
ImmutableMap.Builder<String, JobValidatorService> mapBuilder = new ImmutableMap.Builder();
while (loadedFactories.hasNext()) {
try {
JobValidatorService validator = loadedFactories.next();
String validatorID = validator.getClass().getCanonicalName();
logger.debug("Job Validator Factory provider <" + validatorID + "> found");
mapBuilder.put(validatorID, validator);
} catch (Exception err) {
logger.error("Failed to load job validator factory: " + err);
}
}
jobValidators = mapBuilder.build();
if (logger.isInfoEnabled()) {
logger.info("[JobValidatorRegistry] job validators registered : " + jobValidators.keySet());
}
}
示例8: onRegistration
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
public void onRegistration(ServiceRegistry registry,
Class category) {
if (registered) {
return;
}
registered = true;
// Set pairwise ordering to give codecLib reader precedence.
Class codecLibReaderSPIClass = null;
try {
codecLibReaderSPIClass =
Class.forName("io.scif.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLibSpi");
} catch(Throwable t) {
// Ignore it.
}
if(codecLibReaderSPIClass != null) {
Object codecLibReaderSPI =
registry.getServiceProviderByClass(codecLibReaderSPIClass);
if(codecLibReaderSPI != null) {
registry.setOrdering(category, codecLibReaderSPI, this);
}
}
}
示例9: onRegistration
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
public void onRegistration(ServiceRegistry registry,
Class category) {
if (registered) {
return;
}
registered = true;
// Set pairwise ordering to give codecLib writer precedence.
Class codecLibWriterSPIClass = null;
try {
codecLibWriterSPIClass =
Class.forName("io.scif.media.imageioimpl.plugins.jpeg2000.J2KImageWriterCodecLibSpi");
} catch(Throwable t) {
// Ignore it.
}
if(codecLibWriterSPIClass != null) {
Object codecLibWriterSPI =
registry.getServiceProviderByClass(codecLibWriterSPIClass);
if(codecLibWriterSPI != null) {
registry.setOrdering(category, codecLibWriterSPI, this);
}
}
}
示例10: getImageTranscoders
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
/**
* 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 new HashSet().iterator();
}
return new ImageTranscoderIterator(iter);
}
示例11: onRegistration
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
public void onRegistration(ServiceRegistry registry,
Class<?> category) {
if (registered) {
return;
}
registered = true;
}
示例12: onRegistration
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
public void onRegistration(ServiceRegistry registry,
Class<?> category) {
if (registered) {
return;
}
registered = true;
}
示例13: main
import javax.imageio.spi.ServiceRegistry; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
final ArrayList<Class<?>> services = new ArrayList<Class<?>>();
services.add(ImageInputStreamSpi.class);
final ServiceRegistry reg = new ServiceRegistry(services.iterator());
//create new thread for Registerer and Consumer Class
Thread registerer = new Thread(new Registerer(reg));
Thread consumer = new Thread(new Consumer(reg));
//run both registerer and consumer thread parallely
registerer.start();
consumer.start();
}