Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Mar 18, 2022
2 parents 42c4900 + be5e279 commit eca93ad
Show file tree
Hide file tree
Showing 106 changed files with 801 additions and 776 deletions.
16 changes: 13 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.0.19] - 2022-03-18

### Added

- Add convenient CSV methods
- Add bridge between Text* and Parser/Formatter

### Changed

- Replace composition functions with IO functions

## [0.0.18] - 2022-03-15

Expand Down Expand Up @@ -151,7 +160,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Changed

- Improve XXE desambiguation
- Improve XXE disambiguation
- Improve XML error reporting

### Fixed
Expand All @@ -164,7 +173,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Initial release

[Unreleased]: https://github.com/nbbrd/java-io-util/compare/v0.0.18...HEAD
[Unreleased]: https://github.com/nbbrd/java-io-util/compare/v0.0.19...HEAD
[0.0.19]: https://github.com/nbbrd/java-io-util/compare/v0.0.18...v0.0.19
[0.0.18]: https://github.com/nbbrd/java-io-util/compare/v0.0.17...v0.0.18
[0.0.17]: https://github.com/nbbrd/java-io-util/compare/v0.0.16...v0.0.17
[0.0.16]: https://github.com/nbbrd/java-io-util/compare/v0.0.15...v0.0.16
Expand Down
2 changes: 1 addition & 1 deletion java-io-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.github.nbbrd.java-io-util</groupId>
<artifactId>java-io-parent</artifactId>
<version>0.0.18</version>
<version>0.0.19</version>
</parent>

<artifactId>java-io-base</artifactId>
Expand Down
29 changes: 15 additions & 14 deletions java-io-base/src/main/java/internal/io/AndThenFileParser.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
package internal.io;

import lombok.NonNull;
import nbbrd.io.FileParser;
import nbbrd.io.function.IOFunction;
import nbbrd.io.function.IOSupplier;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.function.Function;

@lombok.AllArgsConstructor
public class AndThenFileParser<T, V> implements FileParser<V> {

@lombok.NonNull
@NonNull
protected final FileParser<T> parser;

@lombok.NonNull
protected final Function<? super T, ? extends V> after;
@NonNull
protected final IOFunction<? super T, ? extends V> after;

@Override
public V parseFile(File source) throws IOException {
return after.apply(parser.parseFile(source));
public @NonNull V parseFile(@NonNull File source) throws IOException {
return after.applyWithIO(parser.parseFile(source));
}

@Override
public V parsePath(Path source) throws IOException {
return after.apply(parser.parsePath(source));
public @NonNull V parsePath(@NonNull Path source) throws IOException {
return after.applyWithIO(parser.parsePath(source));
}

@Override
public V parseResource(Class<?> type, String name) throws IOException {
return after.apply(parser.parseResource(type, name));
public @NonNull V parseResource(@NonNull Class<?> type, @NonNull String name) throws IOException {
return after.applyWithIO(parser.parseResource(type, name));
}

@Override
public V parseStream(IOSupplier<? extends InputStream> source) throws IOException {
return after.apply(parser.parseStream(source));
public @NonNull V parseStream(@NonNull IOSupplier<? extends InputStream> source) throws IOException {
return after.applyWithIO(parser.parseStream(source));
}

@Override
public V parseStream(InputStream resource) throws IOException {
return after.apply(parser.parseStream(resource));
public @NonNull V parseStream(@NonNull InputStream resource) throws IOException {
return after.applyWithIO(parser.parseStream(resource));
}
}
30 changes: 13 additions & 17 deletions java-io-base/src/main/java/internal/io/ComposeFileFormatter.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
package internal.io;

import lombok.NonNull;
import nbbrd.io.FileFormatter;
import nbbrd.io.function.IOFunction;
import nbbrd.io.function.IOSupplier;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.Objects;
import java.util.function.Function;

@lombok.AllArgsConstructor
public class ComposeFileFormatter<V, T> implements FileFormatter<V> {

@lombok.NonNull
@NonNull
protected final FileFormatter<T> formatter;

@lombok.NonNull
protected final Function<? super V, ? extends T> before;
@NonNull
protected final IOFunction<? super V, ? extends T> before;

@Override
public void formatFile(V value, File target) throws IOException {
Objects.requireNonNull(value, "value");
formatter.formatFile(before.apply(value), target);
public void formatFile(@NonNull V value, @NonNull File target) throws IOException {
formatter.formatFile(before.applyWithIO(value), target);
}

@Override
public void formatPath(V value, Path target) throws IOException {
Objects.requireNonNull(value, "value");
formatter.formatPath(before.apply(value), target);
public void formatPath(@NonNull V value, @NonNull Path target) throws IOException {
formatter.formatPath(before.applyWithIO(value), target);
}

@Override
public void formatStream(V value, IOSupplier<? extends OutputStream> target) throws IOException {
Objects.requireNonNull(value, "value");
formatter.formatStream(before.apply(value), target);
public void formatStream(@NonNull V value, @NonNull IOSupplier<? extends OutputStream> target) throws IOException {
formatter.formatStream(before.applyWithIO(value), target);
}

@Override
public void formatStream(V value, OutputStream resource) throws IOException {
Objects.requireNonNull(value, "value");
formatter.formatStream(before.apply(value), resource);
public void formatStream(@NonNull V value, @NonNull OutputStream resource) throws IOException {
formatter.formatStream(before.applyWithIO(value), resource);
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package internal.io;

import lombok.NonNull;
import nbbrd.io.FileParser;
import nbbrd.io.function.IOSupplier;
import nbbrd.io.function.IOUnaryOperator;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Objects;

@lombok.RequiredArgsConstructor
public final class DecodingFileFormatter<T> implements FileParser<T> {

@lombok.NonNull
@NonNull
final FileParser<T> parser;

@lombok.NonNull
@NonNull
final IOUnaryOperator<InputStream> decoder;

@Override
Expand All @@ -39,14 +38,13 @@ public final class DecodingFileFormatter<T> implements FileParser<T> {
}

@Override
public @NonNull T parseStream(IOSupplier<? extends InputStream> source) throws IOException {
public @NonNull T parseStream(@NonNull IOSupplier<? extends InputStream> source) throws IOException {
// force use of default impl
return FileParser.super.parseStream(source);
}

@Override
public @NonNull T parseStream(@NonNull InputStream resource) throws IOException {
Objects.requireNonNull(resource, "resource");
try (InputStream decoding = decoder.applyWithIO(resource)) {
return parser.parseStream(decoding);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package internal.io;

import lombok.NonNull;
import nbbrd.io.FileFormatter;
import nbbrd.io.function.IOSupplier;
import nbbrd.io.function.IOUnaryOperator;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.Objects;

@lombok.RequiredArgsConstructor
public final class EncodingFileFormatter<T> implements FileFormatter<T> {

@lombok.NonNull
@NonNull
final FileFormatter<T> formatter;

@lombok.NonNull
@NonNull
final IOUnaryOperator<OutputStream> encoder;

@Override
Expand All @@ -40,8 +39,6 @@ public void formatStream(@NonNull T value, @NonNull IOSupplier<? extends OutputS

@Override
public void formatStream(@NonNull T value, @NonNull OutputStream resource) throws IOException {
Objects.requireNonNull(value, "value");
Objects.requireNonNull(resource, "resource");
try (OutputStream encoding = encoder.applyWithIO(resource)) {
formatter.formatStream(value, encoding);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
package internal.io;

import lombok.NonNull;
import nbbrd.io.FileFormatter;
import nbbrd.io.function.IOBiConsumer;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Objects;

@lombok.RequiredArgsConstructor
public final class FunctionalFileFormatter<T> implements FileFormatter<T> {

@lombok.NonNull
@NonNull
private final IOBiConsumer<? super T, ? super OutputStream> function;

@Override
public void formatStream(@NonNull T value, @NonNull OutputStream resource) throws IOException {
Objects.requireNonNull(value, "value");
Objects.requireNonNull(resource, "resource");
function.acceptWithIO(value, resource);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package internal.io;

import lombok.NonNull;
import nbbrd.io.FileParser;
import nbbrd.io.function.IOFunction;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -11,12 +11,11 @@
@lombok.RequiredArgsConstructor
public final class FunctionalFileParser<T> implements FileParser<T> {

@lombok.NonNull
@NonNull
private final IOFunction<? super InputStream, ? extends T> function;

@Override
public @NonNull T parseStream(@NonNull InputStream resource) throws IOException {
Objects.requireNonNull(resource, "resource");
return Objects.requireNonNull(function.applyWithIO(resource), "result");
}
}
34 changes: 18 additions & 16 deletions java-io-base/src/main/java/internal/io/IOIterators.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
*/
package internal.io;

import lombok.NonNull;
import nbbrd.io.IOIterator;
import nbbrd.io.function.IOConsumer;
import nbbrd.io.function.IOPredicate;
import nbbrd.io.function.IOSupplier;
import nbbrd.io.function.IOUnaryOperator;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;
Expand All @@ -25,12 +33,6 @@
import java.util.function.Consumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import nbbrd.io.IOIterator;
import nbbrd.io.function.IOConsumer;
import nbbrd.io.function.IOPredicate;
import nbbrd.io.function.IOSupplier;
import nbbrd.io.function.IOUnaryOperator;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
*
Expand All @@ -54,12 +56,12 @@ public Object nextWithIO() throws NoSuchElementException {
}

@Override
public Stream<Object> asStream() {
public @NonNull Stream<Object> asStream() {
return Stream.empty();
}

@Override
public Iterator<Object> asUnchecked() {
public @NonNull Iterator<Object> asUnchecked() {
return Collections.emptyIterator();
}
}
Expand Down Expand Up @@ -91,7 +93,7 @@ public E nextWithIO() throws NoSuchElementException {
public static final class Checked<E> implements IOIterator<E> {

@lombok.Getter
@lombok.NonNull
@NonNull
private final Iterator<E> delegate;

@Override
Expand Down Expand Up @@ -122,7 +124,7 @@ public void removeWithIO() throws IOException {
}

@Override
public void forEachRemainingWithIO(IOConsumer<? super E> action) throws IOException {
public void forEachRemainingWithIO(@NonNull IOConsumer<? super E> action) throws IOException {
try {
delegate.forEachRemaining(action.asUnchecked());
} catch (UncheckedIOException ex) {
Expand All @@ -131,12 +133,12 @@ public void forEachRemainingWithIO(IOConsumer<? super E> action) throws IOExcept
}

@Override
public Stream<E> asStream() {
public @NonNull Stream<E> asStream() {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(delegate, 0), false);
}

@Override
public Iterator<E> asUnchecked() {
public @NonNull Iterator<E> asUnchecked() {
return delegate;
}
}
Expand All @@ -145,7 +147,7 @@ public Iterator<E> asUnchecked() {
public static final class Unchecked<E> implements Iterator<E> {

@lombok.Getter
@lombok.NonNull
@NonNull
private final IOIterator<E> delegate;

@Override
Expand Down Expand Up @@ -188,13 +190,13 @@ public void forEachRemaining(Consumer<? super E> action) {
@lombok.RequiredArgsConstructor
public static final class Functional<E> implements IOIterator<E> {

@lombok.NonNull
@NonNull
private final IOSupplier<E> seed;

@lombok.NonNull
@NonNull
private final IOPredicate<? super E> hasNext;

@lombok.NonNull
@NonNull
private final IOUnaryOperator<E> next;

private boolean seeded = false;
Expand Down
Loading

0 comments on commit eca93ad

Please sign in to comment.