001/* 002 * Copyright 2002-2015 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.messaging.converter; 018 019import org.springframework.messaging.Message; 020import org.springframework.messaging.MessageHeaders; 021import org.springframework.util.MimeTypeUtils; 022 023/** 024 * A {@link MessageConverter} that supports MIME type "application/octet-stream" with the 025 * payload converted to and from a byte[]. 026 * 027 * @author Rossen Stoyanchev 028 * @since 4.0 029 */ 030public class ByteArrayMessageConverter extends AbstractMessageConverter { 031 032 public ByteArrayMessageConverter() { 033 super(MimeTypeUtils.APPLICATION_OCTET_STREAM); 034 } 035 036 037 @Override 038 protected boolean supports(Class<?> clazz) { 039 return (byte[].class == clazz); 040 } 041 042 @Override 043 protected Object convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint) { 044 return message.getPayload(); 045 } 046 047 @Override 048 protected Object convertToInternal(Object payload, MessageHeaders headers, Object conversionHint) { 049 return payload; 050 } 051 052}