Search in sources :

Example 1 with XStreamException

use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.

the class SettingsManager method unsafeLoadSettings.

/**
	 * Load the settings from the input stream. The stream will be closed.
	 * <p>
	 * If this fails then an error message is written to the ImageJ log
	 *
	 * @param inputStream
	 *            the input stream
	 * @param silent
	 *            Set to true to suppress writing an error message to the ImageJ log
	 * @return The settings (or null)
	 */
public static GlobalSettings unsafeLoadSettings(InputStream inputStream, boolean silent) {
    XStream xs = createXStream();
    GlobalSettings config = null;
    try {
        config = (GlobalSettings) xs.fromXML(inputStream);
    } catch (ClassCastException ex) {
    //ex.printStackTrace();
    } catch (XStreamException ex) {
        ex.printStackTrace();
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if (config == null)
        if (!silent)
            IJ.log("Unable to load settings from input stream");
    return config;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream) IOException(java.io.IOException)

Example 2 with XStreamException

use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.

the class SettingsManager method saveSettings.

/**
	 * Save the settings to file.
	 * <p>
	 * If this fails then an error message is written to the ImageJ log
	 *
	 * @param settings
	 *            the settings
	 * @param filename
	 *            the filename
	 * @param silent
	 *            Set to true to suppress writing an error message to the ImageJ log
	 * @return True if saved
	 */
public static boolean saveSettings(GlobalSettings settings, String filename, boolean silent) {
    XStream xs = createXStream();
    FileOutputStream fs = null;
    try {
        fs = new FileOutputStream(filename);
        xs.toXML(settings, fs);
        return true;
    } catch (FileNotFoundException ex) {
    //ex.printStackTrace();
    } catch (XStreamException ex) {
        ex.printStackTrace();
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (!silent)
        IJ.log("Unable to save settings to: " + filename);
    return false;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 3 with XStreamException

use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.

the class SettingsManager method unsafeLoadSettings.

/**
	 * Load the settings within the specified file
	 * <p>
	 * If this fails then an error message is written to the ImageJ log
	 * 
	 * @param filename
	 * @param silent
	 *            Set to true to suppress writing an error message to the ImageJ log
	 * @return The settings (or null)
	 */
public static GlobalSettings unsafeLoadSettings(String filename, boolean silent) {
    XStream xs = createXStream();
    GlobalSettings config = null;
    FileInputStream fs = null;
    try {
        fs = new FileInputStream(filename);
        config = (GlobalSettings) xs.fromXML(fs);
    } catch (ClassCastException ex) {
    //ex.printStackTrace();
    } catch (FileNotFoundException ex) {
    //ex.printStackTrace();
    } catch (XStreamException ex) {
        ex.printStackTrace();
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (config == null)
        if (!silent)
            IJ.log("Unable to load settings from: " + filename);
    return config;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 4 with XStreamException

use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.

the class SettingsManager method saveFitEngineConfiguration.

/**
	 * Save the configuration to file
	 * 
	 * @param config
	 * @param filename
	 * @return True if saved
	 */
public static boolean saveFitEngineConfiguration(FitEngineConfiguration config, String filename) {
    XStream xs = createXStream();
    FileOutputStream fs = null;
    try {
        fs = new FileOutputStream(filename);
        xs.toXML(config, fs);
        return true;
    } catch (FileNotFoundException ex) {
    //ex.printStackTrace();
    } catch (XStreamException ex) {
        ex.printStackTrace();
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return false;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 5 with XStreamException

use of com.thoughtworks.xstream.XStreamException in project GDSC-SMLM by aherbert.

the class BatchPeakFit method loadSettings.

private BatchSettings loadSettings(String configurationFilename) {
    BatchSettings settings = null;
    FileInputStream fs = null;
    try {
        fs = new FileInputStream(configurationFilename);
        settings = (BatchSettings) xs.fromXML(fs);
    } catch (ClassCastException ex) {
    //ex.printStackTrace();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (XStreamException ex) {
        ex.printStackTrace();
    } finally {
        if (fs != null) {
            try {
                fs.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return settings;
}
Also used : XStreamException(com.thoughtworks.xstream.XStreamException) BatchSettings(gdsc.smlm.ij.settings.BatchSettings) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

XStreamException (com.thoughtworks.xstream.XStreamException)25 XStream (com.thoughtworks.xstream.XStream)13 IOException (java.io.IOException)13 FileNotFoundException (java.io.FileNotFoundException)9 FileOutputStream (java.io.FileOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 FitEngineConfiguration (gdsc.smlm.engine.FitEngineConfiguration)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)2 QNameMap (com.thoughtworks.xstream.io.xml.QNameMap)2 StaxReader (com.thoughtworks.xstream.io.xml.StaxReader)2 Metacard (ddf.catalog.data.Metacard)2 StringReader (java.io.StringReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Response (javax.ws.rs.core.Response)2