Skip to content

Commit 6eaba26

Browse files
committed
add CompressionStrategy.toString()
1 parent 54b723f commit 6eaba26

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

http/get_compressed/java/server/src/main/java/com/example/ArrowHttpServer.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static class Handler extends AbstractHandler {
189189
* accepted. If the client does not specify the codecs parameter, then
190190
* defaultCodec is returned.
191191
*/
192-
static Optional<CodecType> pickIpcCodec(
192+
static public Optional<CodecType> pickIpcCodec(
193193
Request request, List<CodecType> available, Optional<CodecType> defaultCodec) {
194194
var accept = request.getHttpFields().getField(HttpHeader.ACCEPT);
195195

@@ -255,7 +255,7 @@ static Optional<CodecType> pickIpcCodec(
255255
* "identity" (uncompressed) either. In this case, a "406 Not
256256
* Acceptable" response should be sent.
257257
*/
258-
static String pickCoding(Request request, List<String> available) {
258+
public static String pickCoding(Request request, List<String> available) {
259259
if (!available.contains("identity")) {
260260
available = new ArrayList<>(available);
261261
available.add("identity");
@@ -282,31 +282,31 @@ static class CompressionStrategy {
282282
/**
283283
* No compression at all.
284284
*/
285-
CompressionStrategy() {
285+
public CompressionStrategy() {
286286
ipcCodec = NoCompressionCodec.INSTANCE;
287287
httpCoding = "identity";
288288
}
289289

290290
/**
291291
* IPC buffer compression without HTTP compression.
292292
*/
293-
CompressionStrategy(CodecType codecType) {
293+
public CompressionStrategy(CodecType codecType) {
294294
this.ipcCodec = CommonsCompressionFactory.INSTANCE.createCodec(codecType);
295295
this.httpCoding = "identity";
296296
}
297297

298298
/**
299299
* HTTP compression without IPC buffer compression.
300300
*/
301-
CompressionStrategy(String coding) {
301+
public CompressionStrategy(String coding) {
302302
this.ipcCodec = NoCompressionCodec.INSTANCE;
303303
this.httpCoding = coding;
304304
}
305305

306306
/**
307307
* IPC buffer compression codec name to be used in HTTP headers.
308308
*/
309-
Optional<String> ipcCodecName() {
309+
public Optional<String> ipcCodecName() {
310310
switch (ipcCodec.getCodecType()) {
311311
case ZSTD:
312312
return Optional.of("zstd");
@@ -318,6 +318,11 @@ Optional<String> ipcCodecName() {
318318
throw new AssertionError("Unexpected codec type: " + ipcCodec.getCodecType());
319319
}
320320
}
321+
322+
@Override
323+
public String toString() {
324+
return ipcCodecName().map(name -> "identity+" + name).orElse(httpCoding);
325+
}
321326
}
322327

323328
/**
@@ -402,7 +407,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
402407
baseRequest.setHandled(true);
403408
return;
404409
}
405-
System.out.println("Compression strategy: " + compression);
410+
System.out.printf("Compression strategy: %s\n", compression);
406411

407412
// In a real application the data would be resolved from a database or
408413
// another source like a file and error handling would be done here

0 commit comments

Comments
 (0)