Skip to content

Commit 0e9c317

Browse files
committed
Refactor: rename Throwing to Sneaky and sneakyThrow to propagate
1 parent 2feb03e commit 0e9c317

File tree

38 files changed

+203
-212
lines changed

38 files changed

+203
-212
lines changed

jooby/src/main/java/io/jooby/Asset.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ public FileAsset(@Nonnull Path file) {
5757
try {
5858
return Files.size(file);
5959
} catch (IOException x) {
60-
throw Throwing.sneakyThrow(x);
60+
throw Sneaky.propagate(x);
6161
}
6262
}
6363

6464
@Override public long getLastModified() {
6565
try {
6666
return Files.getLastModifiedTime(file).toMillis();
6767
} catch (IOException x) {
68-
throw Throwing.sneakyThrow(x);
68+
throw Sneaky.propagate(x);
6969
}
7070
}
7171

@@ -77,7 +77,7 @@ public FileAsset(@Nonnull Path file) {
7777
try {
7878
return new FileInputStream(file.toFile());
7979
} catch (IOException x) {
80-
throw Throwing.sneakyThrow(x);
80+
throw Sneaky.propagate(x);
8181
}
8282
}
8383

@@ -187,7 +187,7 @@ private void checkOpen() {
187187
content = connection.getInputStream();
188188
}
189189
} catch (IOException x) {
190-
throw Throwing.sneakyThrow(x);
190+
throw Sneaky.propagate(x);
191191
}
192192
}
193193
}

jooby/src/main/java/io/jooby/AssetSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ public interface AssetSource {
8888
Asset singleFile = Asset.create(absoluteLocation);
8989
return p -> singleFile;
9090
}
91-
throw Throwing.sneakyThrow(new FileNotFoundException(location.toAbsolutePath().toString()));
91+
throw Sneaky.propagate(new FileNotFoundException(location.toAbsolutePath().toString()));
9292
}
9393
}

jooby/src/main/java/io/jooby/AttachedFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public AttachedFile(@Nonnull InputStream content, @Nonnull String fileName, long
7070
this.content = content;
7171
this.fileSize = fileSize;
7272
} catch (UnsupportedEncodingException x) {
73-
throw Throwing.sneakyThrow(x);
73+
throw Sneaky.propagate(x);
7474
}
7575
}
7676

jooby/src/main/java/io/jooby/Context.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ default long getRequestLength() {
756756
try {
757757
return parser(contentType).parse(this, type.getType());
758758
} catch (Exception x) {
759-
throw Throwing.sneakyThrow(x);
759+
throw Sneaky.propagate(x);
760760
}
761761
}
762762

@@ -783,7 +783,7 @@ default long getRequestLength() {
783783
try {
784784
return parser(contentType).parse(this, type);
785785
} catch (Exception x) {
786-
throw Throwing.sneakyThrow(x);
786+
throw Sneaky.propagate(x);
787787
}
788788
}
789789

@@ -1027,7 +1027,7 @@ default long getRequestLength() {
10271027
send(bytes);
10281028
return this;
10291029
} catch (Exception x) {
1030-
throw Throwing.sneakyThrow(x);
1030+
throw Sneaky.propagate(x);
10311031
}
10321032
}
10331033

@@ -1058,7 +1058,7 @@ default long getRequestLength() {
10581058
* @throws Exception Is something goes wrong.
10591059
*/
10601060
default @Nonnull Context responseStream(@Nonnull MediaType contentType,
1061-
@Nonnull Throwing.Consumer<OutputStream> consumer) throws Exception {
1061+
@Nonnull Sneaky.Consumer<OutputStream> consumer) throws Exception {
10621062
setResponseType(contentType);
10631063
return responseStream(consumer);
10641064
}
@@ -1070,7 +1070,7 @@ default long getRequestLength() {
10701070
* @return HTTP channel as output stream. Usually for chunked responses.
10711071
* @throws Exception Is something goes wrong.
10721072
*/
1073-
default @Nonnull Context responseStream(@Nonnull Throwing.Consumer<OutputStream> consumer)
1073+
default @Nonnull Context responseStream(@Nonnull Sneaky.Consumer<OutputStream> consumer)
10741074
throws Exception {
10751075
try (OutputStream out = responseStream()) {
10761076
consumer.accept(out);
@@ -1120,7 +1120,7 @@ default long getRequestLength() {
11201120
* @return This context.
11211121
* @throws Exception Is something goes wrong.
11221122
*/
1123-
default @Nonnull Context responseWriter(@Nonnull Throwing.Consumer<PrintWriter> consumer)
1123+
default @Nonnull Context responseWriter(@Nonnull Sneaky.Consumer<PrintWriter> consumer)
11241124
throws Exception {
11251125
return responseWriter(MediaType.text, consumer);
11261126
}
@@ -1134,7 +1134,7 @@ default long getRequestLength() {
11341134
* @throws Exception Is something goes wrong.
11351135
*/
11361136
default @Nonnull Context responseWriter(@Nonnull MediaType contentType,
1137-
@Nonnull Throwing.Consumer<PrintWriter> consumer) throws Exception {
1137+
@Nonnull Sneaky.Consumer<PrintWriter> consumer) throws Exception {
11381138
return responseWriter(contentType, contentType.getCharset(), consumer);
11391139
}
11401140

@@ -1148,7 +1148,7 @@ default long getRequestLength() {
11481148
* @throws Exception Is something goes wrong.
11491149
*/
11501150
default @Nonnull Context responseWriter(@Nonnull MediaType contentType, @Nullable Charset charset,
1151-
@Nonnull Throwing.Consumer<PrintWriter> consumer) throws Exception {
1151+
@Nonnull Sneaky.Consumer<PrintWriter> consumer) throws Exception {
11521152
try (PrintWriter writer = responseWriter(contentType, charset)) {
11531153
consumer.accept(writer);
11541154
}
@@ -1271,7 +1271,7 @@ default long getRequestLength() {
12711271
setDefaultResponseType(MediaType.byFile(file));
12721272
return send(FileChannel.open(file));
12731273
} catch (IOException x) {
1274-
throw Throwing.sneakyThrow(x);
1274+
throw Sneaky.propagate(x);
12751275
}
12761276
}
12771277

@@ -1318,8 +1318,8 @@ default long getRequestLength() {
13181318
.error("error handler resulted in exception {} {}", getMethod(), pathString(), x);
13191319
}
13201320
/** rethrow fatal exceptions: */
1321-
if (Throwing.isFatal(cause)) {
1322-
throw Throwing.sneakyThrow(cause);
1321+
if (Sneaky.isFatal(cause)) {
1322+
throw Sneaky.propagate(cause);
13231323
}
13241324
return this;
13251325
}

jooby/src/main/java/io/jooby/Cookie.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,9 @@
3030
import java.util.Base64;
3131
import java.util.Collections;
3232
import java.util.HashMap;
33-
import java.util.Iterator;
3433
import java.util.Locale;
3534
import java.util.Map;
36-
import java.util.Objects;
37-
import java.util.StringJoiner;
3835
import java.util.concurrent.TimeUnit;
39-
import java.util.function.Function;
40-
import java.util.stream.Collectors;
4136

4237
import static java.util.Objects.requireNonNull;
4338

@@ -393,7 +388,7 @@ public long getMaxAge() {
393388
byte[] bytes = mac.doFinal(value.getBytes());
394389
return Base64.getEncoder().withoutPadding().encodeToString(bytes) + "|" + value;
395390
} catch (Exception x) {
396-
throw Throwing.sneakyThrow(x);
391+
throw Sneaky.propagate(x);
397392
}
398393
}
399394

@@ -436,7 +431,7 @@ public static String encode(Map<String, String> attributes) {
436431
}
437432
return joiner.toString();
438433
} catch (UnsupportedEncodingException x) {
439-
throw Throwing.sneakyThrow(x);
434+
throw Sneaky.propagate(x);
440435
}
441436
}
442437

@@ -471,7 +466,7 @@ public static Map<String, String> decode(String value) {
471466

472467
return attributes.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(attributes);
473468
} catch (UnsupportedEncodingException x) {
474-
throw Throwing.sneakyThrow(x);
469+
throw Sneaky.propagate(x);
475470
}
476471
}
477472

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.typesafe.config.Config;
1919
import io.jooby.internal.RouterImpl;
20-
import jdk.nashorn.internal.scripts.JO;
2120
import org.slf4j.Logger;
2221
import org.slf4j.LoggerFactory;
2322

@@ -35,7 +34,6 @@
3534
import java.util.LinkedList;
3635
import java.util.List;
3736
import java.util.Map;
38-
import java.util.Optional;
3937
import java.util.ServiceLoader;
4038
import java.util.Spliterator;
4139
import java.util.concurrent.Executor;
@@ -87,9 +85,9 @@ public class Jooby implements Router, Registry {
8785

8886
private Path tmpdir;
8987

90-
private List<Throwing.Runnable> readyCallbacks;
88+
private List<Sneaky.Runnable> readyCallbacks;
9189

92-
private List<Throwing.Runnable> startingCallbacks;
90+
private List<Sneaky.Runnable> startingCallbacks;
9391

9492
private LinkedList<AutoCloseable> stopCallbacks;
9593

@@ -192,7 +190,7 @@ public Jooby() {
192190
* @param body Start body.
193191
* @return This application.
194192
*/
195-
public @Nonnull Jooby onStarting(@Nonnull Throwing.Runnable body) {
193+
public @Nonnull Jooby onStarting(@Nonnull Sneaky.Runnable body) {
196194
if (startingCallbacks == null) {
197195
startingCallbacks = new ArrayList<>();
198196
}
@@ -207,7 +205,7 @@ public Jooby() {
207205
* @param body Start body.
208206
* @return This application.
209207
*/
210-
public @Nonnull Jooby onStarted(@Nonnull Throwing.Runnable body) {
208+
public @Nonnull Jooby onStarted(@Nonnull Sneaky.Runnable body) {
211209
if (readyCallbacks == null) {
212210
readyCallbacks = new ArrayList<>();
213211
}
@@ -325,7 +323,7 @@ public Jooby renderer(@Nonnull MediaType contentType, @Nonnull Renderer renderer
325323
try {
326324
extension.install(this);
327325
} catch (Exception x) {
328-
throw Throwing.sneakyThrow(x);
326+
throw Sneaky.propagate(x);
329327
}
330328
}
331329
return this;
@@ -557,7 +555,7 @@ private Registry checkRegistry() {
557555
log.info("Server stop resulted in exception", stopx);
558556
}
559557
// rethrow
560-
throw Throwing.sneakyThrow(x);
558+
throw Sneaky.propagate(x);
561559
}
562560
}
563561

@@ -792,15 +790,15 @@ private static void ensureTmpdir(Path tmpdir) {
792790
Files.createDirectories(tmpdir);
793791
}
794792
} catch (IOException x) {
795-
throw Throwing.sneakyThrow(x);
793+
throw Sneaky.propagate(x);
796794
}
797795
}
798796

799-
private List<Throwing.Runnable> fire(List<Throwing.Runnable> tasks) {
797+
private List<Sneaky.Runnable> fire(List<Sneaky.Runnable> tasks) {
800798
if (tasks != null) {
801-
Iterator<Throwing.Runnable> iterator = tasks.iterator();
799+
Iterator<Sneaky.Runnable> iterator = tasks.iterator();
802800
while (iterator.hasNext()) {
803-
Throwing.Runnable task = iterator.next();
801+
Sneaky.Runnable task = iterator.next();
804802
task.run();
805803
iterator.remove();
806804
}
@@ -840,7 +838,7 @@ private static Supplier<Jooby> reflectionProvider(
840838
(Jooby) Stream.of(applicationType.getDeclaredConstructors())
841839
.filter(it -> it.getParameterCount() == 0)
842840
.findFirst()
843-
.map(Throwing.throwingFunction(c -> c.newInstance()))
841+
.map(Sneaky.throwingFunction(c -> c.newInstance()))
844842
.orElseThrow(() -> new IllegalArgumentException(
845843
"Default constructor for: " + applicationType.getName()));
846844
}
@@ -860,7 +858,7 @@ private void joobyRunHook(ClassLoader loader, Server server) {
860858
Consumer consumer = (Consumer) parent.loadClass(hookClassname).newInstance();
861859
consumer.accept(server);
862860
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException x) {
863-
throw Throwing.sneakyThrow(x);
861+
throw Sneaky.propagate(x);
864862
}
865863
}
866864
}

jooby/src/main/java/io/jooby/ServerOptions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.typesafe.config.Config;
1919

2020
import javax.annotation.Nonnull;
21-
import javax.annotation.Nullable;
2221
import java.io.IOException;
2322
import java.net.ServerSocket;
2423
import java.util.Optional;
@@ -381,7 +380,7 @@ private int randomPort() {
381380
try (ServerSocket socket = new ServerSocket(0)) {
382381
return socket.getLocalPort();
383382
} catch (IOException x) {
384-
throw Throwing.sneakyThrow(x);
383+
throw Sneaky.propagate(x);
385384
}
386385
}
387386
}

0 commit comments

Comments
 (0)