當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。