Re: Serialization
From: Roedy Green (look-on_at_mindprod.com.invalid)
Date: 07/21/04
- Next message: Roedy Green: "Re: best book on jni"
- Previous message: bonux: "date"
- In reply to: Mr. Smith: "Serialization"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 21 Jul 2004 17:00:05 GMT
On Wed, 21 Jul 2004 13:12:49 GMT, "Mr. Smith"
<johnmresler@sbcglobal.net> wrote or quoted :
>Sorry for not searching the archives first but I'm in a rush out the door. I
>consider myself a fairly knowledgeable Java programmer and I understand the
>"intent" behind serialization but I have yet to see a good example code that
>displays it in use. Can anyone point me to a source on the web or elsewhere?
>Thanks for your help.
look at http://mindprod.com/projects/javapresenter.html
It reads a preparsed Java source code as as stream of serialised
tokens and displays them.
Serialisation is great because you can dump an entire collection, and
read it back with a single I/O. It lets you massage data in one app
and use it in another.
In the Java glossary if you turn on the frame, you see a navigation
aid, which reads a serialised version of the website index and lets
you jump to any item. The applet itself is just a few lines. All the
work preparing the index is done in batch ahead of time.
Here is the applet:
package com.mindprod.qf;
import java.applet.Applet;
import java.awt.Choice;
import java.awt.Color;
import java.awt.event.ItemListener;
import java.io.InputStream;
import java.net.URL;
/**
* Applet that the end user interacts with. Uses serialised data list
of names and targets.
* Quick find select human name and jump to corresponding URL.
* Applet param golist controls where serialised list comes from.
* param window controls target window.
* See also com\mindprod\keywords\keywords.java which produces the
keyword list.
*/
public class Go extends Applet
{
/**
* List of human names to URLs
*/
GoList goList;
/**
* displayed human names of the anchors
*/
Choice anchorList;
public void init()
{
setBackground(Color.white);
setLayout(null);
String membername = getParameter("golist");
if ( membername == null || membername.length() == 0 )
{
System.out.println("Missing GoList\n");
return;
}
try
{
InputStream is =
Go.class.getResourceAsStream("/com/mindprod/qf/" + membername);
if ( is == null )
{
System.out.println("Missing GoList \"" + membername +
"\" \n");
return;
}
goList = GoList.getData(is);
}
catch ( Exception e )
{
System.out.println("Missing GoList \"" + membername + "\" " +
e + "\n");
return;
}
anchorList = new Choice();
int n = goList.size();
for ( int i=0; i<n; i++ )
{
// use addItem instead of add to keep IE happy.
anchorList.addItem((String) goList.getHumanname(i));
}
anchorList.select(0);
anchorList.setSize(this.getSize());
add(anchorList);
anchorList.addItemListener(
new ItemListener()
{
public void
itemStateChanged(java.awt.event.ItemEvent event)
{
try
{
int index =
anchorList.getSelectedIndex();
if ( index >= 0 )
{
// send them off to visit
the matching page
// won't work unless we
are in a browser
String ref;
String target =
goList.getTarget( index );
if ( target.length() != 0
)
{
ref =
goList.getFilename( index ) + '#' + target;
}
else
{
ref =
goList.getFilename( index );
}
java.net.URL url = new
URL( getDocumentBase(), ref );
String window =
getParameter( "window" );
if ( window == null ||
window.length() == 0 )
{
getAppletContext().showDocument( url );
}
else
{
getAppletContext().showDocument( url, window );
}
}
}
catch ( Exception e )
{
// don't sweat it if it does
not work.
}
}
});
this.setVisible(true); // Lights, Camera, Action.
}
}
-- Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
- Next message: Roedy Green: "Re: best book on jni"
- Previous message: bonux: "date"
- In reply to: Mr. Smith: "Serialization"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|