peakml.io.peakml
Class PeakMLParser

java.lang.Object
  extended by peakml.io.peakml.PeakMLParser

public class PeakMLParser
extends java.lang.Object

Central class for parsing PeakML type files. All access to the parser is handled with static access functions, so no instance should be made (and indeed can be made, as the default constructor is hidden). As a rule all access functions return an instance of the ParseResult filled with the header and peak information. Also, each of the parse-functions can be plugged with ParserProgressListener) instance, which is used to update on the progress of parsing. Only parse(InputStream, ParserProgressListener, boolean) forms the exception to these rules, as this function utilizes the PeakMLProgressListener as the mechanism to return the results to the user.

The parser defines specialized access functions to load PeakML files filled with only a single IPeak subclass (e.g. PeakMLParser#parseCentroids(InputStream, ParserProgressListener)). Use these functions with caution and only when you are sure the file in question contains only these types of peaks or you want to enforce this to be the case. When such an access-function encounters a different IPeak subclass than expected and exception is thrown.

The alternative is to use one of the parse-functions (i.e. the name of the function is parse), which will handle all types of IPeak subclasses and return the peaks as IPeak (with the class information mechanism of Java one can find out the exact type). These functions also allow you to define whether to load all data associated to an IPeak subclass, or only to load the general IPeak data. When only the data IPeak data is needed it will yield a performance boost in memory consumption.


Method Summary
static ParseResult parse(java.io.InputStream in, boolean loadall)
          Parse function for blindly loading data from a PeakML file.
static ParseResult parse(java.io.InputStream in, ParserProgressListener listener, boolean loadall)
          Parse function for blindly loading data from a PeakML file.
static void parse(java.io.InputStream in, PeakMLProgressListener listener, boolean loadall)
          Parse function for blindly loading data from a PeakML file.
static ParseResult parseBackgroundIons(java.io.InputStream in, ParserProgressListener listener)
          Parse function for loading a PeakML file containing only backgroundion entries.
static ParseResult parseIPeakSet(java.io.InputStream in, ParserProgressListener listener)
          Parse function for loading a PeakML file containing only peakset entries (containing other types of entries).
static ParseResult parseMassChromatograms(java.io.InputStream in, ParserProgressListener listener)
          Parse function for loading a PeakML file containing only masschromatogram entries.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parse

public static ParseResult parse(java.io.InputStream in,
                                boolean loadall)
                         throws java.io.IOException,
                                domsax.XmlParserException
Parse function for blindly loading data from a PeakML file. This method calls parse(InputStream, ParserProgressListener, boolean) with the parameter listener set to null.

Parameters:
in - The input-stream to load the data from.
loadall - If set to false only the data known to IPeak is loaded as class Peak.
Returns:
The header and peak information stored in the file.
Throws:
java.io.IOException - Thrown on an IOException.
domsax.XmlParserException - Thrown when an unknown IPeak object is encountered.

parse

public static ParseResult parse(java.io.InputStream in,
                                ParserProgressListener listener,
                                boolean loadall)
                         throws java.io.IOException,
                                domsax.XmlParserException
Parse function for blindly loading data from a PeakML file. This method loads the data in a PeakML file as it encounters it in the file. This means that a mix-model is essentially possible for peak-data stored in a PeakML file. The resulting ParseResult instance is parameterized with IPeak. The class-information made available through the Java language can be used to determine the original type of the peak. The function employs a callback mechanism with ParserProgressListener to return information about the progress through the file. This is calculated with the information returned by Header.getNrPeaks().

The loadall parameter can be used to restrict the amount of data actually being loaded by the function. If this is set to false only data known by the IPeak class is loaded (in this implementation this means that an instance of the Centroid is made). The class information cannot be used to determine the original type of the peak when loadall is set to false.

Parameters:
in - The input-stream to load the data from.
listener - The progress listener.
loadall - If set to false only the data known to IPeak is loaded as class Peak.
Returns:
The header and peak information stored in the file.
Throws:
java.io.IOException - Thrown on an IOException.
domsax.XmlParserException - Thrown when an unknown IPeak object is encountered.

parse

public static void parse(java.io.InputStream in,
                         PeakMLProgressListener listener,
                         boolean loadall)
                  throws java.io.IOException,
                         domsax.XmlParserException
Parse function for blindly loading data from a PeakML file. This method is essentially the same as parse(InputStream, PeakMLProgressListener, boolean) except that it uses the PeakMLProgressListener interface as a callback mechanism to return the header and peak-information. As all data is returned through this the method does not have a return-value.

Parameters:
in - The input-stream to load the data from.
listener - The parser listener, which is used as a callback mechanism to deliver header and peak information.
loadall - If set to false only the data known to IPeak is loaded as class Peak.
Throws:
java.io.IOException - Thrown on an IOException.
domsax.XmlParserException - Thrown when an unknown IPeak object is encountered.

parseMassChromatograms

public static ParseResult parseMassChromatograms(java.io.InputStream in,
                                                 ParserProgressListener listener)
                                          throws java.io.IOException,
                                                 domsax.XmlParserException
Parse function for loading a PeakML file containing only masschromatogram entries. When an entry of another type is encountered an XmlParserException is thrown. The resulting ParseResult instance is type-bound to MassChromatogram to force only masschromatogram types.

Parameters:
in - The input-stream to load the data from.
Returns:
The header and peak information stored in the file.
Throws:
java.io.IOException - Thrown on an IOException.
domsax.XmlParserException - Thrown when an unknown IPeak object is encountered.

parseBackgroundIons

public static ParseResult parseBackgroundIons(java.io.InputStream in,
                                              ParserProgressListener listener)
                                       throws java.io.IOException,
                                              domsax.XmlParserException
Parse function for loading a PeakML file containing only backgroundion entries. When an entry of another type is encountered an XmlParserException is thrown. The resulting ParseResult instance is type-bound to BackgroundIon to force only backgroundion types.

Parameters:
in - The input-stream to load the data from.
Returns:
The header and peak information stored in the file.
Throws:
java.io.IOException - Thrown on an IOException.
domsax.XmlParserException - Thrown when an unknown IPeak object is encountered.

parseIPeakSet

public static ParseResult parseIPeakSet(java.io.InputStream in,
                                        ParserProgressListener listener)
                                 throws java.io.IOException,
                                        domsax.XmlParserException
Parse function for loading a PeakML file containing only peakset entries (containing other types of entries). When an entry of another type is encountered an XmlParserException is thrown. The resulting ParseResult instance is type-bound to IPeakSet to force only peakset types.

Parameters:
in - The input-stream to load the data from.
Returns:
The header and peak information stored in the file.
Throws:
domsax.XmlParserException - Thrown when an unknown IPeak object is encountered.
java.io.IOException