Browse Source

use constants for common empty responses

tags/2.0.1
Jonathan Cobb 4 years ago
parent
commit
f57899c202
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      wizard-server/src/main/java/org/cobbzilla/wizard/resources/ResourceUtil.java

+ 7
- 3
wizard-server/src/main/java/org/cobbzilla/wizard/resources/ResourceUtil.java View File

@@ -37,15 +37,19 @@ import static org.cobbzilla.util.string.StringUtil.UTF8;
@Slf4j
public class ResourceUtil {

public static Response ok() { return Response.ok().build(); }
public static final Response OK_RESPONSE = Response.ok().build();
public static final Response OK_EMPTY_OBJECT = Response.ok(Collections.emptyMap()).build();
public static final Response OK_EMPTY_LIST = Response.ok(Collections.emptyList()).build();

public static Response ok() { return OK_RESPONSE; }

public static Response ok(Object o) { return Response.ok(o).build(); }

public static Response ok_utf8(Object o) { return Response.ok(o).header(CONTENT_ENCODING, UTF8).build(); }

public static Response ok_empty() { return Response.ok(Collections.emptyMap()).build(); }
public static Response ok_empty() { return OK_EMPTY_OBJECT; }

public static Response ok_empty_list() { return Response.ok(Collections.emptyList()).build(); }
public static Response ok_empty_list() { return OK_EMPTY_LIST; }

public static Response send(SendableResource resource) {
return send(resource.getOut(), resource.getStatus(), resource.getHeaders(), resource.getName(), resource.getContentType(), resource.getContentLength(), resource.getForceDownload());


Loading…
Cancel
Save