protected byte[] toBytes(WebMap map) throws IOException {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
if (map instanceof RenderedImageMap) {
RenderedImageMapResponse response = JPEG_MIME_TYPE.equals(map.getMimeType()) ? new JPEGMapResponse(
wms) : new PNGMapResponse(wms);
response.write(map, bout, null);
} else if (map instanceof RawMap) {
((RawMap) map).writeTo(bout);
}