Skip to content

Commit 37eb966

Browse files
committed
rename sendXXX methods to just send
1 parent 38736d2 commit 37eb966

File tree

25 files changed

+103
-113
lines changed

25 files changed

+103
-113
lines changed

docs/asciidoc/responses.adoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ Jooby provides a family of `sendXXX()` methods that produces a response via side
624624
----
625625
{
626626
get("/", ctx -> {
627-
return ctx.sendString("Hello World!");
627+
return ctx.send("Hello World!");
628628
});
629629
}
630630
----
@@ -634,7 +634,7 @@ Jooby provides a family of `sendXXX()` methods that produces a response via side
634634
----
635635
{
636636
get("/") { ctx ->
637-
ctx.sendString("Hello World!")
637+
ctx.send("Hello World!")
638638
}
639639
}
640640
----
@@ -647,11 +647,11 @@ side effects ignoring the output of the route handler.
647647

648648
Family of send methods include:
649649

650-
- javadoc:Context[sendBytes, byte[]]
651-
- javadoc:Context[sendBytes, java.nio.Buffer]
652-
- javadoc:Context[sendString, java.lang.String]
653-
- javadoc:Context[sendFile, java.nio.file.Path]
654-
- javadoc:Context[sendFile, java.io.File]
655-
- javadoc:Context[sendFile, java.nio.channels.FileChannel]
656-
- javadoc:Context[sendAttachment, io.jooby.AttachedFile]
657-
- javadoc:Context[sendStatusCode, io.jooby.StatusCode]
650+
- javadoc:Context[send, byte[]]
651+
- javadoc:Context[send, java.nio.Buffer]
652+
- javadoc:Context[send, java.lang.String]
653+
- javadoc:Context[send, java.nio.file.Path]
654+
- javadoc:Context[send, java.io.File]
655+
- javadoc:Context[send, java.nio.channels.FileChannel]
656+
- javadoc:Context[send, io.jooby.AttachedFile]
657+
- javadoc:Context[send, io.jooby.StatusCode]

examples/src/main/java/examples/BenchApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public Message(String message) {
4848

4949
{
5050
get("/plaintext", ctx -> {
51-
return ctx.sendBytes(MESSAGE_BYTE);
51+
return ctx.send(MESSAGE_BYTE);
5252
});
5353

5454
get("/", ctx -> {
5555
System.out.println(ctx.pathString());
56-
return ctx.sendBytes(MESSAGE_BYTE);
56+
return ctx.send(MESSAGE_BYTE);
5757
});
5858

5959
get("/json", ctx -> Thread.currentThread().getName());

examples/src/main/java/examples/HelloApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public Message(String message) {
4949
{
5050
setExecutionMode(ExecutionMode.EVENT_LOOP);
5151

52-
get("/", ctx -> ctx.sendString(MESSAGE));
52+
get("/", ctx -> ctx.send(MESSAGE));
5353

5454
// get("/{foo}", ctx -> ctx.sendText("Hello World!"));
5555

jooby/src/main/java/io/jooby/AssetHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public AssetHandler(AssetSource... sources) {
5050
String filepath = ctx.pathMap().get(filekey);
5151
Asset asset = resolve(filepath);
5252
if (asset == null) {
53-
ctx.sendStatusCode(StatusCode.NOT_FOUND);
53+
ctx.send(StatusCode.NOT_FOUND);
5454
return ctx;
5555
}
5656

5757
// handle If-None-Match
5858
if (this.etag) {
5959
String ifnm = ctx.header("If-None-Match").value((String) null);
6060
if (ifnm != null && ifnm.equals(asset.getEtag())) {
61-
ctx.sendStatusCode(StatusCode.NOT_MODIFIED);
61+
ctx.send(StatusCode.NOT_MODIFIED);
6262
asset.release();
6363
return ctx;
6464
} else {
@@ -72,7 +72,7 @@ public AssetHandler(AssetSource... sources) {
7272
if (lastModified > 0) {
7373
long ifms = ctx.header("If-Modified-Since").longValue(-1);
7474
if (lastModified <= ifms) {
75-
ctx.sendStatusCode(StatusCode.NOT_MODIFIED);
75+
ctx.send(StatusCode.NOT_MODIFIED);
7676
asset.release();
7777
return ctx;
7878
}
@@ -90,7 +90,7 @@ public AssetHandler(AssetSource... sources) {
9090
ctx.setResponseLength(length);
9191
}
9292
ctx.setResponseType(asset.getContentType());
93-
return ctx.sendStream(asset.stream());
93+
return ctx.send(asset.stream());
9494
}
9595

9696
/**

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

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ default long getRequestLength() {
944944
Route route = getRoute();
945945
Renderer renderer = route.getRenderer();
946946
byte[] bytes = renderer.render(this, value);
947-
sendBytes(bytes);
947+
send(bytes);
948948
return this;
949949
} catch (Exception x) {
950950
throw Throwing.sneakyThrow(x);
@@ -1094,7 +1094,7 @@ default long getRequestLength() {
10941094
*/
10951095
default @Nonnull Context sendRedirect(@Nonnull StatusCode redirect, @Nonnull String location) {
10961096
setHeader("location", location);
1097-
return sendStatusCode(redirect);
1097+
return send(redirect);
10981098
}
10991099

11001100
/**
@@ -1103,8 +1103,8 @@ default long getRequestLength() {
11031103
* @param data Response. Use UTF-8 charset.
11041104
* @return This context.
11051105
*/
1106-
default @Nonnull Context sendString(@Nonnull String data) {
1107-
return sendString(data, StandardCharsets.UTF_8);
1106+
default @Nonnull Context send(@Nonnull String data) {
1107+
return send(data, StandardCharsets.UTF_8);
11081108
}
11091109

11101110
/**
@@ -1114,32 +1114,32 @@ default long getRequestLength() {
11141114
* @param charset Charset.
11151115
* @return This context.
11161116
*/
1117-
@Nonnull Context sendString(@Nonnull String data, @Nonnull Charset charset);
1117+
@Nonnull Context send(@Nonnull String data, @Nonnull Charset charset);
11181118

11191119
/**
11201120
* Send response data.
11211121
*
11221122
* @param data Response.
11231123
* @return This context.
11241124
*/
1125-
@Nonnull Context sendBytes(@Nonnull byte[] data);
1125+
@Nonnull Context send(@Nonnull byte[] data);
11261126

11271127
/**
11281128
* Send response data.
11291129
*
11301130
* @param data Response.
11311131
* @return This context.
11321132
*/
1133-
@Nonnull Context sendBytes(@Nonnull ByteBuffer data);
1133+
@Nonnull Context send(@Nonnull ByteBuffer data);
11341134

11351135
/**
11361136
* Send response data.
11371137
*
11381138
* @param data Response.
11391139
* @return This context.
11401140
*/
1141-
default @Nonnull Context sendBytes(@Nonnull ByteBuf data) {
1142-
return sendBytes(data.nioBuffer());
1141+
default @Nonnull Context send(@Nonnull ByteBuf data) {
1142+
return send(data.nioBuffer());
11431143
}
11441144

11451145
/**
@@ -1148,23 +1148,23 @@ default long getRequestLength() {
11481148
* @param channel Response input.
11491149
* @return This context.
11501150
*/
1151-
@Nonnull Context sendBytes(@Nonnull ReadableByteChannel channel);
1151+
@Nonnull Context send(@Nonnull ReadableByteChannel channel);
11521152

11531153
/**
11541154
* Send response data.
11551155
*
11561156
* @param input Response.
11571157
* @return This context.
11581158
*/
1159-
@Nonnull Context sendStream(@Nonnull InputStream input);
1159+
@Nonnull Context send(@Nonnull InputStream input);
11601160

11611161
/**
11621162
* Send a file attached response.
11631163
*
11641164
* @param file Attached file.
11651165
* @return This context.
11661166
*/
1167-
default @Nonnull Context sendAttachment(@Nonnull AttachedFile file) {
1167+
default @Nonnull Context send(@Nonnull AttachedFile file) {
11681168
setHeader("Content-Disposition", file.getContentDisposition());
11691169
InputStream content = file.stream();
11701170
long length = file.getFileSize();
@@ -1173,9 +1173,9 @@ default long getRequestLength() {
11731173
}
11741174
setDefaultResponseType(file.getContentType());
11751175
if (content instanceof FileInputStream) {
1176-
sendFile(((FileInputStream) content).getChannel());
1176+
send(((FileInputStream) content).getChannel());
11771177
} else {
1178-
sendStream(content);
1178+
send(content);
11791179
}
11801180
return this;
11811181
}
@@ -1186,10 +1186,10 @@ default long getRequestLength() {
11861186
* @param file File response.
11871187
* @return This context.
11881188
*/
1189-
default @Nonnull Context sendFile(@Nonnull Path file) {
1189+
default @Nonnull Context send(@Nonnull Path file) {
11901190
try {
11911191
setDefaultResponseType(MediaType.byFile(file));
1192-
return sendFile(FileChannel.open(file));
1192+
return send(FileChannel.open(file));
11931193
} catch (IOException x) {
11941194
throw Throwing.sneakyThrow(x);
11951195
}
@@ -1201,25 +1201,15 @@ default long getRequestLength() {
12011201
* @param file File response.
12021202
* @return This context.
12031203
*/
1204-
@Nonnull Context sendFile(@Nonnull FileChannel file);
1204+
@Nonnull Context send(@Nonnull FileChannel file);
12051205

12061206
/**
12071207
* Send an empty response with the given status code.
12081208
*
12091209
* @param statusCode Status code.
12101210
* @return This context.
12111211
*/
1212-
@Nonnull default Context sendStatusCode(@Nonnull StatusCode statusCode) {
1213-
return sendStatusCode(statusCode.value());
1214-
}
1215-
1216-
/**
1217-
* Send an empty response with the given status code.
1218-
*
1219-
* @param statusCode Status code.
1220-
* @return This context.
1221-
*/
1222-
@Nonnull Context sendStatusCode(int statusCode);
1212+
@Nonnull Context send(@Nonnull StatusCode statusCode);
12231213

12241214
/**
12251215
* Send an error response. Status code is computed via {@link Router#errorCode(Throwable)}.

jooby/src/main/java/io/jooby/ErrorHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ public interface ErrorHandler {
8181
ctx
8282
.setResponseType(MediaType.html)
8383
.setStatusCode(statusCode)
84-
.sendString(html.toString());
84+
.send(html.toString());
8585
} else {
8686
String message = Optional.ofNullable(cause.getMessage()).orElse(statusCode.reason());
8787
ctx.setResponseType(json)
8888
.setStatusCode(statusCode)
89-
.sendString("{\"message\":\"" + message + "\",\"statusCode\":" + statusCode.value()
89+
.send("{\"message\":\"" + message + "\",\"statusCode\":" + statusCode.value()
9090
+ ",\"reason\":\"" + statusCode.reason() + "\"}");
9191
}
9292
};

jooby/src/main/java/io/jooby/Route.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public interface Handler extends Serializable {
195195
/**
196196
* Favicon handler as a silent 404 error.
197197
*/
198-
public static final Handler FAVICON = ctx -> ctx.sendStatusCode(StatusCode.NOT_FOUND);
198+
public static final Handler FAVICON = ctx -> ctx.send(StatusCode.NOT_FOUND);
199199

200200
private static final List<MediaType> EMPTY_LIST = Collections.emptyList();
201201

jooby/src/main/java/io/jooby/internal/handler/SendAttachment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public SendAttachment(Route.Handler next) {
3131
@Nonnull @Override public Object apply(@Nonnull Context ctx) {
3232
try {
3333
AttachedFile file = (AttachedFile) next.apply(ctx);
34-
return ctx.sendAttachment(file);
34+
return ctx.send(file);
3535
} catch (Throwable x) {
3636
return ctx.sendError(x);
3737
}

jooby/src/main/java/io/jooby/internal/handler/SendByteArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public SendByteArray(Route.Handler next) {
3030
@Nonnull @Override public Object apply(@Nonnull Context ctx) {
3131
try {
3232
byte[] result = (byte[]) next.apply(ctx);
33-
return ctx.sendBytes(result);
33+
return ctx.send(result);
3434
} catch (Throwable x) {
3535
return ctx.sendError(x);
3636
}

jooby/src/main/java/io/jooby/internal/handler/SendByteBuf.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public SendByteBuf(Route.Handler next) {
3131
@Nonnull @Override public Object apply(@Nonnull Context ctx) {
3232
try {
3333
ByteBuf result = (ByteBuf) next.apply(ctx);
34-
return ctx.sendBytes(result);
34+
return ctx.send(result);
3535
} catch (Throwable x) {
3636
return ctx.sendError(x);
3737
}

0 commit comments

Comments
 (0)