Get an image as a stream. Callers must be sure to close the stream when they are done with it.

@deprecated
@see PhotosInterface#getImageAsStream(Photo, int)
@param suffix
The suffix
@return The InputStream
@throws IOException
198646
@Deprecated
    private InputStream getImageAsStream(String suffix) throws IOException {
        StringBuffer buffer = getBaseImageUrl();
        buffer.append(suffix);
        return _getImageAsStream(buffer.toString());
    }
781063
public ImageDownloadResult getImageDownloadResult() throws Exception {
		Future<ImageDownloadResult> future = pool.poll();
		if (future == null) { // no completed tasks in the pool
			return null;
		} else {
			try {
				ImageDownloadResult imdr = future.get();
				return imdr;
			} catch (Exception e) {
				throw e;
			} finally {
				// in any case (Exception or not) the numPendingTask should be reduced
				numPendingTasks--;
			}
		}
	}
1205773
public  InputStream getInputStream(File f)
	throws IOException
	{

		// use the magic numbers to determine the compression type,
		// use file extension only as 2nd choice

		int magic = 0;


		InputStream test = getInputStreamFromFile(f);
		magic = getMagicNumber(test);
		test.close();


		InputStream inputStream = null;

		String fileName = f.getName();

		if (magic == UncompressInputStream.LZW_MAGIC ) {
			// a Z compressed file
			return openCompressedFile(f);
		}

		else if (magic == GZIP_MAGIC ) {
			return openGZIPFile(f);
		}

		else if ( fileName.endsWith(".gz")) {
			return openGZIPFile(f);
		}

		else if ( fileName.endsWith(".zip")){

			ZipFile zipfile = new ZipFile(f);

			// stream to first entry is returned ...
			ZipEntry entry;
			Enumeration<? extends ZipEntry> e = zipfile.entries();
			if ( e.hasMoreElements()){
				entry = e.nextElement();
				inputStream = zipfile.getInputStream(entry);
			} else {
				throw new IOException ("Zip file has no entries");
			}

		}

		else if ( fileName.endsWith(".jar")) {

			JarFile jarFile = new JarFile(f);

			// stream to first entry is returned
			JarEntry entry;
			Enumeration<JarEntry> e = jarFile.entries();
			if ( e.hasMoreElements()){
				entry = e.nextElement();
				inputStream = jarFile.getInputStream(entry);
			} else {
				throw new IOException ("Jar file has no entries");
			}
		}

		else if ( fileName.endsWith(".Z")) {
			// unix compressed
			return openCompressedFile(f);

		}

		else {

			// no particular extension found, assume that it is an uncompressed file
			inputStream = getInputStreamFromFile(f);
		}

		return inputStream;
	}
227437
public static BufferedImage loadImage (InputStream iis, boolean useFastIO)
        throws IOException
    {
        if (iis == null) {
            return null;
        } else if (useFastIO) {
            return FastImageIO.read(iis);
        }
        return ImageIO.read(iis);
    }
93328
public BufferedImage loadImage (String path)
        throws IOException
    {
        return _bundle.getImageResource(path, path.endsWith(FastImageIO.FILE_SUFFIX));
    }
96218
protected static String sniffContentType(InputStream inputStream)
            throws IOException {
        if (inputStream == null)
            return null;
        byte[] bytes = new byte[8];
        inputStream.read(bytes);
        String[] hex = new String[8];
        String hexString = "";
        for (int i = 0; i < 8; i++) {
            hex[i] = getHexValue(bytes[i]);
            hexString += hex[i] + " ";
        }
        String prefix = new String(bytes);
        if (prefix.startsWith("GIF87") || prefix.startsWith("GIF89"))
            return "image/gif";
        if (hex[0].equals("ff") && hex[1].equals("d8"))
            return "image/jpeg";
        if (hex[0].equals("42") && hex[1].equals("4d"))
            return "image/bmp";
        if (hex[0].equals("00") && hex[1].equals("00") && hex[2].equals("01")
                && hex[3].equals("00"))
            return "image/vnd.microsoft.icon";
        if (hexString.trim().equals("89 50 4e 47 0d 0a 1a 0a"))
            return "image/png";
        return null;
    }
1017394
@Override
    public InputStream getInputStream() throws IOException {
	if (barr == null) {
	    barr = IOUtil.toBytes(url.openStream());
	}
	return new ByteArrayInputStream(barr);
    }
794365
public String addMpNewsImage(InputStream inputStream, String fileName) {
        String url = WxEndpoint.get("url.mpnews.image.upload");
        String response = wxClient.post(url, inputStream, fileName);

        Map<String, Object> result = JsonMapper.defaultMapper().json2Map(response);
        if (result.containsKey("url")) {
            return result.get("url").toString();
        } else {
            logger.warn("mpnews image upload failed: {}", response);
            throw new WxRuntimeException(999, response);
        }
    }
977678
public static ImageOutputStream getImageOutputStream(File outFile) throws IORuntimeException {
		try {
			return ImageIO.createImageOutputStream(outFile);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
710243
@Deprecated
    private BufferedImage getOriginalImage(String suffix) throws IOException, FlickrException {
        StringBuffer buffer = getOriginalBaseImageUrl();
        buffer.append(suffix);
        return _getImage(buffer.toString());
    }
1304747
@Override
    public InputStream get(String path) throws IOException {
        InputStream stream = _cl.getResourceAsStream(rewritePath(path));
        if (stream == null) {
            throw new FileNotFoundException("Not found in classpath: " + path);
        } else {
            return stream;
        }
    }
544025
public InputStream getInputStream()
    {
        InputStream stream=null;
        try
        {
            stream=this.commPort.getInputStream();
        }
        catch(IOException exception)
        {
            throw new FaxException("Unable to extract input stream.",exception);
        }
        
        return stream;
    }
1346201
static InputStream getCachedImageStream(URI url, Context context) {
        InputStream imageStream = null;
        if (url != null) {
            if (isCDNURL(url)) {
                try {
                    FileLruCache cache = getCache(context);
                    imageStream = cache.get(url.toString());
                } catch (IOException e) {
                    Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, e.toString());
                }
            }
        }

        return imageStream;
    }
1336070
public static Image getInstance(URL url) throws BadElementException,
			MalformedURLException, IOException {
		InputStream is = null;
		try {
			is = url.openStream();
			int c1 = is.read();
			int c2 = is.read();
			int c3 = is.read();
			int c4 = is.read();
			// jbig2
			int c5 = is.read();
			int c6 = is.read();
			int c7 = is.read();
			int c8 = is.read();
			is.close();

			is = null;
			if (c1 == 'G' && c2 == 'I' && c3 == 'F') {
				GifImage gif = new GifImage(url);
				Image img = gif.getImage(1);
				return img;
			}
			if (c1 == 0xFF && c2 == 0xD8) {
				return new Jpeg(url);
			}
			if (c1 == 0x00 && c2 == 0x00 && c3 == 0x00 && c4 == 0x0c) {
				return new Jpeg2000(url);
			}
			if (c1 == 0xff && c2 == 0x4f && c3 == 0xff && c4 == 0x51) {
				return new Jpeg2000(url);
			}
			if (c1 == PngImage.PNGID[0] && c2 == PngImage.PNGID[1]
					&& c3 == PngImage.PNGID[2] && c4 == PngImage.PNGID[3]) {
				return PngImage.getImage(url);
			}
			if (c1 == 0xD7 && c2 == 0xCD) {
				return new ImgWMF(url);
			}
			if (c1 == 'B' && c2 == 'M') {
				return  BmpImage.getImage(url);
			}
			if ((c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42)
					|| (c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0)) {
				RandomAccessFileOrArray ra = null;
				try {
					if (url.getProtocol().equals("file")) {
						String file = url.getFile();
                        file = Utilities.unEscapeURL(file);
						ra = new RandomAccessFileOrArray(file);
					} else
						ra = new RandomAccessFileOrArray(url);
					Image img = TiffImage.getTiffImage(ra, 1);
					img.url = url;
					return img;
				} finally {
					if (ra != null)
						ra.close();
				}

			}
			if ( c1 == 0x97 && c2 == 'J' && c3 == 'B' && c4 == '2' &&
					c5 == '\r' && c6 == '\n' && c7 == 0x1a && c8 == '\n' ) {
				RandomAccessFileOrArray ra = null;
				try {
					if (url.getProtocol().equals("file")) {
						String file = url.getFile();
						file = Utilities.unEscapeURL(file);
			            ra = new RandomAccessFileOrArray(file);
					} else
						ra = new RandomAccessFileOrArray(url);
					Image img = JBIG2Image.getJbig2Image(ra, 1);
					img.url = url;
					return img;
				} finally {
						if (ra != null)
							ra.close();
				}
			}
			throw new IOException(url.toString()
					+ " is not a recognized imageformat.");
		} finally {
			if (is != null) {
				is.close();
			}
		}
	}
70517
public void flush() throws IOException {
        String outputType = getOutputContentType();

        // Force transcoding, if no other filtering is done
        if (outputType != null && !outputType.equals(originalContentType)) {
            getImage();
        }

        if (image != null) {
            Iterator writers = ImageIO.getImageWritersByMIMEType(outputType);
            if (writers.hasNext()) {
                super.setContentType(outputType);
                OutputStream out = super.getOutputStream();
                try {
                    ImageWriter writer = (ImageWriter) writers.next();
                    try {
                        ImageWriteParam param = writer.getDefaultWriteParam();
    ///////////////////
    // POST-PROCESS
                        // For known formats that don't support transparency, convert to opaque
                        if (isNonAlphaFormat(outputType) && image.getColorModel().getTransparency() != Transparency.OPAQUE) {
                            image = ImageUtil.toBuffered(image, BufferedImage.TYPE_INT_RGB);
                        }

                        Float requestQuality = (Float) originalRequest.getAttribute(ImageServletResponse.ATTRIB_OUTPUT_QUALITY);

                        // The default JPEG quality is not good enough, so always adjust compression/quality
                        if ((requestQuality != null || "jpeg".equalsIgnoreCase(getFormatNameSafe(writer))) && param.canWriteCompressed()) {
                            // TODO: See http://blog.apokalyptik.com/2009/09/16/quality-time-with-your-jpegs/ for better adjusting the (default) JPEG quality
                            // OR: Use the metadata of the original image

                            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);

                            // WORKAROUND: Known bug in GIFImageWriter in certain JDK versions, compression type is not set by default
                            if (param.getCompressionTypes() != null && param.getCompressionType() == null) {
                                param.setCompressionType(param.getCompressionTypes()[0]); // Just choose any, to keep param happy
                            }

                            param.setCompressionQuality(requestQuality != null ? requestQuality : 0.8f);
                        }

                        if ("gif".equalsIgnoreCase(getFormatNameSafe(writer)) && !(image.getColorModel() instanceof IndexColorModel) 
                                /*&& image.getColorModel().getTransparency() != Transparency.OPAQUE*/) {
                            // WORKAROUND: Bug in GIFImageWriter may throw NPE if transparent pixels
                            // See: http://bugs.sun.com/view_bug.do?bug_id=6287936
                            image = ImageUtil.createIndexed(
                                    ImageUtil.toBuffered(image), 256, null,
                                    (image.getColorModel().getTransparency() == Transparency.OPAQUE ? ImageUtil.TRANSPARENCY_OPAQUE : ImageUtil.TRANSPARENCY_BITMASK) | ImageUtil.DITHER_DIFFUSION_ALTSCANS
                            );
                        }
    //////////////////
                        ImageOutputStream stream = ImageIO.createImageOutputStream(out);

                        writer.setOutput(stream);
                        try {
                            writer.write(null, new IIOImage(image, null, null), param);
                        }
                        finally {
                            stream.close();
                        }
                    }
                    finally {
                        writer.dispose();
                    }
                }
                finally {
                    out.flush();
                }
            }
            else {
                context.log("ERROR: No writer for content-type: " + outputType);
                throw new IIOException("Unable to transcode image: No suitable image writer found (content-type: " + outputType + ").");
            }
        }
        else {
            super.setContentType(originalContentType);

            ServletOutputStream out = super.getOutputStream();

            try {
                if (bufferedOut != null) {
                    bufferedOut.writeTo(out);
                }
            }
            finally {
                out.flush();
            }
        }
    }
1286997
public InputStream getInputStream() throws IOException, RepositoryException
   {
      final PipedInputStream pin = new PipedInputStream();
      final PipedOutputStream pout = new PipedOutputStream(pin);

      try
      {

         new Thread()
         {

            /*
             * (non-Javadoc)
             * 
             * @see java.lang.Thread#run()
             */
            public void run()
            {
               try
               {
                  if (isSystem)
                  {
                     node.getSession().exportSystemView(node.getPath(), pout, false, false);
                  }
                  else
                  {
                     node.getSession().exportDocumentView(node.getPath(), pout, false, false);
                  }
               }
               catch (Exception e)
               {
                  if (LOG.isTraceEnabled())
                  {
                     LOG.trace("An exception occurred: " + e.getMessage());
                  }
               }
               finally
               {
                  try
                  {
                     pout.flush();
                     pout.close();
                  }
                  catch (Exception e)
                  {
                     if (LOG.isTraceEnabled())
                     {
                        LOG.trace("An exception occurred: " + e.getMessage());
                     }
                  }
               }
            }

         }.start();

         return pin;
      }
      catch (Exception e)
      {
         LOG.error(e.getLocalizedMessage(), e);
         throw new IOException("can't get input stream", e);
      }

   }
129873
protected <T extends ImageBase> ImageType<T> getImageType( int which ) {
		synchronized ( inputStreams ) {
			return inputStreams.get(which).imageType;
		}
	}