Skip to content

Commit cef8aec

Browse files
committed
Merge branch 'release-0.0.5'
2 parents 89c79a9 + 7c69a69 commit cef8aec

File tree

72 files changed

+3293
-1815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3293
-1815
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/target/
1+
/java-io-xml/target/
2+
/java-io-base/target/

java-io-base/pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>be.nbb.rd</groupId>
7+
<artifactId>java-io-parent</artifactId>
8+
<version>0.0.5</version>
9+
</parent>
10+
11+
<artifactId>java-io-base</artifactId>
12+
<packaging>jar</packaging>
13+
14+
<dependencies>
15+
<!-- annotations & processors -->
16+
<dependency>
17+
<groupId>org.checkerframework</groupId>
18+
<artifactId>checker-qual</artifactId>
19+
<scope>provided</scope>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.projectlombok</groupId>
23+
<artifactId>lombok</artifactId>
24+
<scope>provided</scope>
25+
</dependency>
26+
27+
<!-- test libraries -->
28+
<dependency>
29+
<groupId>junit</groupId>
30+
<artifactId>junit</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.assertj</groupId>
35+
<artifactId>assertj-core</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.google.jimfs</groupId>
40+
<artifactId>jimfs</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
</project>
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/*
2+
* Copyright 2017 National Bank of Belgium
3+
*
4+
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
5+
* by the European Commission - subsequent versions of the EUPL (the "Licence");
6+
* You may not use this work except in compliance with the Licence.
7+
* You may obtain a copy of the Licence at:
8+
*
9+
* http://ec.europa.eu/idabc/eupl
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the Licence is distributed on an "AS IS" basis,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the Licence for the specific language governing permissions and
15+
* limitations under the Licence.
16+
*/
17+
package internal.io;
18+
19+
import java.io.IOException;
20+
import java.io.UncheckedIOException;
21+
import java.util.Collections;
22+
import java.util.Iterator;
23+
import java.util.NoSuchElementException;
24+
import java.util.Spliterators;
25+
import java.util.function.Consumer;
26+
import java.util.stream.Stream;
27+
import java.util.stream.StreamSupport;
28+
import nbbrd.io.IOIterator;
29+
import nbbrd.io.function.IOConsumer;
30+
import nbbrd.io.function.IOPredicate;
31+
import nbbrd.io.function.IOSupplier;
32+
import nbbrd.io.function.IOUnaryOperator;
33+
import org.checkerframework.checker.nullness.qual.Nullable;
34+
35+
/**
36+
*
37+
* @author Philippe Charles
38+
*/
39+
@lombok.experimental.UtilityClass
40+
public class IOIterators {
41+
42+
public enum Empty implements IOIterator<Object> {
43+
44+
INSTANCE;
45+
46+
@Override
47+
public boolean hasNextWithIO() throws IOException {
48+
return false;
49+
}
50+
51+
@Override
52+
public Object nextWithIO() throws IOException, NoSuchElementException {
53+
throw new NoSuchElementException();
54+
}
55+
56+
@Override
57+
public Stream<Object> asStream() {
58+
return Stream.empty();
59+
}
60+
61+
@Override
62+
public Iterator<Object> asUnchecked() {
63+
return Collections.emptyIterator();
64+
}
65+
}
66+
67+
@lombok.RequiredArgsConstructor
68+
public static final class Singleton<E> implements IOIterator<E> {
69+
70+
@Nullable
71+
private final E element;
72+
73+
private boolean first = true;
74+
75+
@Override
76+
public boolean hasNextWithIO() throws IOException {
77+
return first;
78+
}
79+
80+
@Override
81+
public E nextWithIO() throws IOException, NoSuchElementException {
82+
if (!hasNextWithIO()) {
83+
throw new NoSuchElementException();
84+
}
85+
first = false;
86+
return element;
87+
}
88+
}
89+
90+
@lombok.RequiredArgsConstructor
91+
public static final class Checked<E> implements IOIterator<E> {
92+
93+
@lombok.Getter
94+
@lombok.NonNull
95+
private final Iterator<E> delegate;
96+
97+
@Override
98+
public boolean hasNextWithIO() throws IOException {
99+
try {
100+
return delegate.hasNext();
101+
} catch (UncheckedIOException ex) {
102+
throw ex.getCause();
103+
}
104+
}
105+
106+
@Override
107+
public E nextWithIO() throws IOException, NoSuchElementException {
108+
try {
109+
return delegate.next();
110+
} catch (UncheckedIOException ex) {
111+
throw ex.getCause();
112+
}
113+
}
114+
115+
@Override
116+
public void removeWithIO() throws IOException {
117+
try {
118+
delegate.remove();
119+
} catch (UncheckedIOException ex) {
120+
throw ex.getCause();
121+
}
122+
}
123+
124+
@Override
125+
public void forEachRemainingWithIO(IOConsumer<? super E> action) throws IOException {
126+
try {
127+
delegate.forEachRemaining(action.asUnchecked());
128+
} catch (UncheckedIOException ex) {
129+
throw ex.getCause();
130+
}
131+
}
132+
133+
@Override
134+
public Stream<E> asStream() {
135+
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(delegate, 0), false);
136+
}
137+
138+
@Override
139+
public Iterator<E> asUnchecked() {
140+
return delegate;
141+
}
142+
}
143+
144+
@lombok.RequiredArgsConstructor
145+
public static final class Unchecked<E> implements Iterator<E> {
146+
147+
@lombok.Getter
148+
@lombok.NonNull
149+
private final IOIterator<E> delegate;
150+
151+
@Override
152+
public boolean hasNext() {
153+
try {
154+
return delegate.hasNextWithIO();
155+
} catch (IOException ex) {
156+
throw new UncheckedIOException(ex);
157+
}
158+
}
159+
160+
@Override
161+
public E next() {
162+
try {
163+
return delegate.nextWithIO();
164+
} catch (IOException ex) {
165+
throw new UncheckedIOException(ex);
166+
}
167+
}
168+
169+
@Override
170+
public void remove() {
171+
try {
172+
delegate.removeWithIO();
173+
} catch (IOException ex) {
174+
throw new UncheckedIOException(ex);
175+
}
176+
}
177+
178+
@Override
179+
public void forEachRemaining(Consumer<? super E> action) {
180+
try {
181+
delegate.forEachRemainingWithIO(IOConsumer.checked(action));
182+
} catch (IOException ex) {
183+
throw new UncheckedIOException(ex);
184+
}
185+
}
186+
}
187+
188+
@lombok.RequiredArgsConstructor
189+
public static final class Functional<E> implements IOIterator<E> {
190+
191+
@lombok.NonNull
192+
private final IOSupplier<E> seed;
193+
194+
@lombok.NonNull
195+
private final IOPredicate<? super E> hasNext;
196+
197+
@lombok.NonNull
198+
private final IOUnaryOperator<E> next;
199+
200+
private boolean seeded = false;
201+
private E nextValue = null;
202+
203+
@Override
204+
public boolean hasNextWithIO() throws IOException {
205+
if (!seeded) {
206+
seeded = true;
207+
nextValue = seed.getWithIO();
208+
}
209+
return hasNext.testWithIO(nextValue);
210+
}
211+
212+
@Override
213+
public E nextWithIO() throws IOException, NoSuchElementException {
214+
if (!hasNextWithIO()) {
215+
throw new NoSuchElementException();
216+
}
217+
E result = nextValue;
218+
nextValue = next.applyWithIO(nextValue);
219+
return result;
220+
}
221+
}
222+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2020 National Bank of Belgium
3+
*
4+
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
5+
* by the European Commission - subsequent versions of the EUPL (the "Licence");
6+
* You may not use this work except in compliance with the Licence.
7+
* You may obtain a copy of the Licence at:
8+
*
9+
* http://ec.europa.eu/idabc/eupl
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the Licence is distributed on an "AS IS" basis,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the Licence for the specific language governing permissions and
15+
* limitations under the Licence.
16+
*/
17+
package internal.io;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
/**
26+
*
27+
* @author Philippe Charles
28+
*/
29+
@Target(value = {ElementType.METHOD})
30+
@Retention(value = RetentionPolicy.SOURCE)
31+
@Documented
32+
public @interface JdkWithIO {
33+
34+
String value() default "";
35+
36+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2019 National Bank of Belgium
3+
*
4+
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved
5+
* by the European Commission - subsequent versions of the EUPL (the "Licence");
6+
* You may not use this work except in compliance with the Licence.
7+
* You may obtain a copy of the Licence at:
8+
*
9+
* http://ec.europa.eu/idabc/eupl
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the Licence is distributed on an "AS IS" basis,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the Licence for the specific language governing permissions and
15+
* limitations under the Licence.
16+
*/
17+
18+
module nbbrd.io.base {
19+
20+
requires static org.checkerframework.checker.qual;
21+
requires static lombok;
22+
23+
exports nbbrd.io;
24+
exports nbbrd.io.function;
25+
exports nbbrd.io.zip;
26+
}

0 commit comments

Comments
 (0)