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


Java ImageInputStream.close方法代码示例

本文整理汇总了Java中javax.imageio.stream.ImageInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java ImageInputStream.close方法的具体用法?Java ImageInputStream.close怎么用?Java ImageInputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.imageio.stream.ImageInputStream的用法示例。


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

示例1: closeQuietly

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
/**
 * Close an {@link ImageInputStream} unconditionally. Equivalent to
 * calling <code>s.close()</code> when <code>s</code> is nonnull.
 * {@link IOException}s are quietly logged, as there is generally
 * nothing that can be done about exceptions on closing.
 *
 * @param s a (possibly <code>null</code>) <code>ImageInputStream</code>
 */
// Why doesn't ImageInputStream implement Closeable? Argh!
public static void closeQuietly(ImageInputStream s) {
  if (s == null) return;

  try {
    s.close();
  }
  catch (IOException e) {
    // ignore

    // Note that ImageInputStreamImpl.close() rather ridiculously throws
    // an IOException if the stream is already closed. This is always done
    // via ImageInputStreamImpl.checkClosed().
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:24,代码来源:IOUtils.java

示例2: main

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    createTestFile();

    ImageInputStream iis = ImageIO.createImageInputStream(file);
    r = ImageIO.getImageReaders(iis).next();
    iis.close();

    for (int i = 0; i < MAX_THREADS; i++) {
        (new ConcurrentReadingTest()).start();
    }

    // wait for started threads
    boolean needWait = true;
    while (needWait) {
        Thread.sleep(100);
        synchronized(lock) {
            needWait = completeCount < MAX_THREADS;
        }
    }
    System.out.println("Test PASSED.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ConcurrentReadingTest.java

示例3: read

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
/**
 * Returns a {@code BufferedImage} as the result of decoding
 * a supplied {@code ImageInputStream} with an
 * {@code ImageReader} chosen automatically from among those
 * currently registered.  If no registered
 * {@code ImageReader} claims to be able to read the stream,
 * {@code null} is returned.
 *
 * <p> Unlike most other methods in this class, this method <em>does</em>
 * close the provided {@code ImageInputStream} after the read
 * operation has completed, unless {@code null} is returned,
 * in which case this method <em>does not</em> close the stream.
 *
 * @param stream an {@code ImageInputStream} to read from.
 *
 * @return a {@code BufferedImage} containing the decoded
 * contents of the input, or {@code null}.
 *
 * @exception IllegalArgumentException if {@code stream} is
 * {@code null}.
 * @exception IOException if an error occurs during reading.
 */
public static BufferedImage read(ImageInputStream stream)
    throws IOException {
    if (stream == null) {
        throw new IllegalArgumentException("stream == null!");
    }

    Iterator<ImageReader> iter = getImageReaders(stream);
    if (!iter.hasNext()) {
        return null;
    }

    ImageReader reader = iter.next();
    ImageReadParam param = reader.getDefaultReadParam();
    reader.setInput(stream, true, true);
    BufferedImage bi;
    try {
        bi = reader.read(0, param);
    } finally {
        reader.dispose();
        stream.close();
    }
    return bi;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:ImageIO.java

示例4: runTest

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    final Context ictx = (Context)ctx;
    final ImageReader reader = ictx.reader;
    final boolean seekForwardOnly = ictx.seekForwardOnly;
    final boolean ignoreMetadata = ictx.ignoreMetadata;
    do {
        try {
            ImageInputStream iis = ictx.createImageInputStream();
            reader.setInput(iis, seekForwardOnly, ignoreMetadata);
            reader.getImageMetadata(0);
            reader.reset();
            iis.close();
            ictx.closeOriginalStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:InputImageTests.java

示例5: runTest

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    final Context ictx = (Context)ctx;
    final ImageReader reader = ictx.reader;
    final boolean seekForwardOnly = ictx.seekForwardOnly;
    final boolean ignoreMetadata = ictx.ignoreMetadata;
    do {
        try {
            ImageInputStream iis = ictx.createImageInputStream();
            reader.setInput(iis, seekForwardOnly, ignoreMetadata);
            reader.read(0);
            reader.reset();
            iis.close();
            ictx.closeOriginalStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:InputImageTests.java

示例6: read

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
@Override
public BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
		throws IOException, HttpMessageNotReadableException {

	ImageInputStream imageInputStream = null;
	ImageReader imageReader = null;
	try {
		imageInputStream = createImageInputStream(inputMessage.getBody());
		MediaType contentType = inputMessage.getHeaders().getContentType();
		Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByMIMEType(contentType.toString());
		if (imageReaders.hasNext()) {
			imageReader = imageReaders.next();
			ImageReadParam irp = imageReader.getDefaultReadParam();
			process(irp);
			imageReader.setInput(imageInputStream, true);
			return imageReader.read(0, irp);
		}
		else {
			throw new HttpMessageNotReadableException(
					"Could not find javax.imageio.ImageReader for Content-Type [" + contentType + "]");
		}
	}
	finally {
		if (imageReader != null) {
			imageReader.dispose();
		}
		if (imageInputStream != null) {
			try {
				imageInputStream.close();
			}
			catch (IOException ex) {
				// ignore
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:BufferedImageHttpMessageConverter.java

示例7: getImageFormatName

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
private static String getImageFormatName(final byte[] imageBytes)
		throws IOException {
	ByteArrayInputStream input = new ByteArrayInputStream(imageBytes);
	ImageInputStream imageInput = ImageIO.createImageInputStream(input);
	Iterator<ImageReader> iterator = ImageIO.getImageReaders(imageInput);
	String imageFormatName = null;
	if (iterator.hasNext()) {
		ImageReader reader = iterator.next();
		imageFormatName = reader.getFormatName().toUpperCase();
	}

	try {
		return imageFormatName;
	} finally {
		if (imageInput != null) {
			imageInput.close();
		}
	}
}
 
开发者ID:marlonwang,项目名称:raven,代码行数:20,代码来源:ImageUtils.java

示例8: main

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    ByteArrayInputStream is =
        new ByteArrayInputStream(new byte[100]);
    ByteArrayOutputStream os =
        new ByteArrayOutputStream();

    String tmp = System.getProperty("java.io.tmpdir", ".");
    System.out.println("tmp: " + tmp);

    // count number of files before test
    ImageIO.setUseCache(true);
    ImageIO.setCacheDirectory(new File(tmp));

    File tmpDir = ImageIO.getCacheDirectory();
    System.out.println("tmpDir is " + tmpDir);
    int fnum_before = tmpDir.list().length;
    System.out.println("Files before test: " + fnum_before);

    ImageInputStream iis =
        ImageIO.createImageInputStream(is);
    System.out.println("iis = " + iis);

    ImageInputStream iis2 =
        ImageIO.createImageInputStream(is);

    ImageOutputStream ios =
        ImageIO.createImageOutputStream(os);
    System.out.println("ios = " + ios);

    ImageOutputStream ios2 =
        ImageIO.createImageOutputStream(os);

    iis2.close();
    ios2.close();
    int fnum_after = tmpDir.list().length;
    System.out.println("Files after test: " + fnum_after);

    if (fnum_before == fnum_after) {
        throw new RuntimeException("Test failed: cache was not used.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:DeleteOnExitTest.java

示例9: read

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
/**
 * Returns a <code>BufferedImage</code> as the result of decoding
 * a supplied <code>File</code> with an <code>ImageReader</code>
 * chosen automatically from among those currently registered.
 * The <code>File</code> is wrapped in an
 * <code>ImageInputStream</code>.  If no registered
 * <code>ImageReader</code> claims to be able to read the
 * resulting stream, <code>null</code> is returned.
 *
 * <p> The current cache settings from <code>getUseCache</code>and
 * <code>getCacheDirectory</code> will be used to control caching in the
 * <code>ImageInputStream</code> that is created.
 *
 * <p> Note that there is no <code>read</code> method that takes a
 * filename as a <code>String</code>; use this method instead after
 * creating a <code>File</code> from the filename.
 *
 * <p> This method does not attempt to locate
 * <code>ImageReader</code>s that can read directly from a
 * <code>File</code>; that may be accomplished using
 * <code>IIORegistry</code> and <code>ImageReaderSpi</code>.
 *
 * @param input a <code>File</code> to read from.
 *
 * @return a <code>BufferedImage</code> containing the decoded
 * contents of the input, or <code>null</code>.
 *
 * @exception IllegalArgumentException if <code>input</code> is
 * <code>null</code>.
 * @exception IOException if an error occurs during reading.
 */
public static BufferedImage read(File input) throws IOException {
    if (input == null) {
        throw new IllegalArgumentException("input == null!");
    }
    if (!input.canRead()) {
        throw new IIOException("Can't read input file!");
    }

    ImageInputStream stream = createImageInputStream(input);
    if (stream == null) {
        throw new IIOException("Can't create an ImageInputStream!");
    }
    BufferedImage bi = read(stream);
    if (bi == null) {
        stream.close();
    }
    return bi;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:50,代码来源:ImageIO.java

示例10: readImage

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
/**
 * Description of the Method
 *
 * @param source Description of the Parameter
 * @return Description of the Return Value
 * @throws IOException Description of the Exception
 */
public static BufferedImage readImage(Object source) throws IOException {
    ImageInputStream stream = ImageIO.createImageInputStream(source);
    if (stream == null) {
        if (source instanceof java.net.URL) {
            return ImageIO.read((java.net.URL) source);
        } else {
            return null;
        }
    }
    Iterator<?> it = ImageIO.getImageReaders(stream);
    if (!it.hasNext()) {
        // bug with firefox 2
        BufferedImage buf = null;
        if (source instanceof File) {
            buf = ImageIO.read((File) source);
        }
        return buf;
    }
    ImageReader reader = (ImageReader) it.next();
    reader.setInput(stream);
    ImageReadParam param = reader.getDefaultReadParam();

    ImageTypeSpecifier typeToUse = null;
    boolean looking = true;
    for (Iterator<?> i = reader.getImageTypes(0); i.hasNext() && looking; ) {
        ImageTypeSpecifier type = (ImageTypeSpecifier) i.next();
        if (type.getColorModel().getColorSpace().getNumComponents() == 1) {
            typeToUse = type;
            looking = false;
        } else if (type.getColorModel().getColorSpace().isCS_sRGB()) {
            typeToUse = type;
            looking = false;
        }
    }
    if (typeToUse != null) {
        param.setDestinationType(typeToUse);
    }

    BufferedImage b = null;
    try {
        b = reader.read(0, param);
    } catch (Exception e) {
        e.printStackTrace();
    }

    reader.dispose();
    stream.close();
    return b;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:57,代码来源:YassUtils.java

示例11: WriteAbortTest

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public WriteAbortTest(String format) throws Exception {
    try {
        System.out.println("Test for format " + format);
        bimg = new BufferedImage(width, heght,
                BufferedImage.TYPE_INT_RGB);

        Graphics2D g = bimg.createGraphics();
        g.setColor(srccolor);
        g.fillRect(0, 0, width, heght);
        g.dispose();

        file = File.createTempFile("src_", "." + format, new File("."));
        ImageInputStream ios = ImageIO.createImageOutputStream(file);

        ImageWriter writer =
                ImageIO.getImageWritersByFormatName(format).next();

        writer.setOutput(ios);
        writer.addIIOWriteProgressListener(this);

        // Abort writing in IIOWriteProgressListener.imageStarted().
        startAbort = true;
        writer.write(bimg);
        startAbort = false;

        // Abort writing in IIOWriteProgressListener.imageProgress().
        progressAbort = true;
        writer.write(bimg);
        progressAbort = false;

        ios.close();
        /*
         * All abort requests from imageStarted,imageProgress
         * from IIOWriteProgressListener should be reached
         * otherwise throw RuntimeException.
         */
        if (!(startAborted
                && progressAborted)) {
            throw new RuntimeException("All IIOWriteProgressListener abort"
                    + " requests are not processed for format "
                    + format);
        }
    } finally {
        Files.delete(file.toPath());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:WriteAbortTest.java

示例12: main

import javax.imageio.stream.ImageInputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    byte[] buffer = new byte[] {(byte)169, (byte)85}; // 10101001 01010101
    InputStream ins = new ByteArrayInputStream(buffer);
    ImageInputStream in = new FileCacheImageInputStream(ins,null);

    if (in.getBitOffset() != 0) {
        throw new RuntimeException("Initial bit offset != 0!");
    }

    int bit0 = in.readBit(); // 1
    if (bit0 != 1) {
        throw new RuntimeException("First bit != 1");
    }
    if (in.getBitOffset() != 1) {
        throw new RuntimeException("Second bit offset != 1");
    }

    long bits1 = in.readBits(5); // 01010 = 10
    if (bits1 != 10) {
        throw new RuntimeException("Bits 1-5 != 10 (= " + bits1 + ")");
    }
    if (in.getBitOffset() != 6) {
        throw new RuntimeException("Third bit offset != 6");
    }

    int bit1 = in.readBit(); // 0
    if (bit1 != 0) {
        throw new RuntimeException("Bit 6 != 0");
    }
    if (in.getBitOffset() != 7) {
        throw new RuntimeException("Third bit offset != 7");
    }

    long bits2 = in.readBits(8); // 10101010 = 170
    if (bits2 != 170) {
        throw new RuntimeException("Bits 7-14 != 170 (= " + bits2 + ")");
    }
    if (in.getBitOffset() != 7) {
        throw new RuntimeException("Fourth bit offset != 7");
    }

    int bit2 = in.readBit(); // 1
    if (bit2 != 1) {
        throw new RuntimeException("Bit 15 != 1");
    }
    if (in.getBitOffset() != 0) {
        throw new RuntimeException("Fifth bit offset != 0");
    }

    in.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:ReadBitsTest.java


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