Author: andrei_exadel
Date: 2008-02-20 11:56:36 -0500 (Wed, 20 Feb 2008)
New Revision: 6218
Modified:
trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/Bean.java
trunk/sandbox/samples/fileUploadDemo/src/main/webapp/WEB-INF/web.xml
trunk/sandbox/samples/fileUploadDemo/src/main/webapp/pages/index.jsp
Log:
work demo version
Modified: trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/Bean.java
===================================================================
--- trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/Bean.java 2008-02-20
16:48:46 UTC (rev 6217)
+++ trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/Bean.java 2008-02-20
16:56:36 UTC (rev 6218)
@@ -22,19 +22,25 @@
package org.richfaces;
import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import javax.faces.event.ActionEvent;
+import javax.faces.event.FacesEvent;
+import org.richfaces.event.UploadEvent;
+
/**
* @author $Autor$
*
*/
public class Bean {
- private Map<String,InputStream> data = new HashMap<String, InputStream>();
+ private Map data = new HashMap();
private boolean flag;
@@ -46,20 +52,43 @@
System.out.println(flag);
this.flag = flag;
}
+
+ public void listener(UploadEvent event) throws IOException{
+
+ File file = event.getFile();
+ System.out.println("File name : " + file.getName());
+ FileInputStream stream = new FileInputStream(file);
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream(4096);
+ byte [] bytes = new byte[4096];
+ int read;
+ while ((read = stream.read(bytes)) != -1) {
+ buffer.write(bytes, 0 , read);
+ }
+ stream.close();
+ file.delete();
+ System.out.println(buffer.toString());
+
+ }
public void action(ActionEvent event) {
try {
if (data != null) {
- for (String name : data.keySet()) {
+ for (String name : (String [])data.keySet().toArray(new String [0])) {
System.out.println("\nFile Name : " + name);
- InputStream stream = data.get(name);
- byte[] buffer = new byte[4096];
- ByteArrayOutputStream b = new ByteArrayOutputStream();
+ File file = (File)data.get(name);
+
+ FileInputStream stream = new FileInputStream(file);
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream(4096);
+ byte [] bytes = new byte[4096];
int read;
- while ((read = stream.read(buffer)) != -1) {
- b.write(buffer, 0, read);
- System.out.println(b.toString());
+ while ((read = stream.read(bytes)) != -1) {
+ buffer.write(bytes, 0 , read);
}
+ stream.close();
+ data.remove(name);
+ file.delete();
+ System.out.println(buffer.toString());
+
}
}
} catch (Exception e) {
Modified: trunk/sandbox/samples/fileUploadDemo/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/sandbox/samples/fileUploadDemo/src/main/webapp/WEB-INF/web.xml 2008-02-20
16:48:46 UTC (rev 6217)
+++ trunk/sandbox/samples/fileUploadDemo/src/main/webapp/WEB-INF/web.xml 2008-02-20
16:56:36 UTC (rev 6218)
@@ -37,6 +37,7 @@
</init-param>
</filter>
+ <!--
<filter>
<display-name>Sleep Filter</display-name>
<filter-name>sleepFilter</filter-name>
@@ -51,6 +52,7 @@
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
+ -->
<filter-mapping>
<filter-name>fileUpload</filter-name>
Modified: trunk/sandbox/samples/fileUploadDemo/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/sandbox/samples/fileUploadDemo/src/main/webapp/pages/index.jsp 2008-02-20
16:48:46 UTC (rev 6217)
+++ trunk/sandbox/samples/fileUploadDemo/src/main/webapp/pages/index.jsp 2008-02-20
16:56:36 UTC (rev 6218)
@@ -20,16 +20,13 @@
<h:messages />
-<fu:fileUpload data="#{bean.data}" progressInfo="info">
+<fu:fileUpload data="#{bean.data}"
fileUploadListener="#{bean.listener}">
<f:facet name="progress">
- <progressBar:progressBar style="height: 10px; width: 300px;"
enabled="false">
+ <progressBar:progressBar style="height: 10px; width: 300px;">
</progressBar:progressBar>
</f:facet>
- <f:facet name="progressLabel">
- <h:panelGroup>
- <h:outputText value="#{info.uploadedMB}MB from
#{info.MB}MB"></h:outputText>
- <h:outputText style="padding-left: 80px" value="time:
#{info.mm}:#{info.ss}"></h:outputText>
- </h:panelGroup>
+ <f:facet name="label">
+ <h:outputText value="{_MB}MB from {MB}MB uploaded ---
{mm}:{ss}"></h:outputText>
</f:facet>
</fu:fileUpload><br/><br/><br/>
<h:commandButton actionListener="#{bean.action}" style="font-weight:
bold; width: 300px;" value="Print file content in
console"></h:commandButton>
Show replies by date