[Home] DMelt member access. Java source code: kcl.waterloo.xml.GJDecoder
/*
* This code is part of Project Waterloo from King's College London
*
*
* Copyright King's College London 2012-
*
* @author Malcolm Lidierth, King's College London [Contact]
*
* Project Waterloo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Project Waterloo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
*/
package kcl.waterloo.xml;
import java.awt.Component;
import java.awt.Dimension;
import java.beans.ExceptionListener;
import java.beans.XMLDecoder;
import java.io.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.zip.GZIPInputStream;
import javax.swing.SwingWorker;
import kcl.waterloo.defaults.GJDefaults;
import kcl.waterloo.graphics.GJAbstractGraphContainer;
import kcl.waterloo.logging.CommonLogger;
/**
* Static library for deserializing the Waterloo xml files. Any changes here
* need to be tested for backwards compatibility.
*
* @author Malcolm Lidierth, King's College London [Contact]
*/
public class GJDecoder {
private static Class defaultVectorClass = GJDefaults.getDataClass();
private static LinkedHashMap defaultMap = GJDefaults.getMap();
private static boolean updateMessage = false;
private static final CommonLogger logger = new CommonLogger(GJDecoder.class);
private static String fileToLoad = "";
/**
* @return the defaultMap
*/
protected static LinkedHashMap getDefaultMap() {
return defaultMap;
}
private GJDecoder() {
}
static InputStream createInputStream(String fileName) {
BufferedInputStream buffer;
try {
int dotPos = fileName.lastIndexOf(".");
String extension = fileName.substring(dotPos);
FileInputStream input = new FileInputStream(fileName);
buffer = new BufferedInputStream(input);
fileToLoad = fileName;
if (extension.equalsIgnoreCase(".gz")) {
try {
return new GZIPInputStream(buffer);
} catch (IOException ex) {
logger.error(ex.getMessage());
}
} else {
return buffer;
}
} catch (FileNotFoundException ex) {
logger.error(ex.getMessage());
}
return null;
}
public static Object load(String fileName) {
fileToLoad = fileName;
return load(fileName, createInputStream(fileName));
}
/**
* Returns the graphics data from the specified file.
*
* @param fileName the name of the file to load
* @param stream the InputStream for the file
* @return the loaded Object
*/
@SuppressWarnings("unchecked")
public static Object load(final String fileName, final InputStream stream) {
if (fileName.isEmpty()) {
fileToLoad = "Unknown source";
} else {
fileToLoad = fileName;
}
updateMessage = true;
SwingWorker