You are on page 1of 6

PACKAGE CLASS TREE DEPRECATED INDEX HELP

PREV CLASS NEXT CLASS FRAMES NO FRAMES ALL CLASSES


SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

jakarta.servlet
Interface RamStringB64

public interface RamStringB64


javax.servlet.RamStringB64 interface and org.apache.catalina.core.RAMStringB64Array class were developed and written by Mr.
Samuel A Marchant , September 2020 Sydney Australia nicephotog@gmail.com (this preview October 2020 - reshuffled methods are now 3
classes)
javax.servlet.RamStringB64 (Tomcat 9) / jakarta.servlet.RamStringB64 (Tomcat 10) is implemented by
org.apache.catalina.core.RAMStringB64Array An instance of this RamStringB64 interface must be obtained from the ServletContext object.

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"

<Context path="/RAMFileLoader" crossContext="true">


<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

<Context path="/WebApplication3" crossContext="true">


<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

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.

<%-- jsp page content inside WebApplication3 --%>


<%
RamStringB64 r64 = request.getServletContext().getContext("/RAMFileLoader").getRamStringB64Instance();
int imagenumber = 5;
out.write("<img src=\"data:image/jpeg;base64,"+r64.getRAMstringB64(imagenumber)+"\" alt=\"image number "+imagenumber+"\"
/>");

// 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>");

int rmximg = 12;


Ramfile rmx = request.getServletContext().getContext("/RAMFileLoader").getRamFileInstance();
out.write("<img src=\"data:image/jpeg;base64,"+((String)r64.convertToStandardB64(76,(rmx.getRAMByteArray(rmximg))))+"\"
alt=\"image number "+rmximg+"\" />");
%>

Example in a jsp page

<%
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:

// first way to obtain it


ServletContext sxt = ((ServletConfig)this.getServletConfig()).getServletContext();
RamStringB64 r64 = sxt.getRamStringB64Instance();

// Second way to obtain it from the ServletContext


RamStringB64 r64 = getServletContext().getRamStringB64Instance();

// a file stored on the array at some index


int array_64string_index = 27;

// get the file as a base 64 encoded String from the RAMStringB64Array object
String attach_download_b64Image = r64 .getRAMstringB64(array_64string_index);

See also: an associate similar mechanism javax.servlet.Ramfile / jakarta.servlet.Ramfile and


org.apache.catalina.core.RAMfileArray

See also: an associate similar mechanism javax.servlet.RamHttpTools / jakarta.servlet.RamHttpTools and


org.apache.catalina.core.RAMfilingHTTPtools

Method Summary

All Methods Instance Methods Abstract Methods


Modifier and Type Method and Description
java.lang.String getInterfaceReadyFlagB64()

Returns a status string relating the B64 RAMStringB64Array class String[] storage array loaded
status.

boolean getIsInterfaceInstanceReadyB64()

Returns "true" if RAMStringB64Array is completely loaded.

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".

java.lang.String getLoadedCanonicalFileNameAtIndexB64(int idxName)

Gets "the full path and name conjoined complete" of the file at a particular index on the B64
encoded RAMStringB64Array String[] array.

java.lang.String getLoadedFileNameAtIndexB64(int idxName)

Gets "the name only" of the file at a particular index on the B64 encoded RAMStringB64Array
String[] array.

java.lang.String getLoadedRAMstringB64namesInventory(boolean HtmlTXT) Print out tool. Gets a


String of names of the base 64 encoded files were sent to be loaded onto the RAM String[]
array.
long getOutWriteRAMbyteB64Length(int arrLenIdX)

Returns a primitive long of the number of bytes of the particular unencoded file loaded at the
array index.

long getOutWriteRAMStringB64Length(int arrLenIdX)

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 !

void loadPreLoadingListB64(java.io.File[] fistset, boolean urlSafe)

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.

void loadPreLoadingListB64(java.io.File setlist, boolean urlSafe)

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).

void loadPreLoadingListB64(java.lang.String[] fls, boolean urlSafe)

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.

void loadPreLoadingListB64(java.lang.String listset, boolean urlSafe)

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.

java.lang.String convertToStandardB64(int chunklength,String enctostr)

Convert a String to standard Base 64 encryption scheme of chunklength characters per line.
(Standard IETF encode is 76 characters per line).

java.lang.String convertToUrlSafeB64(int chunklength,String enctostr)

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).

java.lang.String convertToStandardB64(int chunklength,byte[] encto)

Convert a String to standard Base 64 encryption scheme of chunklength characters per line
(Standard encode is 76 characters per line).

java.lang.String convertToUrlSafeB64(int chunklength,byte[] encto)

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).

org.apache.tomcat.util.codec.binary.Base64 newb64EcoderObject(int lineLength, byte[] lineCRLF,boolean uarelSafe)


This returns a "constructed" Base 64 encode decode object, the constructors CRLF settings will
be from this RAMstraB64Array classes setting (see its set and ger method for CRLF)

void setLineCRLFB64(java.lang.String CR_LF)

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

java.lang.String getLoadedFileNameAtIndexB64(int idxName)


Gets the name only of the file with no path attached at a particular index on the RAMStringB64Array array.

getLoadedCanonicalFileNameAtIndexB64

java.lang.String getLoadedCanonicalFileNameAtIndexB64(int idxName)


Gets the full path and name of the file at a particular index of the RAMStringB64Array from its inventory record filenames array.

setLineCRLFB64

void setLineCRLFB64(java.lang.String CR_LF)


sets a new line character according to chosen requirement.

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

void loadPreLoadingListB64(java.io.File setlist, boolean urlSafe)


Load the RAMStringB64Array by what MUST BE a TXT file - A list of filenames with full path on newlines or comma separated full path
names (NO quotations around them , ordinary text) saved in the TXT file that has been loaded by a program to be a java.io.File object.
loadPreLoadingListB64

void loadPreLoadingListB64(java.lang.String listset, boolean urlSafe)


Load the files by a String passed to the RAMStringB64Array object from another program i.e. a servlet (the bare full path names as
allowed by programming language syntax separated by commas or concatenated to the appropriate platform newline character).

loadPreLoadingListB64

void loadPreLoadingListB64(java.lang.String[] fls, boolean urlSafe)


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.

loadPreLoadingListB64

void loadPreLoadingListB64(java.io.File[] fistset, boolean urlSafe)


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 base 64 encoded String storage[] array by a java.io.File[] array object from some other
program in the server i.e. a special custom servlet.

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

long getOutWriteRAMbyteB64Length(int arrLenIdX)


int arrLenIdX The index required to obtain the array/file-size length no different to
e.g. only: File.length() property

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

long getOutWriteRAMStringB64Length(int arrLenIdX)


int arrLenIdX The index required to obtain the String element length no different to
e.g. only: aString[43].length() property

Returns a primitive long of the number of String characters of String[] array base 64 encoded storage array element

getRAMstringB64

java.lang.String getRAMstringB64(int idxAr)


Brings back a base 64 encoded String element from the RAMStringB64Array array of a loaded file from the specified index on the loaded
RAMStringB64Array String[] storage array. Returns a String object from the input argument int idxAr index of the files'loaded base 64
encoded String for use to acquire for output in a servlet

getLoadedRAMstringB64namesInventory

java.lang.String getLoadedRAMstringB64namesInventory(boolean HtmlTXT)


Print out tool. Gets a String of names of the files were sent to be loaded onto the RAMStringB64Array object base 64 encoded array.
The boolean argument is to choose whether to place report parts on an HTML line <P> tag or a text/plain newline character (if it was not
the html setting on the boolean input argument then view source in your browser to see it as text).
boolean HtmlTXT HTML paragraph tag separator as output or newline characters.

convertToStandardB64

java.lang.String convertToStandardB64(int chunklength,String enctostr)


int chunklength the number of characters setting of the base 64 line
Convert a String to standard Base 64 encryption scheme of 76 characters per line.("recommended" for images) Some browsers only
allow 300kb of image Base 64 data.
Calling an array element of stored byte[] array from RAMfileArray class, using

convertToUrlSafeB64

java.lang.String convertToUrlSafeB64(int chunklength,String enctostr)


int chunklength the number of characters setting of the base 64 line
Convert a String to URL Safe Base 64 ("NOT recommended" for images) encryption scheme of 76 characters per line.

convertToStandardB64

java.lang.String convertToStandardB64(int chunklength,byte[] encto)


int chunklength the number of characters setting of the base 64 line
byte[] encto the information to encode
Convert a String to standard Base 64 encryption scheme of 76 characters per line.("recommended" for images) Some browsers only
allow 300kb of image Base 64 data.
Calling an array element of stored byte[] array from RAMfileArray class, using

convertToUrlSafeB64

java.lang.String convertToUrlSafeB64(int chunklength,byte[] encto)


int chunklength the number of characters setting of the base 64 line
byte[] encto the information to encode
Convert a String to URL Safe Base 64 ("NOT recommended" for images) encryption scheme of 76 characters per line.

newb64EcoderObject

org.apache.tomcat.util.codec.binary.Base64 newb64EcoderObject(int lineLength, byte[] lineCRLF,boolean uarelSafe)


This returns a "constructed" Base 64 encode decode object.

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.

PACKAGE CLASS TREE DEPRECATED INDEX HELP

PREV CLASS NEXT CLASS FRAMES NO FRAMES ALL CLASSES


SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

You might also like