Converts nullable array into an empty stream, and non-null array into a stream.
@param nullable The nullable array to convert.
@param <T> The type of the value.
@return A stream of zero or more values.
344999
public static <T> Stream<T> ofNullable(T[] nullable) {
        return null == nullable ? Stream.empty() : Stream.of(nullable);
    }
916237
@Nullable
    public static String[] nullableArrayOfStringsFromListOfStrings(@Nullable List<String> list) {
        return list == null || list.isEmpty()
                ? null
                : list.toArray(new String[list.size()]);
    }
1020704
@Override
  public <T> Serializer<T> nullable(Serializer<T> serializer) {
    return new NullSerializer<T>(serializer);
  }
1227105
@Override
  public Streamlet<R> filter(SerializablePredicate<R> filterFn) {
    checkNotNull(filterFn, "filterFn cannot be null");

    FilterStreamlet<R> retval = new FilterStreamlet<>(this, filterFn);
    addChild(retval);
    return retval;
  }
889662
public static <R> Stream<R> of(Iterable<R> iterable) {
        return new Stream<R>(iterable.iterator());
    }
1105757
public static byte[] bytes(Streamable streamable) {
        if (streamable == null) return null;

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            streamable.write(stream);
        } catch (IOException e) {
            throw new ApplicationException(e);
        }
        return stream.toByteArray();
    }
621882
public static Persistable persistable(final Streamable streamable) {
        return new Persistable() {

            @Override
            public int size() {
                return streamable.size();
            }

            @Override
            public void write(ByteBuffer buffer) {
                try {
                    streamable.write(new ByteBufferOutputStream(buffer));
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }

            @Override
            public void read(ByteBuffer buffer) {
                try {
                    streamable.read(new ByteBufferInputStream(buffer));
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }

        };
    }
926107
public static LongStream ofNullable(long[] nullable) {
        return null == nullable ? LongStream.empty() : Arrays.stream(nullable);
    }
941937
public static <T> T fromByteArrayFst(byte[] data, Class<T> clazz) {
        return fromByteArrayFst(data, clazz, null);
    }
603747
public static <T> Object[] toArray(Iterable<T> iterable)
    {
        if (iterable == null)
        {
            throw new NullPointerException();
        }
        if (iterable instanceof Collection)
        {
            return ((Collection<T>) iterable).toArray();
        }
        if (iterable instanceof RichIterable)
        {
            return ((RichIterable<T>) iterable).toArray();
        }
        MutableList<T> result = Lists.mutable.empty();
        Iterate.addAllTo(iterable, result);
        return result.toArray();
    }
352599
public static <T> Stream<T> streamOf( Optional<T> value)
    {
    return value.map( Stream::of).orElse( Stream.empty());
    }
737304
@Nullable
  public static byte [] getAllBytes (@Nullable final IHasInputStream aISP)
  {
    if (aISP == null)
      return null;

    return getAllBytes (aISP.getInputStream ());
  }
757263
@Nullable
    public static String readUTF(@NotNull final InputStream stream) throws IOException {
        final DataInputStream dataInput = new DataInputStream(stream);
        if (stream instanceof ByteArraySizedInputStream) {
            final ByteArraySizedInputStream sizedStream = (ByteArraySizedInputStream) stream;
            final int streamSize = sizedStream.size();
            if (streamSize >= 2) {
                sizedStream.mark(Integer.MAX_VALUE);
                final int utfLen = dataInput.readUnsignedShort();
                if (utfLen == streamSize - 2) {
                    boolean isAscii = true;
                    final byte[] bytes = sizedStream.toByteArray();
                    for (int i = 0; i < utfLen; ++i) {
                        if ((bytes[i + 2] & 0xff) > 127) {
                            isAscii = false;
                            break;
                        }
                    }
                    if (isAscii) {
                        return fromAsciiByteArray(bytes, 2, utfLen);
                    }
                }
                sizedStream.reset();
            }
        }
        try {
            String result = null;
            StringBuilder builder = null;
            for (; ; ) {
                final String temp;
                try {
                    temp = dataInput.readUTF();
                    if (result != null && result.length() == 0 &&
                        builder != null && builder.length() == 0 && temp.length() == 0) {
                        break;
                    }
                } catch (EOFException e) {
                    break;
                }
                if (result == null) {
                    result = temp;
                } else {
                    if (builder == null) {
                        builder = new StringBuilder();
                        builder.append(result);
                    }
                    builder.append(temp);
                }
            }
            return (builder != null) ? builder.toString() : result;
        } finally {
            dataInput.close();
        }
    }
159051
@Override
    public StreamT<W,T> onEmpty(final T value) {

        return (StreamT<W,T>) FoldableTransformerSeq.super.onEmpty(value);
    }
1072085
@SafeVarargs
    public static <T> Stream<T> buildStream(T... array) {
        return JMOptional.getOptional(array).map(Arrays::stream)
                .orElseGet(Stream::empty);
    }
1275560
@Override
  public <T> Streamlet<T> map(SerializableFunction<R, ? extends T> mapFn) {
    checkNotNull(mapFn, "mapFn cannot be null");

    MapStreamlet<R, T> retval = new MapStreamlet<>(this, mapFn);
    addChild(retval);
    return retval;
  }
783339
@Nullable
    public static String[] nullableArrayOfStrings(@Nullable List<Object> list) {
        if (list == null || list.isEmpty()) {
            return null;
        } else {
            final String[] strings = new String[list.size()];

            //noinspection ForLoopReplaceableByForEach -> on Android it's faster
            for (int i = 0; i < list.size(); i++) {
                final Object arg = list.get(i);
                strings[i] = arg != null ? arg.toString() : "null";
            }
            return strings;
        }
    }