Reduce flushes in FormHttpMessageConverter
Before this commit, each part written by the FormHttpMessageConverter would typically end with a flush, which reduced performance.
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.http.converter;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLDecoder;
|
||||
@@ -618,7 +619,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
|
||||
private boolean headersWritten = false;
|
||||
|
||||
public MultipartHttpOutputMessage(OutputStream outputStream, Charset charset) {
|
||||
this.outputStream = outputStream;
|
||||
this.outputStream = new MultipartOutputStream(outputStream);
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
@@ -654,6 +655,32 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
|
||||
private byte[] getBytes(String name) {
|
||||
return name.getBytes(this.charset);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* OutputStream that neither flushes nor closes.
|
||||
*/
|
||||
private static class MultipartOutputStream extends FilterOutputStream {
|
||||
|
||||
public MultipartOutputStream(OutputStream out) {
|
||||
super(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int let) throws IOException {
|
||||
this.out.write(b, off, let);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user