added headers support to MultipartFile abstraction

This commit is contained in:
Juergen Hoeller
2011-06-27 23:02:13 +00:00
parent 78470782d4
commit 0371f569ec
7 changed files with 182 additions and 16 deletions

View File

@@ -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();
}
}