|
Keel 2.1RC2 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.keel.comm.BinaryWrapper
Handles the transfer and serializatoin issues BLOBs and other binary objects between Keel's client and server sides. Designed specifically to handle both VERY large objects (1GB+) as well as small binary objects. Based partly on the DefaultFileItem object from the Jarkarta Commons Fileupload project. This class can handle both local (e.g. single-VM deployments) and remote requests and responses with binary objects, of basically any size. Small objects ("small" being less than the adjustable threshold) can be handled in-memory as a simple byte array. Larger objects will be written to a file, and passed as a URL reference to this file. The client-side must then access this URL in order to access the content. (For secure content, ensure that the URL is accessible only to the user running the web/application server (e.g. Tomcat), not to the end-user (e.g. with the browser) directly. BinaryWrapper is "two-way", that is, used for both uploaded files (binary objects coming from the client) and binary responses (such as PDF's or charts, images, etc) coming from the server as the result of execution of Models. For use in Models, use a BinaryWrapper as the content of an Output.
| Field Summary | |
protected byte[] |
cachedContentCached content, if below the threshold (or setKeepInMemory was called) |
protected java.lang.String |
contentFileNameExternal filename for content - not retained when serialized |
protected java.lang.String |
contentTypeThe content type passed by the browser, or null if not defined (this is typically a mime type and subtype). |
private static int |
counterCounter used in unique identifier generation. |
private java.lang.Process |
currentProcessHandle to the current process, if any |
private java.lang.String |
execPathA BinaryWrapper can be a reference to an external process (e.g. |
protected java.lang.String |
fileNameThe original filename in originating filesystem. |
private int |
modeThe current mode of this BinaryWrapper. |
private static int |
MODE_EXECUTABLEThis BinaryWrapper represents an executable task, no stored content at all. |
private static int |
MODE_INMEMORYThe content is stored in memory |
private static int |
MODE_KEEPINMEMORYContent is stored in memory, no matter what it's size (see the setKeepInMemory() method) |
private static int |
MODE_UNKNOWNThe mode of this BinaryWrapper has not yet been determined |
private static int |
MODE_URLThe content is stored at a URL location |
protected java.io.File |
repositoryThe directory in which uploaded and temporary files will be stored, if stored on disk. |
protected long |
sizeWhen the content is supplied, we know it's size. |
protected int |
sizeThresholdThe threshold above which contents will be stored on disk. |
private java.lang.String |
urlThe URL to access the content from the "receiving" side of this BinaryWrapper |
private java.lang.String |
urlPrefixIf the content we're dealing with is larger than the threshold (defined above), then we must write it to disk on the originating system and read it back from a URL on the destination side. |
| Constructor Summary | |
BinaryWrapper()Create an uninitialized BinaryWrapper |
|
| Method Summary | |
void |
close()Closes and flushes the underlying output stream. |
void |
delete()Deletes the underlying storage for a file item, including deleting any associated temporary disk file. |
protected void |
finalize()Call release to clean up if we have not already |
byte[] |
get()Returns the data as an array of bytes. |
java.lang.String |
getContentType()Returns the content type passed by the browser or null if not defined. |
java.lang.String |
getFileName()Retrieve the "filename" property of this BinaryWrapper. |
java.io.InputStream |
getInputStream()Returns an InputStreamthat can be used to retrieve the contents of this BinaryWrapper. |
java.io.OutputStream |
getOutputStream()Returns an OutputStreamthat can be used for storing the contents of the file. |
long |
getSize()Returns the size of the content, if we know it. |
java.lang.String |
getString()Returns the contents of the file as a String, using the default character encoding. |
java.lang.String |
getString(java.lang.String encoding)Returns the contents of the file as a String, using the specified encoding. |
boolean |
isExecutable()Does this BinaryWrapper refer to some external executable program in order to get it's content? |
boolean |
isInMemory()Provides a hint as to whether or not the file contents will be read from memory. |
void |
loadFromStream(java.io.InputStream is)Load the content of this BinaryWrapper from the specified input stream. |
void |
loadFromURL(java.lang.String url) |
private java.lang.String |
modeToString(int mode)Convert the specified mode value into a string |
void |
release()Removes the file contents from the temporary storage. |
void |
setContent(byte[] newContent)Set the content cache directly. |
void |
setContentType(java.lang.String newType)Specify the content type of the content to be transferred. |
void |
setExecutablePath(java.lang.String newPath)Specify a path to an executable from which this BinaryWrapper get's it's content. |
void |
setFileName(java.lang.String newName)Specify the "filename" for this content. |
void |
setKeepInMemory()Insist that the data be kept in memory, no matter the size. |
void |
setRepository(java.io.File newRepository)Specify the file repository used to hold content in temporary files if it's size exceeds the threshold size. |
void |
setThreshold(int newThreshold)The threshold, in bytes, below which items will be retained in memory and above which they will be stored as a file. |
void |
setURLPrefix(java.lang.String newUrlPrefix) |
java.lang.String |
toString()Return this BinaryWrapper as a string description, useful for debugging |
void |
writeToFile(java.lang.String fileName)Convenience method to write the contents to the specified filename |
void |
writeToStream(java.io.OutputStream bout)Write the current content to the specified output stream |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
private static int counter
private static final int MODE_UNKNOWN
private static final int MODE_INMEMORY
private static final int MODE_URL
private static final int MODE_EXECUTABLE
private static final int MODE_KEEPINMEMORY
private int mode
protected java.lang.String contentType
null if not defined (this is typically a mime type and subtype).
protected java.lang.String fileName
protected transient java.lang.String contentFileName
protected long size
protected int sizeThreshold
protected java.io.File repository
private java.lang.String urlPrefix
private java.lang.String url
protected byte[] cachedContent
private java.lang.String execPath
private transient java.lang.Process currentProcess
| Constructor Detail |
public BinaryWrapper()
| Method Detail |
public void setKeepInMemory()
public void setFileName(java.lang.String newName)
newName - Name to set the filename property topublic java.lang.String getFileName()
public void setContentType(java.lang.String newType)
newType - The mime type of the content of this BinaryWrapperpublic void setRepository(java.io.File newRepository)
newRepository - A File object indicating a writeable directory.public void setThreshold(int newThreshold)
newThreshold - A new size in bytes to use as the threshold.public void setContent(byte[] newContent)
newContent - A byte array of content (which may not be null or zero-length)public void setExecutablePath(java.lang.String newPath)
newPath -public boolean isExecutable()
public java.io.InputStream getInputStream()
throws java.io.IOException
InputStreamthat can be used to retrieve the contents of this BinaryWrapper.
InputStreamthat can be used to retrieve the contents of the file.java.io.IOException - if an error occurs.public java.lang.String getContentType()
null if not defined.
null if not defined.public boolean isInMemory()
true if the file contents will be read from memory; false otherwise.public long getSize()
public void loadFromURL(java.lang.String url)
throws java.io.IOException
java.io.IOException
public byte[] get()
throws java.io.IOException
java.io.IOException
public java.lang.String getString(java.lang.String encoding)
throws java.io.UnsupportedEncodingException,
java.io.IOException
get()to retrieve the contents of the file.
encoding - The character encoding to use.java.io.UnsupportedEncodingException - if the requested character encoding is not available.java.io.IOException - If the get() method throws an IOException retrieving the content.
public java.lang.String getString()
throws java.io.IOException
get()to retrieve the contents of the file.
java.io.IOException - If the get() method throws an IOException retrieving the content.
public void close()
throws java.io.IOException
java.io.IOException - Thrown if any errors occur with the output streamspublic void delete()
FileItem instance is garbage collected, this method can be used to ensure that this is done at an earlier time, thus preserving system resources.
public java.io.OutputStream getOutputStream()
throws java.io.IOException
OutputStreamthat can be used for storing the contents of the file.
OutputStreamthat can be used for storing the contensts of the file.java.io.IOException - if an error occurs.
public void loadFromStream(java.io.InputStream is)
throws java.io.IOException
is - The input stream to load fromjava.io.IOException - If an IOException occurs during loading
protected void finalize()
throws java.lang.Throwable
java.lang.Throwable
public void release()
throws java.lang.Throwable
java.lang.Throwableprivate java.lang.String modeToString(int mode)
mode - The modepublic void setURLPrefix(java.lang.String newUrlPrefix)
newUrlPrefix - The urlPrefix to set. See class Javadoc for a description.public java.lang.String toString()
public void writeToStream(java.io.OutputStream bout)
throws java.io.IOException
bout - The output stream to write the contents tojava.io.IOException - If an error occurs during writing
public void writeToFile(java.lang.String fileName)
throws java.io.IOException
fileName - A full pathname of the output file to writejava.io.IOException - If an error occurs during writing.
|
Keel 2.1RC2 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||