org.bitbucket.gkutiel.in.my.mind.handler.Textual Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of in-my-mind Show documentation
Show all versions of in-my-mind Show documentation
An opinionated web framework on top of in-core
The newest version!
package org.bitbucket.gkutiel.in.my.mind.handler;
import static com.google.common.net.HttpHeaders.CONTENT_TYPE;
import java.io.UnsupportedEncodingException;
import org.bitbucket.gkutiel.in.Handler;
import com.google.common.base.Strings;
public abstract class Textual extends Handler {
protected abstract String getContentType();
protected abstract String getText();
@Override public final void handle() {
try {
res().getHeaders().addHeader(CONTENT_TYPE, getContentType() + ";charset=utf-8");
res().writeBytes(Strings.nullToEmpty(getText()).getBytes("utf-8"));
} catch (final UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}