-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all, I have used UploadEvent of ZK to upload huge files like the below codes:
@Listen("onUpload = #fileupload")
public void updata(UploadEvent evt) {
log.info("===start to upload");
Media media = evt.getMedia();
if(media == null) {
return;
}
log.info("file upload path === " + savePath);
mediaName = media.getName();
log.info("media.name() 1 === " + mediaName);
long mediaSize = media.getByteData().length;
log.info("media length === " + mediaSize);
Infact, the codes is simple and it always works well, but what my question is :
How to release the memory which media occupies ?
Even, I write this media into file on DISK, it doesn't work. The memory of my web is huge either.
if(media.isBinary()) {
try {
InputStream input = media.getStreamData();
FileOutputStream outputStream = new FileOutputStream(savePath);
byte[] buf = new byte[1024 * 500];
int length = 0;
while ((length = input.read(buf)) != -1) {
outputStream.write(buf, 0, length);
}
input.close();
input = null;
outputStream.flush();
outputStream.close();
showNotify("Upload Success", win);
} catch (IOException e1) {
log.error(e1.getMessage());
log.error("Upload Error");
System.exit(-1);
}
}
So, are there some methods to release the precious memory that media occupies after it has been written into file on disk ?
Thank you very much!
Maybe try to close the InputStream
and FileOutputStream
correct, as in the finally method of the try catch or use try with resources available from Java 1.7.
They both implement the AutoCloseable
interface.
Then it should be the garbage collector who needs to take it and dispose it.
Greetz chill.
Asked: 2015-02-27 12:48:28 +0800
Seen: 12 times
Last updated: Feb 27 '15
How to stop combining commands in an ajax call ?
zk developmet is esay [closed]
Need help with scrolling horizontal tabs in Right-to-Left (Arabic)
Create tab dynamically, multitab application
Radio button value change on database value
How to implement, each user has its own session timeout time