forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAK-32398 Remove Apache Commons FileItem#get() use (sakaiproject#4189)
This returns the file upload as a byte array which if you are allowing large uploads would all get read onto the heap. Instead it uses an input stream.
- Loading branch information
Showing
5 changed files
with
90 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
feedback/src/java/org/sakaiproject/feedback/util/FileItemDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.sakaiproject.feedback.util; | ||
|
||
import org.apache.commons.fileupload.FileItem; | ||
import org.apache.commons.io.FilenameUtils; | ||
|
||
import javax.activation.DataSource; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
/** | ||
* Proxy to allow FileItems to be used as DataSources for attachments. | ||
*/ | ||
public class FileItemDataSource implements DataSource { | ||
|
||
private FileItem fileItem; | ||
|
||
public FileItemDataSource(FileItem fileItem) { | ||
this.fileItem = fileItem; | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() throws IOException { | ||
return fileItem.getInputStream(); | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream() throws IOException { | ||
throw new IOException("getOutputStream() isn't supported"); | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
return fileItem.getContentType(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
String fileName = fileItem.getName(); | ||
if (fileName != null) { | ||
fileName = FilenameUtils.getName(fileName); | ||
} | ||
return fileName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters