File-Stream Processing Using FileEntryCallback

You are viewing an old version (v. 3) of this page.
The latest version is v. 16, last edited on Aug 23, 2012 (view differences | )
<< View previous version | view page history | view next version >>

File-Stream Processing Using FileEntryCallback

There are currently no attachments on this page.

The all-new ACE FileEntry component introduces in-memory file processing. This feature is designed to provide for anti-virus scanning, validity checks or a scenario where the upload doesn't need to be saved and creating it on the disk may be excessive processing.

The component requires that a listener bean, FileEntryCallback, be created to handle the incrementally uploaded bytes. The contract that FileEntryCallbacks must implement is:

/* Notifies the file handler everytime a file begins uploading.
 * fileInfo - information known about the file, before downloading the contents */
public void begin(FileEntryResults.FileInfo fileInfo);

/* We're working with chunks of bytes, as we read them in... */
public void write(byte[] buffer, int offset, int length);

/* We work with bytes, as we read them in... */
public void write(int data);

/* Should we decide to invalidate an upload, perhaps it's over quota, then this method
 * must handle it for the callback. This method may massage the result (raising some
 * prompts and accepting upload), or possibly fail the upload for good by calling
 * FileEntryResults.FileInfo.updateStatus(FileEntryStatus, boolean status).
 * fileInfo - The same object that was passed into begin(FileInfo)
public void end(FileEntryResults.FileInfo fileInfo);

This example demos in-memory processing to provide an MD5 hash for files under 5mb, and a toy example of file handling.

  • [*Implementing FileEntryCallback*]
  • [*Adding the FileEntry Component to Facelet Page*]
  • [*Adding the "Quota Exceeded" Dialog*]

Implementing FileEntryCallback

  • Check fileInfo.getStatus() to determine if the file has pre-failed
  • uploading, due to too many files uploaded, an invalid file extension,
  • or content type.
    Creating our handler is the most important step of this tutorial. Everything else is just wiring up the dependencies.
  • The begin Method
    public void begin(FileEntryResults.FileInfo fileInfo) {}
  • The write Methods
    public void write(byte[] buffer, int offset, int length) {}
    public void write(int data) {}
  • The end Method
    // Some comments here
    public void end(FileEntryResults.FileInfo fileInfo) {}

Adding the FileEntry Component to a Facelet Page

Adding the "Quota Exceeded" Dialog to a Facelet Page

That concludes this overview of the new in-memory processing feature. If you're interested in further details of how this example works, take a look at the complete source code below; or sign up for ICEfaces training for a complete guide to this example and every feature of ICEfaces!

There are currently no attachments on this page.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

© Copyright 2017 ICEsoft Technologies Canada Corp.