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

com.cybermkd.route.render.ImageRender Maven / Gradle / Ivy

There is a newer version: 1.0.1.3
Show newest version
package com.cybermkd.route.render;

import com.cybermkd.common.Render;
import com.cybermkd.common.http.ContentType;
import com.cybermkd.common.http.HttpRequest;
import com.cybermkd.common.http.HttpResponse;
import com.cybermkd.common.http.exception.WebException;
import com.cybermkd.common.http.result.HttpStatus;
import com.cybermkd.common.http.result.ImageResult;
import com.cybermkd.log.Logger;

import java.awt.image.RenderedImage;

/**
 * Created by ice on 14-12-29.
 */
public class ImageRender extends Render {
    private static final Logger logger = Logger.getLogger(ImageRender.class);

    public void render(HttpRequest request, HttpResponse response, Object out) {
        if (out != null) {
            ImageResult result = null;
            if (out instanceof RenderedImage) {
                result = new ImageResult((RenderedImage) out);
            }

            if (result == null) {
                throw new WebException(HttpStatus.NOT_FOUND, "Image not support '" + out + "'.");
            } else {
                response.setContentType(ContentType.typeOf(result.getType()).value());
                write(request, response, result.getType(), result.getResult());
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy