Package org.apache.avro
Class SchemaParser
java.lang.Object
org.apache.avro.SchemaParser
Avro schema parser for text-based formats like JSON, IDL, etc.
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
-
Constructor Summary
-
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.resolve
(SchemaParser.ParseResult result) Deprecated.
-
Constructor Details
-
SchemaParser
public SchemaParser()Create a schema parser. Initially, the list of known (named) schemata is empty.
-
-
Method Details
-
parse
Parse an Avro schema from a file. The file content is assumed to be UTF-8 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-8 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-8 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.
-