package de.anycook.api.providers.messagebodywriters;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
/**
* @author Jan Graßegger<jan@anycook.de>
*/
@Provider
@Produces({"text/plain", "application/json"})
public class BooleanMessageBodyWriter implements MessageBodyWriter<Boolean>{
@Override
public boolean isWriteable(Class<?> type, Type type1, Annotation[] antns, MediaType mt) {
return true;
}
@Override
public long getSize(Boolean t, Class<?> type, Type type1, Annotation[] antns, MediaType mt) {
return -1;
}
@Override
public void writeTo(Boolean bool, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException, WebApplicationException {
entityStream.write(bool.toString().getBytes());
}
}