in src/java/org/apache/fulcrum/intake/IntakeServiceImpl.java [197:312]
private Map<AppData, File> loadSerialized(String serialDataPath, long timeStamp)
{
getLogger().debug(
"Entered loadSerialized(" + serialDataPath + ", " + timeStamp
+ ")");
long timer = System.currentTimeMillis();
if (serialDataPath == null)
{
return null;
}
File serialDataFile = new File(serialDataPath);
if (!serialDataFile.exists())
{
getLogger().info("No serialized file found, parsing XML");
return null;
}
if (serialDataFile.lastModified() <= timeStamp)
{
getLogger().info("serialized file too old, parsing XML");
return null;
}
ObjectInputStream in = null;
Map<AppData, File> serialData = null;
try
{
FileInputStream fin = new FileInputStream(serialDataFile);
in = new ObjectInputStream(fin);
Object o = in.readObject();
if (o instanceof Map)
{
@SuppressWarnings("unchecked") // checked with instanceof
Map<AppData, File> map = (Map<AppData, File>) o;
serialData = map;
}
else
{
// This could be old file from intake. Try to delete it
getLogger().info("serialized object is not an intake map, ignoring");
in.close();
in = null;
// Try to delete the file
boolean result = serialDataFile.delete();
if ( result == false )
{
getLogger().error("Unknown serialized file could not be removed");
}
}
}
catch (IOException e)
{
getLogger().error("Serialized File could not be read.", e);
// We got a corrupt file for some reason.
// Null out serialData to be sure
serialData = null;
}
catch (ClassNotFoundException e)
{
getLogger().error("Objects could not be read from serialized file.", e);
// This should not happen
// Null out serialData to be sure
serialData = null;
}
finally
{
// Could be null if we opened a file, didn't find it to be a
// Map object and then nuked it away.
try
{
if (in != null)
{
in.close();
}
}
catch (IOException e)
{
getLogger().error("Exception while closing file", e);
}
}
// Recreate transient loggers
if (serialData != null)
{
for (AppData appData : serialData.keySet())
{
for (Group group : appData.getGroups())
{
if (group instanceof LogEnabled)
{
((LogEnabled)group).enableLogging(getLogger());
}
for (Field<?> field : group.getFields())
{
if (field instanceof LogEnabled)
{
((LogEnabled)field).enableLogging(getLogger());
}
}
}
}
}
getLogger().info("Loaded serialized map object, ignoring XML");
getLogger().debug("Loading took " + (System.currentTimeMillis() - timer));
return serialData;
}