Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Oct 1, 2021
2 parents df27920 + 654b9ae commit 445dc56
Show file tree
Hide file tree
Showing 28 changed files with 535 additions and 343 deletions.
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.14</version>
<version>0.0.15</version>
</parent>

<artifactId>java-io-base</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions java-io-base/src/main/java/internal/io/IOIterators.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public enum Empty implements IOIterator<Object> {
INSTANCE;

@Override
public boolean hasNextWithIO() throws IOException {
public boolean hasNextWithIO() {
return false;
}

@Override
public Object nextWithIO() throws IOException, NoSuchElementException {
public Object nextWithIO() throws NoSuchElementException {
throw new NoSuchElementException();
}

Expand All @@ -73,12 +73,12 @@ public static final class Singleton<E> implements IOIterator<E> {
private boolean first = true;

@Override
public boolean hasNextWithIO() throws IOException {
public boolean hasNextWithIO() {
return first;
}

@Override
public E nextWithIO() throws IOException, NoSuchElementException {
public E nextWithIO() throws NoSuchElementException {
if (!hasNextWithIO()) {
throw new NoSuchElementException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public CharSequence formatTemporalAccessor(DateTimeFormatter formatter, Temporal
try {
return formatter.format(value);
} catch (DateTimeException ex) {
doNothing(ex);
}
}
return null;
Expand All @@ -68,6 +69,7 @@ public CharSequence formatStringList(Function<Stream<CharSequence>, String> join
try {
return joiner.apply(value.stream().map(CharSequence.class::cast));
} catch (Exception ex) {
doNothing(ex);
}
}
return null;
Expand Down
10 changes: 10 additions & 0 deletions java-io-base/src/main/java/internal/io/text/InternalParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@lombok.experimental.UtilityClass
public class InternalParser {

@SuppressWarnings("unchecked")
public <T> T parseTemporalAccessor(DateTimeFormatter formatter, TemporalQuery<T>[] queries, CharSequence input) {
if (input != null) {
try {
Expand All @@ -53,6 +54,7 @@ public <T> T parseTemporalAccessor(DateTimeFormatter formatter, TemporalQuery<T>
return (T) formatter.parseBest(input, queries);
}
} catch (DateTimeParseException ex) {
doNothing(ex);
}
}
return null;
Expand Down Expand Up @@ -94,6 +96,7 @@ public double[] parseDoubleArray(CharSequence input) {
}
return result;
} catch (Exception ex) {
doNothing(ex);
}
}
return null;
Expand All @@ -115,6 +118,7 @@ public String[] parseStringArray(CharSequence input) {
}
return result;
} catch (Exception ex) {
doNothing(ex);
}
}
return null;
Expand All @@ -125,6 +129,7 @@ public Integer parseInteger(CharSequence input) {
try {
return Integer.valueOf(input.toString());
} catch (NumberFormatException ex) {
doNothing(ex);
}
}
return null;
Expand All @@ -135,6 +140,7 @@ public Long parseLong(CharSequence input) {
try {
return Long.valueOf(input.toString());
} catch (NumberFormatException ex) {
doNothing(ex);
}
}
return null;
Expand All @@ -145,6 +151,7 @@ public Double parseDouble(CharSequence input) {
try {
return Double.valueOf(input.toString());
} catch (NumberFormatException ex) {
doNothing(ex);
}
}
return null;
Expand All @@ -155,6 +162,7 @@ public Charset parseCharset(CharSequence input) {
try {
return Charset.forName(input.toString());
} catch (IllegalArgumentException ex) {
doNothing(ex);
}
}
return null;
Expand Down Expand Up @@ -183,6 +191,7 @@ public <T extends Enum<T>> T parseEnum(Class<T> enumClass, CharSequence input) {
try {
return Enum.valueOf(enumClass, input.toString());
} catch (IllegalArgumentException ex) {
doNothing(ex);
}
}
return null;
Expand Down Expand Up @@ -291,6 +300,7 @@ public URL parseURL(CharSequence input) {
try {
return new URL(input.toString());
} catch (MalformedURLException ex) {
doNothing(ex);
}
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion java-io-base/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
exports nbbrd.io.text;
exports nbbrd.io.zip;

exports internal.io.text to nbbrd.io.xml;
exports internal.io.text to nbbrd.io.xml, nbbrd.io.xml.bind;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class AbstractIOIterator<E> implements IOIterator<E> {

private enum State {
COMPUTED, NOT_COMPUTED, DONE
};
}

private State state = State.NOT_COMPUTED;

Expand Down
2 changes: 1 addition & 1 deletion java-io-base/src/main/java/nbbrd/io/FileFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ default void formatPath(@NonNull T value, @NonNull Path target) throws IOExcepti
}
}

default void formatStream(@NonNull T value, IOSupplier<? extends OutputStream> target) throws IOException {
default void formatStream(@NonNull T value, @NonNull IOSupplier<? extends OutputStream> target) throws IOException {
Objects.requireNonNull(value, "value");
Objects.requireNonNull(target, "target");
try (OutputStream resource = LegacyFiles.checkResource(target.getWithIO(), "Missing OutputStream")) {
Expand Down
1 change: 1 addition & 0 deletions java-io-base/src/main/java/nbbrd/io/IOIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ default void forEachRemainingWithIO(@NonNull IOConsumer<? super E> action) throw
return new IOIterators.Unchecked<>(this);
}

@SuppressWarnings("unchecked")
@StaticFactoryMethod
static <E> @NonNull IOIterator<E> empty() {
return (IOIterator<E>) IOIterators.Empty.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static IOException wrap(@NonNull Throwable ex) {
@NonNull
public static Throwable unwrap(@NonNull IOException ex) {
Objects.requireNonNull(ex);
return ex instanceof WrappedIOException ? ((WrappedIOException) ex).getCause() : ex;
return ex instanceof WrappedIOException ? ex.getCause() : ex;
}

private WrappedIOException(Throwable ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Represents an operation that accepts a single input argument and returns no
* result. Unlike most other functional interfaces, {@code Consumer} is expected
* to operate via side-effects.
* to operate via side effects.
*
* @param <T> the type of the input to the operation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public interface IOPredicate<T> {
@JdkWithIO
@StaticFactoryMethod
static <T> @NonNull IOPredicate<T> isEqual(Object targetRef) {
return (null == targetRef) ? Objects::isNull : (object) -> targetRef.equals(object);
return (null == targetRef) ? Objects::isNull : targetRef::equals;
}

@StaticFactoryMethod
Expand Down
3 changes: 2 additions & 1 deletion java-io-base/src/main/java/nbbrd/io/sys/ProcessReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ProcessReader {
return newReader(new ProcessBuilder(args).start());
}

public static @NonNull BufferedReader newReader(@NonNull Process process) throws IOException {
public static @NonNull BufferedReader newReader(@NonNull Process process) {
return new BufferedReader(new InputStreamReader(new ProcessInputStream(process), Charset.defaultCharset()));
}

Expand Down Expand Up @@ -69,6 +69,7 @@ public void close() throws IOException {
}

// we need the process to end, else we'll get an illegal Thread State Exception
@SuppressWarnings("StatementWithEmptyBody")
private void readUntilEnd() throws IOException {
while (delegate.read() != -1) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class SystemProperties {

/**
* Path used to find directories and JAR archives containing class files.
* Elements of the class path are separated by a platform-specific character specified in the path.separator property.
* Elements of the class path are separated by a platform-specific character specified in the path separator property.
*
* @return
*/
Expand Down
5 changes: 3 additions & 2 deletions java-io-base/src/main/java/nbbrd/io/text/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public interface Parser<T> {
return o -> after.apply(parse(o));
}

@SuppressWarnings("unchecked")
@StaticFactoryMethod
static <T> @NonNull Parser<T> onDateTimeFormatter(@NonNull DateTimeFormatter formatter, TemporalQuery<T>... queries) {
Objects.requireNonNull(formatter);
Expand Down Expand Up @@ -170,7 +171,7 @@ public interface Parser<T> {
}

@StaticFactoryMethod
static <T extends Enum<T>> @NonNull Parser<T> onEnum(Class<T> type, ToIntFunction<T> function) {
static <T extends Enum<T>> @NonNull Parser<T> onEnum(@NonNull Class<T> type, @NonNull ToIntFunction<T> function) {
final T[] values = type.getEnumConstants();
Objects.requireNonNull(function);
return onInteger().andThen(code -> InternalParser.parse(values, function, code));
Expand All @@ -192,7 +193,7 @@ public interface Parser<T> {
}

@StaticFactoryMethod
static @NonNull Parser<List<String>> onStringList(@NonNull Function<CharSequence, Stream<String>> splitter) {
static @NonNull Parser<List<String>> onStringList(@NonNull Function<CharSequence, @NonNull Stream<String>> splitter) {
Objects.requireNonNull(splitter);
return o -> InternalParser.parseStringList(splitter, o);
}
Expand Down
4 changes: 2 additions & 2 deletions java-io-base/src/main/java/nbbrd/io/text/TextParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ default T parseResource(@NonNull Class<?> type, @NonNull String name, @NonNull C
}

@NonNull
default T parseReader(IOSupplier<? extends Reader> source) throws IOException {
default T parseReader(@NonNull IOSupplier<? extends Reader> source) throws IOException {
Objects.requireNonNull(source, "source");
try (Reader resource = LegacyFiles.checkResource(source.getWithIO(), "Missing Reader")) {
return parseReader(resource);
}
}

@NonNull
default T parseStream(IOSupplier<? extends InputStream> source, @NonNull Charset encoding) throws IOException {
default T parseStream(@NonNull IOSupplier<? extends InputStream> source, @NonNull Charset encoding) throws IOException {
Objects.requireNonNull(source, "source");
Objects.requireNonNull(encoding, "encoding");
try (InputStream resource = LegacyFiles.checkResource(source.getWithIO(), "Missing InputStream")) {
Expand Down
1 change: 1 addition & 0 deletions java-io-base/src/test/java/_test/IOIteratorAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private static <E> void assertIteratorBehavior(Supplier<IOIterator<E>> iterable)
.isThrownBy(iterator::nextWithIO);
}

@SafeVarargs
public static <E> void assertContent(Supplier<IOIterator<E>> iterable, E... content) throws IOException {
assertThat(iterable.get().asUnchecked())
.toIterable()
Expand Down
Loading

0 comments on commit 445dc56

Please sign in to comment.