dcsimg
MAP presistence required.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   abdul_qadeer
Posted On:   Thursday, November 15, 2001 02:52 AM

Hello every Body I want to MAP object that should remain in memory through out the life time of the application. I have a java.util.MAP object which is populated with the values that it takes from that XML file. I want that once that MAP is created in the memory then it should remain presistent there. Because I am using the MAP values for that data validation entered by the user. I want to minimize that file read operations. So this can solve my problem if the MAP remains in that memory for the life time of an application so that every user who enters his data could be verified through that same syncronized MAP. Any suggestion ? And thank you very much for the guidence.    More>>

Hello every Body

I want to MAP object that should remain in memory through out the life time of the application.
I have a java.util.MAP object which is populated with the values that it takes from that XML file.
I want that once that MAP is created in the memory then it should remain presistent there.
Because I am using the MAP values for that data validation entered by the user.

I want to minimize that file read operations.
So this can solve my problem if the MAP remains in that memory for the life time of an application so that every user who enters his data could be verified through that same syncronized MAP.
Any suggestion ?

And thank you very much for the guidence.

   <<Less

Re: MAP presistence required.

Posted By:   Otis_Gospodnetic  
Posted On:   Saturday, November 17, 2001 11:16 AM

Hello,

Unless I am misunderstanding your question, this requires no 'special' coding.


You can read the file with java.io.File class, parse is with something like Xerces-J from Apache, instantiate your Map and simply put elements in it like you normally put them in the Map.


You then just have to expose this Map to the rest of the code (e.g. make it public, or wrap it in a class that has accessor methods that get values from the Map, etc.)


Here is some code that will help you with reading the XML file.



/**
* Main.
*
* @param args command line arguments
*/
public static void main(String[] args)
{
if (args.length < 1)
{
System.err.println("Feed me some arguments...");
System.exit(0);
}

for (int i=0; i < args.length; i++)
{
File file = new File(args[i]);
// optionally check that the file exists, is readable, is not a directory, etc.
FileInputStream fis = null;
try
{
fis = new FileInputStream(file);
}
catch (FileNotFoundException fnfe)
{
System.out.println("File " + args[i] + " can't be read.");
if (fis != null)
{
try
{
fis.close();
}
catch (IOException ioe)
{
System.out.println("File " + args[i] + " can't be closed.");
}
}
// go to next file
continue;
}
byte[] buffer = new byte[4096];

int bytesRead;
//StringBuffer xmlStrBuffer = new StringBuffer();
String xmlStr = "";
try
{
while ((bytesRead = fis.read(buffer)) != -1)
{
//xmlStrBuffer.append(buffer, 0, bytesRead);
xmlStr = xmlStr.concat(new String(buffer, 0, bytesRead));
}
}
catch (IOException ioe)
{
if (fis != null)
{
try
{
fis.close();
}
catch (IOException ioe2)
{
System.out.println("Error reading file " + args[i]);
}
}
// go to next file
continue;
}

try
{
//System.out.println(xmlStr);
// CALL Xerces-J HERE
}
catch (org.xml.sax.SAXException se)
{
System.err.println("org.xml.sax.SAXException thrown");
se.printStackTrace();
}

About | Sitemap | Contact