The BH Package
The Source The .jar The API
//A Test Servlet
import java.util.Arrays;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import static BH.Bytes_Hex.*;
import student_types.*;
public class Bytes_HexServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String test="Hello_World Mr. O'Mally& Mr. Brown-Smith";
String hextest=String2HexString(test);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body><b><font size='+1'><pre> ");
out.println("--The Test String: \n"+test);
byte[] theBytes = String2ByteArray(test);
out.println("--As a byte Array:\n "+Arrays.toString(theBytes));
String hexstring=ByteArray2HexString(theBytes);
out.println("--As a Hex String:\n "+hexstring);
char[] theHexes= hexstring.toCharArray();
out.println("--As a Hex Array:\n "+Arrays.toString(theHexes));
out.println("--Back to the String:\n "+ ByteArray2String(HexArray2ByteArray(theHexes)));
out.println("\nIn One Step");
String ashex=String2HexString(test);
out.println("--String to Hex String:\n "+ashex);
out.println("--Hex String to String:\n "+HexString2String(ashex));
out.println("\n--Objects:");
student jones=new student("jones","senior",90);
byte[] baj=Object2ByteArray(jones);
out.println("Object to HexString: \n"+ByteArray2HexString(baj));
Object the_object=ByteArrayToObject(baj); //The same code but not from the .jar
out.println("<font color='BLUE'>\nI am using a local version of ByteArray2Object\nByteArray2Object has issues in Tomcat lib\n"+
"'seeing' project classes.</font>\n ");
student jones1=(student)the_object;
out.println("--Back to student and get name:");
out.println(jones1.name);
out.println("</pre></font></b></body></html> ");
out.flush();
out.close();
}
public Object ByteArrayToObject(byte[] b){
try {
ByteArrayInputStream bi = new ByteArrayInputStream(b);
ObjectInputStream oin=null;
try {
oin=new ObjectInputStream(bi);
} catch (Exception e) {
e.printStackTrace();
}
return oin.readObject();
} catch (Exception e) {
e.printStackTrace();
}
return new String("No Object");
}
}
http://hoare.cs.umsl.edu/servlet/j-siegel/Bytes_HexServlet
As of now, Bytes_Hex.jar on hoare.cs.umsl.edu.
The .class file was compiled on my home system and moved up to the webapp. In order
to compile on hoare.cs.umsl.edu I will have to make the .jar visible to the source file. Perhaps
create a personal library directory and add it to my CLASSPATH, maybe just add the webapp library directory?