Package com.luciad.format.xml.util
Class TLcdXMLPeeker
java.lang.Object
com.luciad.format.xml.util.TLcdXMLPeeker
- All Implemented Interfaces:
ILcdInputStreamFactoryCapable
Allows to quickly determine the type of an XML file without consuming the input stream.
This can be used, for example, to choose a XML decoder for a data source or to implement a
canDecode
method.
Example usage:
String namespaceURI = TLcdXMLPeeker.decodeRootElementName(inputStream).getNamespaceURI();
if (myNamespaceV1.equals(namespaceURI)) {
return myDecoderV1.decode(inputStream);
} else if (myNamespaceV2.equals(namespaceURI)) {
return myDecoderV2.decode(inputStream);
} else {
...
}
The used ILcdInputStreamFactory
must create streams that support marking
(most buffered input streams do). If not, an exception is thrown.
- Since:
- 2017.1
-
Constructor Summary
ConstructorDescriptionCreates a new peeker.TLcdXMLPeeker
(ILcdInputStreamFactory aFactory) Creates a new peeker that uses the given input stream factory. -
Method Summary
Modifier and TypeMethodDescriptionstatic QName
decodeRootElementName
(InputStream aInputStream) Decodes the name of the root element in the given input stream.decodeRootElementName
(String aSource) Decodes the name of the root element in the given source.Returns the input stream factory that is used.void
setInputStreamFactory
(ILcdInputStreamFactory aInputStreamFactory) Sets the input stream factory to be used.
-
Constructor Details
-
TLcdXMLPeeker
public TLcdXMLPeeker()Creates a new peeker. -
TLcdXMLPeeker
Creates a new peeker that uses the given input stream factory.- Parameters:
aFactory
- the factory to use when decoding a source
-
-
Method Details
-
decodeRootElementName
Decodes the name of the root element in the given source.- Parameters:
aSource
- the source file to peek into- Returns:
- the name of the root element in the source
- Throws:
IOException
-
decodeRootElementName
Decodes the name of the root element in the given input stream.- Parameters:
aInputStream
- the stream to peek into. The stream must supportmarking
.- Returns:
- the name of the root element in the source
- Throws:
IllegalArgumentException
- if the input stream does not support markingIOException
-
setInputStreamFactory
Sets the input stream factory to be used. The factory must create streams that supportmarking
(most buffered input streams do).- Specified by:
setInputStreamFactory
in interfaceILcdInputStreamFactoryCapable
- Parameters:
aInputStreamFactory
- the input stream factory to be used.
-
getInputStreamFactory
Description copied from interface:ILcdInputStreamFactoryCapable
Returns the input stream factory that is used.- Specified by:
getInputStreamFactory
in interfaceILcdInputStreamFactoryCapable
- Returns:
- the input stream factory that is used.
-