return an InputStream if successful or throw an exception
488964
private <T> T executeWithRetry(final Callable<ExecuteResult> task,
                                   InputStreamProcessor<T> processor) throws
            CouchException {
        int attempts = 10;
        CouchException lastException = null;
        while (attempts-- > 0) {
            ExecuteResult result = null;
            try {
                result = task.call();
                if (result.stream != null) {
                    // success - process the inputstream
                    try {
                        return processor.processStream(result.stream);
                    } catch (Exception e) {
                        // Error processing the input stream
                        if (attempts > 0) {
                            logger.log(Level.WARNING, "Received an exception during response " +
                                    "stream processing. A retry will be attempted.", e);
                        } else {
                            logger.log(Level.SEVERE, "Response stream processing failed, no " +
                                    "retries remaining.", e);
                            throw e;
                        }
                    } finally {
                        result.stream.close();
                    }
                }
            } catch (Exception e) {
                throw new CouchException("Unexpected exception", e, -1);
            }
            lastException = result.exception;
            if (result.fatal) {
                // fatal exception - don't attempt any more retries
                throw result.exception;
            }
        }
        throw lastException;
    }
802376
protected InputStream getStream(HttpClient httpClient, String url) {
        try {
            HttpEntity entity = get(httpClient, url);
            if (entity == null) return null;
            return entity.getContent();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
156833
public synchronized InputStream getInputStream() throws IOException {
        if (!connected) {
            connect();
        }

        // Nothing to return
        if (responseCode == HTTP_NOT_FOUND) {
            throw new FileNotFoundException(url.toString());
        }
        int length;

        if (inputStream == null) {
            return null;
        }

        // "De-chunk" the output stream
        else if ("chunked".equalsIgnoreCase(getHeaderField("Transfer-Encoding"))) {
            if (!(inputStream instanceof ChunkedInputStream)) {
                inputStream = new ChunkedInputStream(inputStream);
            }
        }

        // Make sure we don't wait forever, if the content-length is known
        else if ((length = getHeaderFieldInt("Content-Length", -1)) >= 0) {
            if (!(inputStream instanceof FixedLengthInputStream)) {
                inputStream = new FixedLengthInputStream(inputStream, length);
            }
        }
        return inputStream;
    }
258333
public InputStream readInputStream()
        throws IOException
    {
        int tag = read();

        switch (tag) {
            case 'N':
                return null;

            case 'B':
            case 'b':
                _isLastChunk = tag == 'B';
                _chunkLength = (read() << 8) + read();
                break;

            default:
                throw expect("inputStream", tag);
        }

        return new InputStream() {
            boolean _isClosed = false;

            public int read()
                throws IOException
            {
                if (_isClosed || _is == null)
                    return -1;

                int ch = parseByte();
                if (ch < 0)
                    _isClosed = true;

                return ch;
            }

            public int read(byte[] buffer, int offset, int length)
                throws IOException
            {
                if (_isClosed || _is == null)
                    return -1;

                int len = HessianInput.this.read(buffer, offset, length);
                if (len < 0)
                    _isClosed = true;

                return len;
            }

            public void close()
                throws IOException
            {
                while (read() >= 0) {
                }

                _isClosed = true;
            }
        };
    }
400835
@Override
    public InputStream getInputStream() throws IOException {
        try {
            InputStream result = entry.adapt(InputStream.class);
            if (result == null) {
                throw new IOException("The entry did not supply an input stream: " + entry);
            }
            return result;
        } catch (UnableToAdaptException e) {
            throw new IOException("Unable to get input stream for entry: " + entry.getPath() + '/' + entry.getName(), e);
        }
    }
674055
public InputStream getData() {
    if (data != null) {
      return new ByteArrayInputStream(data);
    } else if (dataStream != null) {
      return dataStream;
    } else {
      throw new IllegalStateException("Either the byte[] or the stream mustn't be null at this point.");
    }
  }
56673
private static InputStream getInputStream(final Socket socket) throws IOException {
    final InputStream delegate = socket.getInputStream();
    return new InputStream() {
      @Override public void close() throws IOException {
        synchronized (socket) {
          socket.shutdownInput();
          if (socket.isOutputShutdown()) {
            socket.close();
          }
        }
      }
      
      // Boring delegates from here on down
      @Override public int read() throws IOException {
        return delegate.read();
      }
      
      @Override public int read(byte[] b) throws IOException {
        return delegate.read(b);
      }
      
      @Override public int read(byte[] b, int off, int len) throws IOException {
        return delegate.read(b, off, len);
      }
      
      @Override public long skip(long n) throws IOException {
        return delegate.skip(n);
      }
      
      @Override public int available() throws IOException {
        return delegate.available();
      }
      
      @Override public void mark(int readlimit) {
        delegate.mark(readlimit);
      }
      
      @Override public void reset() throws IOException {
        delegate.reset();
      }
      
      @Override public boolean markSupported() {
        return delegate.markSupported();
      }
    };
  }
562431
protected synchronized InputStream getInputStream() throws IOException {
        if (isClosedOrPending()) {
            throw new IOException("Socket Closed");
        }
        if (shut_rd) {
            throw new IOException("Socket input is shutdown");
        }
        if (socketInputStream == null) {
            socketInputStream = new SocketInputStream(this);
        }
        return socketInputStream;
    }
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;
        }
    }
319618
public InputStreamReader getFileStream(String filename, String encoding)
			throws NoSuchPathException, UnmarshalException{
		try {
			return new InputStreamReader(new FileInputStream(filename), encoding);
		} catch (FileNotFoundException e) {
			throw new NoSuchPathException(e);
		} catch (UnsupportedEncodingException e){
			throw new UnmarshalException(e);
		}
	}
779869
private InputStream asInputStream() {
        InputStream inputStream = classLoader.getResourceAsStream(path);
        if (inputStream == null) {
            throw new RuntimeException("File '" + path + "' was not found.");
        }
        return inputStream;
    }
688416
public T get() throws Exception {
    waitForPromiseSuccess();

    if (response != null) {
      return response;
    } else {
      if (this.exception instanceof IOException) {
        throw (IOException) this.exception;
      } else if (this.exception instanceof io.netty.handler.timeout.TimeoutException) {
        throw new TimeoutException();
      } else {
        throw new IOException(this.exception);
      }
    }
  }
155344
public static InputStream getRequestInputStream(ExternalContext ec)
            throws IOException
    {
        RequestType type = getRequestType(ec);
        if (type.isRequestFromClient())
        {
            Object req = ec.getRequest();
            if (type.isPortlet())
            {
                return (InputStream) _runMethod(req, "getPortletInputStream");
            }
            else
            {
                return ((ServletRequest) ec.getRequest()).getInputStream();
            }
        }

        return null;
    }
1017394
@Override
    public InputStream getInputStream() throws IOException {
	if (barr == null) {
	    barr = IOUtil.toBytes(url.openStream());
	}
	return new ByteArrayInputStream(barr);
    }
1091230
public void process(InputStream is) throws Exception
   {
      readHeader(is);
      readVersion(is);
      readTableData(readTableHeaders(is), is);
   }
192808
public InputStream getAsStream() throws ProponoException {
        if (getContents() != null && !getContents().isEmpty()) {
            final Content c = getContents().get(0);
            if (c.getSrc() != null) {
                return getResourceAsStream();
            } else if (inputStream != null) {
                return inputStream;
            } else if (bytes != null) {
                return new ByteArrayInputStream(bytes);
            } else {
                throw new ProponoException("ERROR: no src URI or binary data to return");
            }
        } else {
            throw new ProponoException("ERROR: no content found in entry");
        }
    }
40261
private static InputStream inputStreamFromJar(String relativePathPrefix, String src) throws IOException {
        String absoluteName = getAbsoluteName(relativePathPrefix, src);
        return XmlUtils.class.getResourceAsStream(absoluteName);
    }