当前位置: 首页>>代码示例>>Java>>正文


Java MemoryCacheImageInputStream类代码示例

本文整理汇总了Java中javax.imageio.stream.MemoryCacheImageInputStream的典型用法代码示例。如果您正苦于以下问题:Java MemoryCacheImageInputStream类的具体用法?Java MemoryCacheImageInputStream怎么用?Java MemoryCacheImageInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MemoryCacheImageInputStream类属于javax.imageio.stream包,在下文中一共展示了MemoryCacheImageInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
/**
 * Gets the size of an image.
 *
 * @param name the image name
 * @param in the input stream
 * @return the size of the image
 *
 * @throws BrokenImageException if the image is faulty
 * @throws UnrecognizedImageTypeException if the image type is unknown
 * @throws IOException if reading the image goes wrong
 */
public Dimension run(String name, InputStream in) throws IOException {
  final ImageInputStream stream = new MemoryCacheImageInputStream(in);

  final Iterator<ImageReader> i = ImageIO.getImageReaders(stream);
  if (!i.hasNext()) throw new UnrecognizedImageTypeException(name);

  final ImageReader reader = i.next();
  try {
    reader.setInput(stream);
    return new Dimension(reader.getWidth(0), reader.getHeight(0));
  }
  finally {
    reader.dispose();
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:27,代码来源:ImageIOImageLoader.java

示例2: createInputStreamInstance

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:InputStreamImageInputStreamSpi.java

示例3: main

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:GetElementsByTagNameTest.java

示例4: readBinaryMaskVolume

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
/**
* readBinaryMaskVolume() method
* Reads volume-mask from a Binary file (1-byte character array)
*/
static public void readBinaryMaskVolume() {
	maskVolumeBoolean = new boolean [numberOfPValues];
	FileInputStream fis;
	BufferedInputStream bis;
	
	try { 
		fis = new FileInputStream(maskInputVolume);
		bis = new BufferedInputStream(fis);
		MemoryCacheImageInputStream mciis = new MemoryCacheImageInputStream(bis);
		setByteOrder(mciis, byteorder);
		
		for (int i=0; i < numberOfPValues; i++) {
			if (mciis.readUnsignedByte()>0) maskVolumeBoolean[i]=true;
			else maskVolumeBoolean[i]=false;
		}
		
	} catch (Exception e) {
		System.out.println("Error in readBinaryData(): "+e);
	}
	return;
}
 
开发者ID:SOCR,项目名称:HTML5_WebSite,代码行数:26,代码来源:Test_FDR.java

示例5: copyJpegMetaData

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
/**
 * Copy jpeg meta data (exif) from source to dest and save it to out
 *
 * @param source
 * @param dest
 * @param out
 * @throws IOException
 */
public static void copyJpegMetaData(InputStream source, InputStream dest, ImageOutputStream out) throws IOException {
    // Read meta data from src image
    Iterator iter = ImageIO.getImageReadersByFormatName("jpeg");
    ImageReader reader=(ImageReader) iter.next();
    ImageInputStream iis = new MemoryCacheImageInputStream(source);
    reader.setInput(iis);
    IIOMetadata metadata = reader.getImageMetadata(0);
    iis.close();
    // Read dest image
    ImageInputStream outIis = new MemoryCacheImageInputStream(dest);
    reader.setInput(outIis);
    IIOImage image = reader.readAll(0,null);
    image.setMetadata(metadata);
    outIis.close();
    // write dest image
    iter = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter writer=(ImageWriter) iter.next();
    writer.setOutput(out);
    writer.write(image);
}
 
开发者ID:mortennobel,项目名称:java-image-scaling,代码行数:29,代码来源:ImageUtils.java

示例6: readHeader

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
/** 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);
    }
}
 
开发者ID:pojosontheweb,项目名称:selenium-utils,代码行数:23,代码来源:MJPGImageReader.java

示例7: readHeader

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
/** 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);
    }
}
 
开发者ID:pojosontheweb,项目名称:selenium-utils,代码行数:22,代码来源:MJPGImageReader.java

示例8: isAcceptedImageFormat

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
private static boolean isAcceptedImageFormat(final byte[] tileData)
{
    if(tileData == null)
    {
        return false;
    }

    try(final ByteArrayInputStream        byteArray  = new ByteArrayInputStream(tileData);
        final MemoryCacheImageInputStream cacheImage = new MemoryCacheImageInputStream(byteArray))
    {
        return TilesVerifier.canReadImage(pngImageReaders, cacheImage) || TilesVerifier.canReadImage(jpegImageReaders, cacheImage);
    }
    catch(final IOException ignored)
    {
        return false;
    }
}
 
开发者ID:GitHubRGI,项目名称:swagd,代码行数:18,代码来源:TilesVerifier.java

示例9: checkJpegMaskRender

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
@Test
public void checkJpegMaskRender() throws IOException, URISyntaxException {
    NitfRenderer renderer = new NitfRenderer();

    // Mock up a render source
    ImageSegment mockImageSegment = Mockito.mock(ImageSegment.class);
    Mockito.when(mockImageSegment.getImageCompression()).thenReturn(ImageCompression.JPEGMASK);
    Mockito.when(mockImageSegment.getNumberOfBlocksPerRow()).thenReturn(2);
    Mockito.when(mockImageSegment.getNumberOfBlocksPerColumn()).thenReturn(3);
    Mockito.when(mockImageSegment.getNumberOfPixelsPerBlockHorizontal()).thenReturn(256L);
    Mockito.when(mockImageSegment.getNumberOfPixelsPerBlockVertical()).thenReturn(256L);
    Mockito.when(mockImageSegment.getNumBands()).thenReturn(1);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(parseHexBinary("00000044000400000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000"));
    FileInputStream fis = new FileInputStream(new File(getClass().getResource("/256by256.jpg").toURI()));
    byte[] lastBlock = new byte[fis.available()];
    fis.read(lastBlock);
    baos.write(lastBlock, 0, lastBlock.length);
    ImageInputStream iis = new MemoryCacheImageInputStream(new ByteArrayInputStream(baos.toByteArray()));
    Mockito.when(mockImageSegment.getData()).thenReturn(iis);
    BufferedImage imgAGRB = new BufferedImage((int) (mockImageSegment.getNumberOfBlocksPerRow() * mockImageSegment.getNumberOfPixelsPerBlockHorizontal()),
            (int) (mockImageSegment.getNumberOfBlocksPerColumn() * mockImageSegment.getNumberOfPixelsPerBlockVertical()),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D targetGraphic = imgAGRB.createGraphics();
    renderer.render(mockImageSegment, targetGraphic);
}
 
开发者ID:codice,项目名称:imaging-nitf,代码行数:27,代码来源:JpegTest.java

示例10: checkJpegMaskRender2

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
@Test
public void checkJpegMaskRender2() throws IOException, URISyntaxException {
    NitfRenderer renderer = new NitfRenderer();

    // Mock up a render source
    ImageSegment mockImageSegment = Mockito.mock(ImageSegment.class);
    Mockito.when(mockImageSegment.getImageCompression()).thenReturn(ImageCompression.JPEGMASK);
    Mockito.when(mockImageSegment.getNumberOfBlocksPerRow()).thenReturn(3);
    Mockito.when(mockImageSegment.getNumberOfBlocksPerColumn()).thenReturn(2);
    Mockito.when(mockImageSegment.getNumberOfPixelsPerBlockHorizontal()).thenReturn(256L);
    Mockito.when(mockImageSegment.getNumberOfPixelsPerBlockVertical()).thenReturn(256L);
    Mockito.when(mockImageSegment.getNumBands()).thenReturn(1);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.write(parseHexBinary("00000044000400000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000"));
    FileInputStream fis = new FileInputStream(new File(getClass().getResource("/256by256.jpg").toURI()));
    byte[] lastBlock = new byte[fis.available()];
    fis.read(lastBlock);
    baos.write(lastBlock, 0, lastBlock.length);
    ImageInputStream iis = new MemoryCacheImageInputStream(new ByteArrayInputStream(baos.toByteArray()));
    Mockito.when(mockImageSegment.getData()).thenReturn(iis);
    BufferedImage imgAGRB = new BufferedImage((int) (mockImageSegment.getNumberOfBlocksPerRow() * mockImageSegment.getNumberOfPixelsPerBlockHorizontal()),
            (int) (mockImageSegment.getNumberOfBlocksPerColumn() * mockImageSegment.getNumberOfPixelsPerBlockVertical()),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D targetGraphic = imgAGRB.createGraphics();
    renderer.render(mockImageSegment, targetGraphic);
}
 
开发者ID:codice,项目名称:imaging-nitf,代码行数:27,代码来源:JpegTest.java

示例11: handleGraphicSegment

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public final void handleGraphicSegment(final NitfReader reader, final long dataLength) throws NitfFormatException {
    GraphicSegmentParser graphicSegmentParser = new GraphicSegmentParser();
    GraphicSegment graphicSegment = graphicSegmentParser.parse(reader, this, dataLength);
    if ((segmentsToExtract & GRAPHIC_DATA) == GRAPHIC_DATA) {
        if (dataLength > 0) {
            // TODO: [IMG-77] this implementation probably should have a file-backed option
            byte[] bytes = reader.readBytesRaw((int) dataLength);
            graphicSegment.setData(new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)));
        }
    } else {
        if (dataLength > 0) {
            reader.skip(dataLength);
        }
    }
    nitfStorage.getGraphicSegments().add(graphicSegment);
}
 
开发者ID:codice,项目名称:imaging-nitf,代码行数:21,代码来源:SlottedParseStrategy.java

示例12: handleSymbolSegment

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public final void handleSymbolSegment(final NitfReader reader, final long dataLength) throws NitfFormatException {
    SymbolSegmentParser symbolSegmentParser = new SymbolSegmentParser();
    SymbolSegment symbolSegment = symbolSegmentParser.parse(reader, this, dataLength);
    if ((segmentsToExtract & SYMBOL_DATA) == SYMBOL_DATA) {
        if (dataLength > 0) {
            byte[] bytes = reader.readBytesRaw((int) dataLength);
            symbolSegment.setData(new MemoryCacheImageInputStream(new ByteArrayInputStream(bytes)));
        }
    } else {
        if (dataLength > 0) {
            reader.skip(dataLength);
        }
    }
    nitfStorage.getSymbolSegments().add(symbolSegment);
}
 
开发者ID:codice,项目名称:imaging-nitf,代码行数:20,代码来源:SlottedParseStrategy.java

示例13: checkBadWriter

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
@Test
public void checkBadWriter() throws NitfFormatException {
    NitfReader reader = new NitfInputStreamReader(new BufferedInputStream(getInputStream("/WithBE.ntf")));
    SlottedParseStrategy parseStrategy = new SlottedParseStrategy(SlottedParseStrategy.ALL_SEGMENT_DATA);
    HeapStrategyConfiguration heapStrategyConfiguration = new HeapStrategyConfiguration(length -> length > ABOUT_100K);
    HeapStrategy<ImageInputStream> imageDataStrategy = new ConfigurableHeapStrategy<>(heapStrategyConfiguration,
            file -> new FileImageInputStream(file), is -> new MemoryCacheImageInputStream(is));
    parseStrategy.setImageHeapStrategy(imageDataStrategy);
    NitfParser.parse(reader, parseStrategy);

    // Introduce deliberate issue
    // Introduce deliberate issue
    ImageSegment imageSegment = parseStrategy.getDataSource().getImageSegments().get(0);
    TargetId originalTargetId = imageSegment.getImageTargetId();
    TargetIdImpl newTargetId = new TargetIdImpl();
    newTargetId.setBasicEncyclopediaNumber(originalTargetId.getBasicEncyclopediaNumber());
    newTargetId.setOSuffix(originalTargetId.getOSuffix());
    newTargetId.setCountryCode(null);
    imageSegment.setImageTargetId(newTargetId);

    NitfWriter writer = new NitfFileWriter(parseStrategy.getDataSource(), "checkBadWriter.ntf");
    assertEquals(0, LOGGER.getLoggingEvents().size());
    writer.write();
    assertThat(LOGGER.getLoggingEvents(), is(Arrays.asList(LoggingEvent.error("Could not write", "Cannot generate string target identifier with null country code"))));
}
 
开发者ID:codice,项目名称:imaging-nitf,代码行数:26,代码来源:BasicWriterTest.java

示例14: checkBadStreamWriter

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
@Test
public void checkBadStreamWriter() throws NitfFormatException, FileNotFoundException {
    OutputStream outputStream = new FileOutputStream("checkBadStreamWriter.ntf");
    NitfReader reader = new NitfInputStreamReader(new BufferedInputStream(getInputStream("/WithBE.ntf")));
    SlottedParseStrategy parseStrategy = new SlottedParseStrategy(SlottedParseStrategy.ALL_SEGMENT_DATA);
    HeapStrategyConfiguration heapStrategyConfiguration = new HeapStrategyConfiguration(length -> length > ABOUT_100K);
    HeapStrategy<ImageInputStream> imageDataStrategy = new ConfigurableHeapStrategy<>(heapStrategyConfiguration,
            file -> new FileImageInputStream(file), is -> new MemoryCacheImageInputStream(is));
    parseStrategy.setImageHeapStrategy(imageDataStrategy);
    NitfParser.parse(reader, parseStrategy);

    // Introduce deliberate issue
    ImageSegment imageSegment = parseStrategy.getDataSource().getImageSegments().get(0);
    TargetId originalTargetId = imageSegment.getImageTargetId();
    TargetIdImpl newTargetId = new TargetIdImpl();
    newTargetId.setBasicEncyclopediaNumber(originalTargetId.getBasicEncyclopediaNumber());
    newTargetId.setOSuffix(originalTargetId.getOSuffix());
    newTargetId.setCountryCode(null);
    imageSegment.setImageTargetId(newTargetId);

    NitfWriter writer = new NitfOutputStreamWriter(parseStrategy.getDataSource(), outputStream);
    assertEquals(0, LOGGER.getLoggingEvents().size());
    writer.write();
    assertThat(LOGGER.getLoggingEvents(), is(Arrays.asList(LoggingEvent.error("Could not write", "Cannot generate string target identifier with null country code"))));
}
 
开发者ID:codice,项目名称:imaging-nitf,代码行数:26,代码来源:BasicWriterTest.java

示例15: roundTripFile

import javax.imageio.stream.MemoryCacheImageInputStream; //导入依赖的package包/类
protected void roundTripFile(String sourceFileName) throws URISyntaxException, NitfFormatException, IOException {
    String outputFile = FilenameUtils.getName(sourceFileName);
    NitfReader reader = new NitfInputStreamReader(new BufferedInputStream(getInputStream(sourceFileName)));
    SlottedParseStrategy parseStrategy = new SlottedParseStrategy(SlottedParseStrategy.ALL_SEGMENT_DATA);
    HeapStrategyConfiguration heapStrategyConfiguration = new HeapStrategyConfiguration(length -> length > ABOUT_100K);
    HeapStrategy<ImageInputStream> imageDataStrategy = new ConfigurableHeapStrategy<>(heapStrategyConfiguration,
            file -> new FileImageInputStream(file), is -> new MemoryCacheImageInputStream(is));
    parseStrategy.setImageHeapStrategy(imageDataStrategy);

    NitfParser.parse(reader, parseStrategy);
    NitfWriter writer = new NitfFileWriter(parseStrategy.getDataSource(), outputFile);
    writer.write();
    assertTrue(FileUtils.contentEquals(new File(getClass().getResource(sourceFileName).toURI()), new File(outputFile)));
    assertTrue(new File(outputFile).delete());

    // Do the same again, but with stream writing
    try (
        OutputStream outputStream = new FileOutputStream(outputFile)) {
        writer = new NitfOutputStreamWriter(parseStrategy.getDataSource(), outputStream);
        writer.write();
        assertTrue(FileUtils.contentEquals(new File(getClass().getResource(sourceFileName).toURI()), new File(outputFile)));
    }
    assertTrue(new File(outputFile).delete());
}
 
开发者ID:codice,项目名称:imaging-nitf,代码行数:25,代码来源:AbstractWriterTest.java


注:本文中的javax.imageio.stream.MemoryCacheImageInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。