New file |
| | |
| | | package com.dy.pipIrrGlobal.config; |
| | | |
| | | import org.springframework.http.HttpInputMessage; |
| | | import org.springframework.http.HttpOutputMessage; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.converter.AbstractHttpMessageConverter; |
| | | import org.springframework.http.converter.HttpMessageNotReadableException; |
| | | import org.springframework.http.converter.HttpMessageNotWritableException; |
| | | import org.springframework.util.StreamUtils; |
| | | |
| | | import java.io.IOException; |
| | | import java.nio.charset.StandardCharsets; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2024/8/28 15:58 |
| | | * @Description |
| | | */ |
| | | public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<byte[]> { |
| | | |
| | | public ByteArrayHttpMessageConverter() { |
| | | super(MediaType.APPLICATION_OCTET_STREAM, new MediaType("application", "octet-stream", StandardCharsets.UTF_8)); |
| | | } |
| | | |
| | | @Override |
| | | protected boolean supports(Class<?> clazz) { |
| | | return byte[].class == clazz; |
| | | } |
| | | |
| | | @Override |
| | | protected byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { |
| | | // Read the byte array from the input message |
| | | return StreamUtils.copyToByteArray(inputMessage.getBody()); |
| | | } |
| | | |
| | | @Override |
| | | protected void writeInternal(byte[] bytes, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { |
| | | // Write the byte array to the output message |
| | | outputMessage.getBody().write(bytes); |
| | | } |
| | | } |