CVS: Tapestry/examples/Tutorial/src/tutorial/workbench/upload UploadResults.java,NONE,1.1.2.1 Upload.java,1.5,1.5.2.1 Upload.html,1.3.4.1,NONE Results.java,1.4,NONE Results.page,1.6.2.1,NONE Results.html,1.4.2.1,NONE Upload.page,1.4.2.1,NONE
Howard Lewis Ship <[email protected]>
| Newsgroups | gmane.comp.java.tapestry.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/workbench/upload
In directory sc8-pr-cvs1:/tmp/cvs-serv10583/examples/Tutorial/src/tutorial/workbench/upload
Modified Files:
Tag: hship-2-3
Upload.java
Added Files:
Tag: hship-2-3
UploadResults.java
Removed Files:
Tag: hship-2-3
Upload.html Results.java Results.page Results.html Upload.page
Log Message:
Reorganize the tutorials to use new 2.4 features.
--- NEW FILE: UploadResults.java ---
package tutorial.workbench.upload;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.io.Writer;
import net.sf.tapestry.IRequestCycle;
import net.sf.tapestry.IUploadFile;
import net.sf.tapestry.RequestCycleException;
import net.sf.tapestry.html.BasePage;
import net.sf.tapestry.util.io.BinaryDumpOutputStream;
/**
* Displays the uploaded file as a hexadecimal dump.
*
* @author Howard Lewis Ship
* @version $Id: UploadResults.java,v 1.1.2.1 2003/01/02 03:15:32 hship Exp $
*
**/
public class UploadResults extends BasePage
{
private IUploadFile file;
private String fileDump;
public void detach()
{
file = null;
fileDump = null;
super.detach();
}
public IUploadFile getFile()
{
return file;
}
public String getFileDump()
{
return fileDump;
}
public void activate(IUploadFile file, boolean showAscii, int bytesPerLine, IRequestCycle cycle)
throws RequestCycleException
{
this.file = file;
StringWriter writer = null;
BinaryDumpOutputStream out = null;
InputStream in = null;
try
{
in = file.getStream();
writer = new StringWriter();
out = new BinaryDumpOutputStream(writer);
out.setShowAscii(showAscii);
out.setBytesPerLine(bytesPerLine) ;
byte[] buffer = new byte[1000];
while (true)
{
int length = in.read(buffer);
if (length < 0)
break;
out.write(buffer, 0, length);
}
in.close();
in = null;
out.close();
out = null;
fileDump = writer.getBuffer().toString();
writer.close();
writer = null;
}
catch (IOException ex)
{
throw new RequestCycleException("Unable to display file.", this, ex);
}
finally
{
close(in);
close(out);
close(writer);
}
cycle.setPage(this);
}
private void close(InputStream stream)
{
if (stream != null)
{
try
{
stream.close();
}
catch (IOException ex)
{
}
}
}
private void close(OutputStream stream)
{
if (stream != null)
{
try
{
stream.close();
}
catch (IOException ex)
{
}
}
}
private void close(Writer writer)
{
if (writer != null)
{
try
{
writer.close();
}
catch (IOException ex)
{
}
}
}
}
Index: Upload.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/examples/Tutorial/src/tutorial/workbench/upload/Upload.java,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -C2 -d -r1.5 -r1.5.2.1
*** Upload.java 27 Nov 2002 17:58:56 -0000 1.5
--- Upload.java 2 Jan 2003 03:15:32 -0000 1.5.2.1
***************
*** 57,61 ****
}
! Results results = (Results) cycle.getPage("upload.Results");
results.activate(file, showAscii, Integer.parseInt(bytesPerLine), cycle);
--- 57,61 ----
}
! UploadResults results = (UploadResults) cycle.getPage("UploadResults");
results.activate(file, showAscii, Integer.parseInt(bytesPerLine), cycle);
--- Upload.html DELETED ---
--- Results.java DELETED ---
--- Results.page DELETED ---
--- Results.html DELETED ---
--- Upload.page DELETED ---
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf