use of com.revolsys.geometry.io.GeometryWriter in project com.revolsys.open by revolsys.
the class GeometryHttpMessageConverter method write.
@Override
public void write(final Geometry geometry, final MediaType mediaType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
if (!HttpServletUtils.getResponse().isCommitted()) {
MediaType actualMediaType;
if (mediaType == null) {
actualMediaType = getDefaultMediaType();
} else {
actualMediaType = mediaType;
}
if (actualMediaType != null) {
final Charset charset = HttpServletUtils.setContentTypeWithCharset(outputMessage, actualMediaType);
final OutputStream body = outputMessage.getBody();
final String mediaTypeString = actualMediaType.getType() + "/" + actualMediaType.getSubtype();
final GeometryWriterFactory writerFactory = IoFactory.factoryByMediaType(GeometryWriterFactory.class, mediaTypeString);
if (writerFactory == null) {
throw new IllegalArgumentException("Media type " + actualMediaType + " not supported");
} else {
final String baseName = HttpServletUtils.getRequestBaseFileName();
final GeometryWriter writer = writerFactory.newGeometryWriter(baseName, body, charset);
writer.write(geometry);
writer.close();
}
}
}
}
Aggregations