added headers support to MultipartFile abstraction
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,8 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
@@ -39,6 +41,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*/
|
||||
public class MockMultipartFile implements MultipartFile {
|
||||
|
||||
private static final String CONTENT_TYPE = "Content-Type";
|
||||
|
||||
private final String name;
|
||||
|
||||
private String originalFilename;
|
||||
@@ -129,4 +133,26 @@ public class MockMultipartFile implements MultipartFile {
|
||||
FileCopyUtils.copy(this.content, dest);
|
||||
}
|
||||
|
||||
public String getHeader(String name) {
|
||||
if (CONTENT_TYPE.equalsIgnoreCase(name)) {
|
||||
return this.contentType;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getHeaders(String name) {
|
||||
if (CONTENT_TYPE.equalsIgnoreCase(name)) {
|
||||
return new String[] {this.contentType};
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Iterator<String> getHeaderNames(String name) {
|
||||
return Collections.singleton(CONTENT_TYPE).iterator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user