[ 2642430 ] Upload give intermitten IllegalStateException

This commit is contained in:
Heng Sin Low 2009-02-26 17:05:32 +00:00
parent 0cf4478890
commit 735e61778a
2 changed files with 32 additions and 8 deletions

View File

@ -25,7 +25,6 @@ import org.adempiere.webui.component.FilenameBox;
import org.adempiere.webui.event.ValueChangeEvent;
import org.compiere.model.GridField;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.zkoss.util.media.Media;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
@ -113,7 +112,7 @@ public class WFilenameEditor extends WEditor
try
{
file = Fileupload.get();
file = Fileupload.get(true);
if (file == null)
return;
@ -136,10 +135,9 @@ public class WFilenameEditor extends WEditor
fos = new FileOutputStream(tempFile);
byte[] bytes = null;
try {
if (file.inMemory()) {
bytes = file.getByteData();
}
catch ( IllegalStateException ise ) {
} else {
InputStream is = file.getStreamData();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[ 1000 ];

View File

@ -17,6 +17,9 @@
package org.adempiere.webui.panel;
import java.awt.Dimension;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import org.adempiere.webui.apps.AEnv;
@ -412,7 +415,7 @@ public class WAttachment extends Window implements EventListener
try
{
media = Fileupload.get();
media = Fileupload.get(true);
if (media != null)
{
@ -437,7 +440,7 @@ public class WAttachment extends Window implements EventListener
{
if (m_attachment.getEntryName(i).equals(fileName))
{
m_attachment.updateEntry(i, media.getByteData());
m_attachment.updateEntry(i, getMediaData(media));
cbContent.setSelectedIndex(i);
m_change = true;
return;
@ -446,7 +449,7 @@ public class WAttachment extends Window implements EventListener
//new
if (m_attachment.addEntry(fileName, media.getByteData()))
if (m_attachment.addEntry(fileName, getMediaData(media)))
{
cbContent.appendItem(media.getName(), media.getName());
cbContent.setSelectedIndex(cbContent.getItemCount()-1);
@ -454,6 +457,29 @@ public class WAttachment extends Window implements EventListener
}
} // getFileName
private byte[] getMediaData(Media media) {
byte[] bytes = null;
if (media.inMemory())
bytes = media.getByteData();
else {
InputStream is = media.getStreamData();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[ 1000 ];
int byteread = 0;
try {
while (( byteread=is.read(buf) )!=-1)
baos.write(buf,0,byteread);
} catch (IOException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
throw new IllegalStateException(e.getLocalizedMessage());
}
bytes = baos.toByteArray();
}
return bytes;
}
/**
* Delete entire Attachment
*/