Drop "get" prefix from Part accessor methods
This commit is contained in:
@@ -29,10 +29,9 @@ import reactor.core.publisher.Mono;
|
||||
public interface FilePart extends Part {
|
||||
|
||||
/**
|
||||
* Return the name of the file selected by the user in a browser form.
|
||||
* Return the original filename in the client's filesystem.
|
||||
*/
|
||||
String getFilename();
|
||||
|
||||
String filename();
|
||||
|
||||
/**
|
||||
* Transfer the file in this part to the given file destination.
|
||||
|
||||
@@ -27,6 +27,6 @@ public interface FormFieldPart extends Part {
|
||||
/**
|
||||
* Return the form field value.
|
||||
*/
|
||||
String getValue();
|
||||
String value();
|
||||
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class MultipartHttpMessageReader implements HttpMessageReader<MultiValueM
|
||||
ReactiveHttpInputMessage inputMessage, Map<String, Object> hints) {
|
||||
|
||||
return this.partReader.read(elementType, inputMessage, hints)
|
||||
.collectMultimap(Part::getName).map(this::toMultiValueMap);
|
||||
.collectMultimap(Part::name).map(this::toMultiValueMap);
|
||||
}
|
||||
|
||||
private LinkedMultiValueMap<String, Part> toMultiValueMap(Map<String, Collection<Part>> map) {
|
||||
|
||||
@@ -43,16 +43,18 @@ public interface Part {
|
||||
* Return the name of the part in the multipart form.
|
||||
* @return the name of the part, never {@code null} or empty
|
||||
*/
|
||||
String getName();
|
||||
String name();
|
||||
|
||||
/**
|
||||
* Return the headers associated with the part.
|
||||
*/
|
||||
HttpHeaders getHeaders();
|
||||
HttpHeaders headers();
|
||||
|
||||
/**
|
||||
* Return the part raw content as a stream of DataBuffer's.
|
||||
* Return the content for this part.
|
||||
* <p>Note that for a {@link FormFieldPart} the content may be accessed
|
||||
* more easily via {@link FormFieldPart#value()}.
|
||||
*/
|
||||
Flux<DataBuffer> getContent();
|
||||
Flux<DataBuffer> content();
|
||||
|
||||
}
|
||||
|
||||
@@ -185,10 +185,14 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
|
||||
public void onPartFinished(StreamStorage storage, Map<String, List<String>> headers) {
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
httpHeaders.putAll(headers);
|
||||
Part part = MultipartUtils.getFileName(httpHeaders) != null ?
|
||||
new SynchronossFilePart(httpHeaders, storage, this.bufferFactory) :
|
||||
this.sink.next(createPart(httpHeaders, storage));
|
||||
}
|
||||
|
||||
private Part createPart(HttpHeaders httpHeaders, StreamStorage storage) {
|
||||
String fileName = MultipartUtils.getFileName(httpHeaders);
|
||||
return fileName != null ?
|
||||
new SynchronossFilePart(httpHeaders, storage, fileName, this.bufferFactory) :
|
||||
new DefaultSynchronossPart(httpHeaders, storage, this.bufferFactory);
|
||||
this.sink.next(part);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -238,12 +242,12 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return MultipartUtils.getFieldName(this.headers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
public HttpHeaders headers() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
@@ -265,7 +269,7 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
|
||||
|
||||
|
||||
@Override
|
||||
public Flux<DataBuffer> getContent() {
|
||||
public Flux<DataBuffer> content() {
|
||||
InputStream inputStream = this.storage.getInputStream();
|
||||
return DataBufferUtils.read(inputStream, getBufferFactory(), 4096);
|
||||
}
|
||||
@@ -278,14 +282,14 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
|
||||
private static class SynchronossFilePart extends DefaultSynchronossPart implements FilePart {
|
||||
|
||||
|
||||
public SynchronossFilePart(HttpHeaders headers, StreamStorage storage, DataBufferFactory factory) {
|
||||
public SynchronossFilePart(HttpHeaders headers, StreamStorage storage, String fileName, DataBufferFactory factory) {
|
||||
super(headers, storage, factory);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return MultipartUtils.getFileName(getHeaders());
|
||||
public String filename() {
|
||||
return MultipartUtils.getFileName(headers());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -341,12 +345,12 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
|
||||
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
public String value() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<DataBuffer> getContent() {
|
||||
public Flux<DataBuffer> content() {
|
||||
byte[] bytes = this.content.getBytes(getCharset());
|
||||
DataBuffer buffer = getBufferFactory().allocateBuffer(bytes.length);
|
||||
buffer.write(bytes);
|
||||
@@ -354,7 +358,7 @@ public class SynchronossPartHttpMessageReader implements HttpMessageReader<Part>
|
||||
}
|
||||
|
||||
private Charset getCharset() {
|
||||
return Optional.ofNullable(MultipartUtils.getCharEncoding(getHeaders()))
|
||||
return Optional.ofNullable(MultipartUtils.getCharEncoding(headers()))
|
||||
.map(Charset::forName).orElse(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public class WebExchangeDataBinder extends WebDataBinder {
|
||||
private static void addBindValue(Map<String, Object> params, String key, List<?> values) {
|
||||
if (!CollectionUtils.isEmpty(values)) {
|
||||
values = values.stream()
|
||||
.map(value -> value instanceof FormFieldPart ? ((FormFieldPart) value).getValue() : value)
|
||||
.map(value -> value instanceof FormFieldPart ? ((FormFieldPart) value).value() : value)
|
||||
.collect(Collectors.toList());
|
||||
params.put(key, values.size() == 1 ? values.get(0) : values);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user