Creates a {@link CloseableIterable} from a standard {@link Stream}.
19967
public static <T> CloseableIterator<T> fromStream(Stream<T> stream) {
        return wrap(stream.iterator(), stream);
    }
579903
public static <T> PeekingCloseableIterator<T> peekingIterator(final CloseableIterator<T> iterator) {
        final PeekingIterator<T> peeking = Iterators.peekingIterator(iterator);
        return new PeekingCloseableIterator<T>() {
            @Override
            public void close() {
                iterator.close();
            }

            @Override
            public T peek() {
                return peeking.peek();
            }

            @Override
            public T next() {
                return peeking.next();
            }

            @Override
            public void remove() {
                peeking.remove();
            }

            @Override
            public boolean hasNext() {
                return peeking.hasNext();
            }
        };
    }
613340
public static Closeable closeableFrom(@WillNotClose @Nullable final Clob clob) {
        return closeableFrom(clob, Clob::free);
    }
362569
public static <T> CloseableReference<T> closeableFrom(@WillNotClose @Nullable final T reference, Closer<T> closer) {
        return new CloseableReference<>(reference, closer);
    }
625496
public static <T> CloseableIterable<T> filter(final CloseableIterable<T> iterable, final Predicate<? super T> filter) {
        return wrap(Iterables.filter(iterable, filter::test), iterable);
    }
1120214
public static <F, T> CloseableIterable<T> transform(final CloseableIterable<F> iterable, final Function<? super F, ? extends T> function) {
        return wrap(Iterables.transform(iterable, function::apply), iterable);
    }
1089786
public static void safelyClose(OutputStream stream) {
		if(stream != null) {
			try {
				stream.close();
			} catch(IOException e) {
				logger.warn("error closing internal output stream, this may lead to a stream leak", e);
			}
		}
	}
1166121
public static <T> Collection<T> collect(Iterable<T> stream) {
        LinkedList<T> collection = new LinkedList<>();
        for (T e : stream) {
            collection.add(e);
        }
        return collection;
    }
297444
static Reader asReader(final Readable readable) {
    checkNotNull(readable);
    if (readable instanceof Reader) {
      return (Reader) readable;
    }
    return new Reader() {
      @Override
      public int read(char[] cbuf, int off, int len) throws IOException {
        return read(CharBuffer.wrap(cbuf, off, len));
      }

      @Override
      public int read(CharBuffer target) throws IOException {
        return readable.read(target);
      }

      @Override
      public void close() throws IOException {
        if (readable instanceof Closeable) {
          ((Closeable) readable).close();
        }
      }
    };
  }
1180495
public static <T> CloseableIterable<T> singleton(T value) {
        return fromIterable(Collections.singleton(value));
    }
279697
public void close() throws IOException {
		if(inner instanceof CloseableIterator) {
			CloseableIterator<String> toBeClosed = (CloseableIterator<String>) inner;
			toBeClosed.close();
		}
	}
131715
public static <T extends IOReadableWritable> T createCopyWritable(T original) throws IOException {
		if (original == null) {
			return null;
		}

		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
		try (DataOutputViewStreamWrapper out = new DataOutputViewStreamWrapper(baos)) {
			original.write(out);
		}

		final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
		try (DataInputViewStreamWrapper in = new DataInputViewStreamWrapper(bais)) {

			@SuppressWarnings("unchecked")
			T copy = (T) instantiate(original.getClass());
			copy.read(in);
			return copy;
		}
	}
1079714
public static SeekableSource inMemorySeekableSourceFrom(InputStream stream) throws IOException {
        requireNonNull(stream);
        return new ByteArraySeekableSource(IOUtils.toByteArray(stream));
    }
1091536
public static String fromStream(InputStream stream) throws IOException {
		if (stream != null) {			
			try {
				Writer writer = new StringWriter();
				Reader reader = new BufferedReader(new InputStreamReader(stream));
				int read;
				while ((read = reader.read()) != -1) {
					writer.write(read);
				}
				return writer.toString();
			} finally {
				try {
					stream.close();
				} catch(IOException e) {
					logger.warn("error closing the input stream", e);
				}
			}			
		}
		return null;
	}
1297689
public static <T> CloseableIterator<T> singletonIterator(T value) {
        return fromIterator(Iterators.singletonIterator(value));
    }
472802
public static Closeable closeableFrom(@WillNotClose @Nullable final Blob blob) {
        return closeableFrom(blob, Blob::free);
    }
889614
public static <T> CloseableIterable<T> filter(final CloseableIterable<?> iterable, final Class<T> type) {
        return wrap(Iterables.filter(iterable, type), iterable);
    }