@Override public void close() { nextItem = null; try { clearGroup(); } finally { baseStream.close(); } }
public ObjectStream<List<String>> tokenize(StringTokenizer tok) { return ObjectStreams.transform(this, new TokenizerFunction(tok)); }
@Override public void close() { source.close(); } };
@Override public boolean hasNext() { if (!hasNextCalled) { next = stream.readObject(); hasNextCalled = true; } return next != null; }
/** * Auto-detect a compression mode from a file name. * @param name The file name. * @return The compression mode. Will never be {@link #AUTO}. */ public static CompressionMode autodetect(String name) { return AUTO.getEffectiveCompressionMode(name); }
@Override public ObjectStream<Entity> openStream() throws IOException { return ObjectStreams.wrap(entities); }
/** * Open a file for input with the default charset. * * @param file The file to open. * @param compression The compression mode. * @return A reader opened on the file. * @throws IOException if there was an error opening the file. * @see #openInput(java.io.File, Charset, CompressionMode) */ public static Reader openInput(File file, CompressionMode compression) throws IOException { return openInput(file, Charset.defaultCharset(), compression); }
@Override default Spliterator<T> spliterator() { return Spliterators.spliteratorUnknownSize(iterator(), 0); } }
/** * Wrap an iterator in an object stream. * * The iterator may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param iterator An iterator to wrap * @return An object stream returning the elements of the iterator. */ public static <T> ObjectStream<T> wrap(Iterator<? extends T> iterator) { return new IteratorObjectStream<>(iterator); }
/** * Get the iterator. This method just returns {@code this}, so for-each * loops can be used over streams. * * @return The stream as an iterator. * @see java.lang.Iterable#iterator() */ @Override public Iterator<T> iterator() { return new ObjectStreamIterator<>(this); }
/** * Create a file byte source, automatically decompressing based on file name. * @param file The file byte source. * @return The byte source, possibly decompressing. */ public static ByteSource byteSource(File file) { return byteSource(file, CompressionMode.AUTO); }
/** * Concatenate object streams. Each object stream is closed as closed as it is consumed. * @param streams The object streams to concatenate. * @param <T> The type of data. * @return The concatenated object stream. */ public static <T> ObjectStream<T> concat(Iterable<? extends ObjectStream<? extends T>> streams) { return new SequencedObjectStream<>(streams); }
@Override public Stream<T> onClose(Runnable closeHandler) { return stream().onClose(closeHandler); } }
@Override public void close() { delegate.close(); } }
@Override default void forEach(Consumer<? super T> action) { T obj = readObject(); while (obj != null) { action.accept(obj); obj = readObject(); } }
/** * Auto-detect a compression mode from a file's name. * @param file The file. * @return The compression mode. Will never be {@link #AUTO}. */ public static CompressionMode autodetect(File file) { return AUTO.getEffectiveCompressionMode(file.getName() ); } }
/** * Wrap a collection in an object stream. * * The iterator may not contain `null`. This property is checked lazily; the object stream will not fail * until the `null` would be returned. * * @param <T> The type of data to return. * @param collection A collection to wrap * @return An object stream returning the elements of the collection. */ public static <T> ObjectStream<T> wrap(Collection<? extends T> collection) { return new IteratorObjectStream<>(collection); }
@Override public void close() { delegate.close(); }
@Override public T readObject() { T obj = delegate.readObject(); while (obj != null && !filter.apply(obj)) { obj = delegate.readObject(); } return obj; } }
protected GroupingObjectStream(@WillCloseWhenClosed ObjectStream<? extends E> base) { baseStream = base; // prime the stream; nextItem = baseStream.readObject(); }