public class CasIOUtils extends Object
A collection of static methods aimed at making it easy to
TSI information can be
TS information is available embedded, for COMPRESSED_FILTERED_TS format, and also from embedded or external TSI information (since it also contains the type system information).
When an external TSI is supplied while loading Compressed Form 6,
Compressed Form 6 loading decoding type system is picked from these sources, in this order:
The serialization formats supported here are specified in the SerialFormat enum.
The load
api's automatically use the appropriate deserializers, based on the input data format.
Loading inputs may be supplied as URLs or as an appropriately buffered InputStream.
Note: you can use Files or Paths by converting these to URLs:
URL url = a_path.toUri().toURL();
URL url = a_file.toUri().toURL();
When loading, an optional CasLoadMode enum value maybe specified to indicate
For more details, see the Javadocs for CasLoadMode.
When TS or TSI information is saved, it is either saved in the same destination (e.g. file or stream), or in a separate one.
Summary of APIs for saving:
save(aCAS, outputStream, aSerialFormat)
save(aCAS, outputStream, tsiOutputStream, aSerialFormat)
Summary of APIs for loading:
load(aURL , aCas)
load(inputStream, aCas)
load(inputStream, aCas, typeSystem)
// typeSystem used for decoding Compressed Form 6load(inputStream, tsiInputStream, aCas)
load(aURL , tsiURL , aCAS, casLoadMode) - the second URL is for loading a separately-stored TSI
load(inputStream, tsiInputStream, aCAS, aCasLoadMode)
load(aURL , tsiURL , aCAS, lenient) - lenient is used to set the CasLoadMode to LENIENT or DEFAULT
load(inputStream, tsiInputStream, aCAS, lenient)
Constructor and Description |
---|
CasIOUtils() |
Modifier and Type | Method and Description |
---|---|
static SerialFormat |
load(InputStream casInputStream,
CAS aCAS)
Loads a Cas from an Input Stream.
|
static SerialFormat |
load(InputStream casInputStream,
CAS aCAS,
TypeSystem typeSystem)
This load variant can be used for loading Form 6 compressed CASes where the
type system to use to deserialize is provided as an argument.
|
static SerialFormat |
load(InputStream casInputStream,
InputStream tsiInputStream,
CAS aCAS)
Loads a CAS from an Input Stream.
|
static SerialFormat |
load(InputStream casInputStream,
InputStream tsiInputStream,
CAS aCAS,
boolean leniently)
Loads a CAS from an Input Stream.
|
static SerialFormat |
load(InputStream casInputStream,
InputStream tsiInputStream,
CAS aCAS,
CasLoadMode casLoadMode)
Loads a CAS from an Input Stream.
|
static SerialFormat |
load(URL casUrl,
CAS aCAS)
Loads a Cas from a URL source.
|
static SerialFormat |
load(URL casUrl,
URL tsiUrl,
CAS aCAS,
boolean leniently)
Loads a CAS from a URL source.
|
static SerialFormat |
load(URL casUrl,
URL tsiUrl,
CAS aCAS,
CasLoadMode casLoadMode)
Loads a CAS from a URL source.
|
static void |
save(CAS aCas,
OutputStream docOS,
OutputStream tsiOS,
SerialFormat format)
Write the CAS in the specified format.
|
static void |
save(CAS aCas,
OutputStream docOS,
SerialFormat format)
Write the CAS in the specified format.
|
static void |
writeTypeSystem(CAS aCas,
OutputStream aOS,
boolean includeIndexDefs) |
public static SerialFormat load(URL casUrl, CAS aCAS) throws IOException
casUrl
- The url containing the CASaCAS
- The CAS that should be filledIOException
- - Problem loading from given URLpublic static SerialFormat load(URL casUrl, URL tsiUrl, CAS aCAS, CasLoadMode casLoadMode) throws IOException
casUrl
- The url to deserialize the CAS fromtsiUrl
- null or an optional url to deserialize the type system and index definitions fromaCAS
- The CAS that should be filledcasLoadMode
- specifies how to handle reinitialization and lenient loading
see the Javadocs for CasLoadModeIOException
- Problem loadingpublic static SerialFormat load(URL casUrl, URL tsiUrl, CAS aCAS, boolean leniently) throws IOException
casUrl
- The url to deserialize the CAS fromtsiUrl
- The optional url to deserialize the type system and index definitions fromaCAS
- The CAS that should be filledleniently
- true means do lenient loadingIOException
- Problem loadingpublic static SerialFormat load(InputStream casInputStream, CAS aCAS) throws IOException
casInputStream
- The input stream containing the CAS. Caller should buffer this appropriately.aCAS
- The CAS that should be filledIOException
- - Problem loading from given InputStreampublic static SerialFormat load(InputStream casInputStream, InputStream tsiInputStream, CAS aCAS) throws IOException
casInputStream
- -tsiInputStream
- -aCAS
- -IOException
- -public static SerialFormat load(InputStream casInputStream, InputStream tsiInputStream, CAS aCAS, boolean leniently) throws IOException
casInputStream
- -tsiInputStream
- -aCAS
- -leniently
- -IOException
- -public static SerialFormat load(InputStream casInputStream, InputStream tsiInputStream, CAS aCAS, CasLoadMode casLoadMode) throws IOException
casInputStream
- The input stream containing the CAS, appropriately buffered.tsiInputStream
- The optional input stream containing the type system, appropriately buffered.
This is only used if it is non null and
- the casInputStream does not already come with an embedded CAS Type System and Index Definition, or
- the serial format is COMPRESSED_FILTERED_TSIaCAS
- The CAS that should be filledcasLoadMode
- specifies loading alternative like lenient and reinit, see CasLoadMode.IOException
- - Problem loading from given InputStreampublic static SerialFormat load(InputStream casInputStream, CAS aCAS, TypeSystem typeSystem) throws IOException
casInputStream
- The input stream containing the CAS, appropriately buffered.aCAS
- The CAS that should be filledtypeSystem
- the type system to use for decoding the serialized form, must be non-nullIOException
- Problem loading from given InputStreampublic static void save(CAS aCas, OutputStream docOS, SerialFormat format) throws IOException
aCas
- The CAS that should be serialized and storeddocOS
- The output stream for the CASformat
- The SerialFormat in which the CAS should be stored.IOException
- - Problem saving to the given InputStreampublic static void save(CAS aCas, OutputStream docOS, OutputStream tsiOS, SerialFormat format) throws IOException
aCas
- The CAS that should be serialized and storeddocOS
- The output stream for the CAS, with appropriate bufferingtsiOS
- Optional output stream for type system information. Only used if the format does not
support storing typesystem information directly in the main output file.format
- The SerialFormat in which the CAS should be stored.IOException
- - Problem saving to the given InputStreampublic static void writeTypeSystem(CAS aCas, OutputStream aOS, boolean includeIndexDefs) throws IOException
IOException
Copyright © 2006–2017 The Apache Software Foundation. All rights reserved.