Adaptor to allow FileItem objects generated by the package renamed commons-upload to be used by the Servlet 3.0 upload API that expects Parts.
| 39 | * 3.0 upload API that expects {@link Part}s. |
| 40 | */ |
| 41 | public class ApplicationPart implements Part { |
| 42 | |
| 43 | private final FileItem fileItem; |
| 44 | private final File location; |
| 45 | |
| 46 | /** |
| 47 | * Constructs a new ApplicationPart. |
| 48 | * |
| 49 | * @param fileItem the underlying FileItem |
| 50 | * @param location the file location |
| 51 | */ |
| 52 | public ApplicationPart(FileItem fileItem, File location) { |
| 53 | this.fileItem = fileItem; |
| 54 | this.location = location; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public void delete() throws IOException { |
| 59 | fileItem.delete(); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public String getContentType() { |
| 64 | return fileItem.getContentType(); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public String getHeader(String name) { |
| 69 | if (fileItem instanceof DiskFileItem) { |
| 70 | return fileItem.getHeaders().getHeader(name); |
| 71 | } |
| 72 | return null; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public Collection<String> getHeaderNames() { |
| 77 | if (fileItem instanceof DiskFileItem) { |
| 78 | LinkedHashSet<String> headerNames = new LinkedHashSet<>(); |
| 79 | Iterator<String> iter = fileItem.getHeaders().getHeaderNames(); |
| 80 | while (iter.hasNext()) { |
| 81 | headerNames.add(iter.next()); |
| 82 | } |
| 83 | return headerNames; |
| 84 | } |
| 85 | return Collections.emptyList(); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public Collection<String> getHeaders(String name) { |
| 90 | if (fileItem instanceof DiskFileItem) { |
| 91 | LinkedHashSet<String> headers = new LinkedHashSet<>(); |
| 92 | Iterator<String> iter = fileItem.getHeaders().getHeaders(name); |
| 93 | while (iter.hasNext()) { |
| 94 | headers.add(iter.next()); |
| 95 | } |
| 96 | return headers; |
| 97 | } |
| 98 | return Collections.emptyList(); |
nothing calls this directly
no outgoing calls
no test coverage detected