Eliminate the need for Encoder#getContentLength
Issue: SPR-16892
This commit is contained in:
@@ -55,8 +55,4 @@ public class ByteArrayEncoder extends AbstractEncoder<byte[]> {
|
||||
return Flux.from(inputStream).map(bufferFactory::wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getContentLength(byte[] bytes, @Nullable MimeType mimeType) {
|
||||
return (long) bytes.length;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,4 @@ public class ByteBufferEncoder extends AbstractEncoder<ByteBuffer> {
|
||||
return Flux.from(inputStream).map(bufferFactory::wrap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getContentLength(ByteBuffer byteBuffer, @Nullable MimeType mimeType) {
|
||||
return (long) byteBuffer.array().length;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,11 +82,6 @@ public class CharSequenceEncoder extends AbstractEncoder<CharSequence> {
|
||||
return charset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getContentLength(CharSequence data, @Nullable MimeType mimeType) {
|
||||
return (long) data.toString().getBytes(getCharset(mimeType)).length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code CharSequenceEncoder} that supports only "text/plain".
|
||||
*/
|
||||
|
||||
@@ -55,9 +55,4 @@ public class DataBufferEncoder extends AbstractEncoder<DataBuffer> {
|
||||
return Flux.from(inputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getContentLength(DataBuffer dataBuffer, @Nullable MimeType mimeType) {
|
||||
return (long) dataBuffer.readableByteCount();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,8 +72,12 @@ public interface Encoder<T> {
|
||||
* @param t the item to check
|
||||
* @return the length in bytes, or {@code null} if not known.
|
||||
* @since 5.0.5
|
||||
* @deprecated this method was added so {@code EncoderHttpMessageWriter}
|
||||
* can set the content-length header. However after further improvements as
|
||||
* of 5.0.7, it is no longer needed, and not used.
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
default Long getContentLength(T t, @Nullable MimeType mimeType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.springframework.core.codec;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
@@ -70,17 +68,4 @@ public class ResourceEncoder extends AbstractSingleValueEncoder<Resource> {
|
||||
return DataBufferUtils.read(resource, dataBufferFactory, this.bufferSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getContentLength(Resource resource, @Nullable MimeType mimeType) {
|
||||
// Don't consume InputStream...
|
||||
if (InputStreamResource.class != resource.getClass()) {
|
||||
try {
|
||||
return resource.contentLength();
|
||||
}
|
||||
catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user