Class SchemaParser
Parses formatted (i.e., text based) schemata from a given source using the
available FormattedSchemaParser implementations, and returns the
first result. This means it can transparently handle any schema format. The
Avro project defines a JSON based format and an IDL format (the latter
available as a separate dependency), but you can also provide your own.
The parser can handle various text based sources. If the source contains a UTF encoded latin text based format it can even detect which UTF encoding was used (UTF-8, UTF16BE, UTF16LE, UTF-32BE or UTF32LE).
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreate a schema parser that validates names usingNameValidator.UTF_VALIDATOR.SchemaParser(NameValidator nameValidator) Create a schema parser with the specified name validator. -
Method Summary
Modifier and TypeMethodDescriptionGet all parsed schemata.Parse an Avro schema from a file.Parse an Avro schema from a file written with a specific character set.parse(InputStream in) Parse an Avro schema from an input stream.parse(InputStream in, Charset charset) Parse an Avro schema from an input stream.Parse an Avro schema from an input reader.parse(CharSequence text) Parse an Avro schema from a string.Parse an Avro schema from a file written with a specific character set.Parse an Avro schema from a file.Parse an Avro schema from a file written with a specific character set.static SchemaparseSingle(String schema) Use a default SchemaParser to parse a single schema.static SchemaparseSingle(Path schemaFile) Use a default SchemaParser to parse a single schema from a file.resolve(SchemaParser.ParseResult result) Deprecated.
-
Constructor Details
-
SchemaParser
public SchemaParser()Create a schema parser that validates names usingNameValidator.UTF_VALIDATOR. Initially, the list of known (named) schemata is empty. -
SchemaParser
Create a schema parser with the specified name validator.Initially, the list of known (named) schemata is empty.
Note: using
NameValidator.STRICT_VALIDATORto validate names is advised for maximum interoperability.- Parameters:
nameValidator- the name validator to use
-
-
Method Details
-
parseSingle
Use a default SchemaParser to parse a single schema. Equivalent to:
new SchemaParser().parse(schema).mainSchema()- Parameters:
schema- the formatted schema to parse- Returns:
- the parsed schema
- Throws:
SchemaParseException- when the schema is invalid- See Also:
-
parseSingle
Use a default SchemaParser to parse a single schema from a file. Equivalent to:
new SchemaParser().parse(schemaFile).mainSchema()- Parameters:
schemaFile- the formatted schema to parse- Returns:
- the parsed schema
- Throws:
SchemaParseException- when the schema is invalidIOException- See Also:
-
parse
Parse an Avro schema from a file. The file content is assumed to be UTF text.- Parameters:
file- the file to read- Returns:
- the schema
- Throws:
IOException- when the schema cannot be readSchemaParseException- if parsing the schema failed; contains suppressed underlying parse exceptions if available- See Also:
-
parse
public SchemaParser.ParseResult parse(File file, Charset charset) throws IOException, SchemaParseException Parse an Avro schema from a file written with a specific character set.- Parameters:
file- the file to readcharset- the character set of the file contents- Returns:
- the schema
- Throws:
IOException- when the schema cannot be readSchemaParseException- if parsing the schema failed; contains suppressed underlying parse exceptions if available
-
parse
Parse an Avro schema from a file. The file content is assumed to be UTF text.- Parameters:
file- the file to read- Returns:
- the schema
- Throws:
IOException- when the schema cannot be readSchemaParseException- if parsing the schema failed; contains suppressed underlying parse exceptions if available- See Also:
-
parse
public SchemaParser.ParseResult parse(Path file, Charset charset) throws IOException, SchemaParseException Parse an Avro schema from a file written with a specific character set.- Parameters:
file- the file to readcharset- the character set of the file contents- Returns:
- the schema
- Throws:
IOException- when the schema cannot be readSchemaParseException- if parsing the schema failed; contains suppressed underlying parse exceptions if available
-
parse
public SchemaParser.ParseResult parse(URI location, Charset charset) throws IOException, SchemaParseException Parse an Avro schema from a file written with a specific character set.- Parameters:
location- the location of the schema resourcecharset- the character set of the schema resource- Returns:
- the schema
- Throws:
IOException- when the schema cannot be readSchemaParseException- if parsing the schema failed; contains suppressed underlying parse exceptions if available
-
parse
Parse an Avro schema from an input stream. The stream content is assumed to be UTF text. Note that the stream stays open after reading.- Parameters:
in- the stream to read- Returns:
- the schema
- Throws:
IOException- when the schema cannot be readSchemaParseException- if parsing the schema failed; contains suppressed underlying parse exceptions if available- See Also:
-
parse
public SchemaParser.ParseResult parse(InputStream in, Charset charset) throws IOException, SchemaParseException Parse an Avro schema from an input stream. Note that the stream stays open after reading.- Parameters:
in- the stream to readcharset- the character set of the stream contents- Returns:
- the schema
- Throws:
IOException- when the schema cannot be readSchemaParseException- if parsing the schema failed; contains suppressed underlying parse exceptions if available
-
parse
Parse an Avro schema from an input reader.- Parameters:
in- the stream to read- Returns:
- the schema
- Throws:
IOException- when the schema cannot be readSchemaParseException- if parsing the schema failed; contains suppressed underlying parse exceptions if available
-
parse
Parse an Avro schema from a string.- Parameters:
text- the text to parse- Returns:
- the schema
- Throws:
SchemaParseException- if parsing the schema failed; contains suppressed underlying parse exceptions if available
-
getParsedNamedSchemas
Get all parsed schemata.- Returns:
- all parsed schemas, in the order they were parsed
-
resolve
Deprecated.
-