All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.analogweb.Response Maven / Gradle / Ivy

The newest version!
package org.analogweb;

/**
 * Holding response entity to write.
 *
 * @author y2k2mt
 */
public interface Response {

    ResponseEntity getEntity();

    long getContentLength();

    void commit(RequestContext request, ResponseContext response);

    Response NOT_FOUND = new Response() {

        @Override
        public ResponseEntity getEntity() {
            // NOP
            return null;
        }

        @Override
        public long getContentLength() {
            // NOP
            return 0;
        }

        @Override
        public void commit(RequestContext request, ResponseContext response) {
            try {
                response.commit(request, this);
            } finally {
                response.ensure();
            }
        }
    };
    Response EMPTY = new Response() {

        ResponseEntity EMPTY_ENTITY = new ResponseEntity() {

            @Override
            public String entity() {
                // NOP
                return "";
            }

            @Override
            public long getContentLength() {
                // NOP
                return 0;
            }
        };

        @Override
        public ResponseEntity getEntity() {
            // NOP
            return EMPTY_ENTITY;
        }

        @Override
        public long getContentLength() {
            return getEntity().getContentLength();
        }

        @Override
        public void commit(RequestContext request, ResponseContext response) {
            try {
                response.commit(request, this);
            } finally {
                response.ensure();
            }
        }
    };
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy