Professional Documents
Culture Documents
jakarta.servlet
Interface RamStringB64
This interface is the user end set of tools of the RAMStringB64Array class that is started when the Tomcat Server itself is started.
It is called from within a Servlet application context.
To make it more useful to the JSP context and allow other applications JSP engines to use it, the application should be configured with
crossContext attribute in its context.xml
The best "secure" method of "loading" the class of this interface is to use an application ContextListener to hear its "Application loaded event"
on load, however, all resources inside other applications means the resources must be loaded ready first in sequence.
The main purpose of this class is to store Base 64 encoded files for MIME mail attachments and ready printing to JSP pages
inside <IMG> tag src= attribute for base 64 image embedding.
Use of base 64 embedded images in web pages lowers the number of connection requests to a server , in turn lowering the
overhead of requirement to multi-task with concurrency, such as thread pipelining (alternately and best if the image does not
need to be changed, outright embedding of a converted image should be used with an HTML / JSP editor).
Example: To get the application context from another application and write a B64 image into a jsp page
1. First the META-INF/context.xml in each of the applications must be changed. for "crossContext"
The JSP page in "WebApplication3" will obtain the RamStringB64 interface instance and bring back a Base 64 encoded image
through the "RAMFileLoader" application (a separate loaded application) that has a persistent concrete class associate its
loaded application instance with pre loaded stored Strings on an array.
Because the RAMfileArray class or RAMStringB64Array class are part of the server and instantiated when an application loads, it
is persistent unlike a servlet. However, only one instance of each class per application occurs upon application loading and can
most likely serve all the needs of other applications by cross context use if well strategy managed.
// get another , but is on the from the RAMfileArray byte[] array not as B64
// require it to be converted to Base 64 from byte[] array convertToStandardB64(int chunklength,byte[] encto)
out.write("<p>");
<%
out.write("<img src=\"data:image/jpeg;base64,"+r64.getRAMstringB64(array_file_index )+"\" alt=\"image number
"+array_64string_index +"\" />");
%>
There is , only one instance of RAMStringB64Array each loaded application (e.g. .war) and to use it must be instantiated first before all other
activities. A good simple test of the time required for the files to load onto the array at initialization is using all the documents for the array in a
folder and copy and paste all of them to another folder, the time it requires to complete from the start of the copying sequence is approximately
the time to wait for the files to complete loading onto the RAMStringB64Array String[] storage array.
To reload the RAMStringB64Array will require stopping and undeploying the application that it is operated through because when it is loaded it
is impossible to change that. It is only for secure purpose that it is not made easier (attempting reload of array when it has been loaded only
causes reload attempt to bypass), so it is suggested, only a loader servlet, an inventory servlet and a byte-download-output servlet are present
in the application it is initiated for use from. An instance of the interface is obtained this way using getRamStringB64Instance() method of
javax.servlet.ServletContext interface:
// get the file as a base 64 encoded String from the RAMStringB64Array object
String attach_download_b64Image = r64 .getRAMstringB64(array_64string_index);
Method Summary
Returns a status string relating the B64 RAMStringB64Array class String[] storage array loaded
status.
boolean getIsInterfaceInstanceReadyB64()
java.lang.String getLineCRLFB64()
Returns a newline character, either a default CR LF "\r\n" string "newline character" has been
set or the compliment "set" method of this get method can be used to custom set a "newline
character".
Gets "the full path and name conjoined complete" of the file at a particular index on the B64
encoded RAMStringB64Array String[] array.
Gets "the name only" of the file at a particular index on the B64 encoded RAMStringB64Array
String[] array.
Returns a primitive long of the number of bytes of the particular unencoded file loaded at the
array index.
Returns a primitive long of the number of ( String.length() ) String type characters of the
particular encoded file loaded as an element at the array index.
java.lang.String getRAMstringB64(int idxAr)
Brings back the Base 64 encoded String element from the RAMStringB64 pre-loaded String[]
array from the specified index.
int getTotalLoadedB64Files()
The number of files encoded loaded on the RAMStringB64 String[] array. ( Array.length )
java.lang.String getUrlSafeLoadingFlagB64()
Returns a string boolean alike flag ("TRUE"=url safe, or "FALSE") of whether the files were
loaded using the url safe Base 64 encoding scheme.
WARNING ! URL Safe DOES NOT appear to operate for base 64 embed images !
This is the recommended way to load the RAMStringB64Array (loop the file array first to
check if File.exists())
Load the files for the objects RAMStringB64Array String[] array by a java.io.File[] array object
from some other program in the server i.e. a special custom servlet.
Load the RAMStringB64Array by what MUST BE a TXT file - A list of full path filenames
(separated by commas or by newline characters of the platform the server operates).
Load the files by passing a String array of full path filename elements to the RAMStringB64Array
object the bare full path names as allowed by programming language syntax).
It is best to apply String trim method to the ready names as assurance.
Load the files by a String passed to the RAM file object from another program i.e. a servlet. - A
list of full path filenames (separated by commas or by newline characters of the platform the
server operates).
java.lang.String pingMessageTestB64()
Returns a String message of version and particulars as output about the RAMStringB64Array
class object for test and debug purpose.
Convert a String to standard Base 64 encryption scheme of chunklength characters per line.
(Standard IETF encode is 76 characters per line).
Convert a String to URL Safe Base 64 (not recommended for images) encryption scheme of
chunklength characters per line.(Standard IETF encode is 76 characters per line).
Convert a String to standard Base 64 encryption scheme of chunklength characters per line
(Standard encode is 76 characters per line).
Convert a String to URL Safe Base 64 (not recommended for images) encryption scheme of
chunklength characters per line.(Standard encode is 76 characters per line).
Sets a global newline character. ( See its compliment retrieval method - getLineCRLFB64() )
Method Detail
getIsInterfaceInstanceReadyB64
boolean getIsInterfaceInstanceReadyB64()
Returns true if RAMStringB64Array object is completely loaded based on whether the files are all loaded ready for use by the String
process report flag steps, not the finish of the loading procedure sequence.
Convenience boolean for testing.
getInterfaceReadyFlagB64
java.lang.String getInterfaceReadyFlagB64()
Returns a "status string" relating the RAMStringB64Array object loaded status. There are four flags that can be used in a servlet to
check the applications RAMStringB64Array instance if loading has been attempted.
UNASSIGNED_ARRAY - nothing occurred, the object is simply a created instance of / with the recently loaded web application.
LOADING_ARRAY - Loading is occurring.
FAILED_LOAD - Some problem has occurred such as an exception, see the Tomcat stderr logs (or server error logs of any other java
server it is fitted to the application context of)
ARRAY_LOADED_READY - All loading has finished , the object is now ready to use.
note: For testing the time it will take to load the object to ready, it is not dissimilar to the time it takes on a desktop to copy all files from
one folder to another.
getLoadedFileNameAtIndexB64
getLoadedCanonicalFileNameAtIndexB64
setLineCRLFB64
getLineCRLFB64
java.lang.String getLineCRLFB64()
Retrieves a newline character, either a default CR LF "\r\n" string "newline character" has been set or the compliment set method of this
get method can be used to custom set a "newline character".
getTotalLoadedB64Files
int getTotalLoadedB64Files()
Returns the number of files loaded on the RAMStringB64Array
loadPreLoadingListB64
loadPreLoadingListB64
loadPreLoadingListB64
getUrlSafeLoadingFlagB64
java.lang.String getUrlSafeLoadingFlagB64()
returns a string boolean alike flag ("TRUE" or "FALSE") of of whether the encoder was set as "url safe base 64 encoding scheme" at time
of loading.
There are only two schemes , safe and non-safe.
"FALSE" - unsafe base 64 encoding scheme
"TRUE" - url safe base 64 encoding scheme
For IMG tag page embedded base 64, unsafe setting seems the reliable scheme.
getOutWriteRAMbyteB64Length
Returns a primitive long of the number of bytes of the particular file in its byte[] state before it was used to convert to base 64 encoded
(not the encoded String on the array).
getOutWriteRAMStringB64Length
Returns a primitive long of the number of String characters of String[] array base 64 encoded storage array element
getRAMstringB64
getLoadedRAMstringB64namesInventory
convertToStandardB64
convertToUrlSafeB64
convertToStandardB64
convertToUrlSafeB64
newb64EcoderObject
pingMessageTestB64
java.lang.String pingMessageTestB64()
Should contain details such as Version , date compiled, OS Platform compiled on , JDK level used for compile, and any changes from
previous versions
All in all a debug ping message to understand if it is operative without triggering any dangerous mechanisms.