Package org.apache.avro

# Class SchemaParser

java.lang.Object
org.apache.avro.SchemaParser

public class SchemaParser extends Object
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:
  - `FormattedSchemaParser`
  - `UtfTextUtils`

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static interface`
`SchemaParser.ParseResult`

## Constructor Summary

Constructors
Constructor
Description
`SchemaParser()`
Create a schema parser.

## Method Summary

Modifier and Type
Method
Description
`List<Schema>`
`getParsedNamedSchemas()`
Get all parsed schemata.
`SchemaParser.ParseResult`
`parse(File file)`
Parse an Avro schema from a file.
`SchemaParser.ParseResult`
`parse(File file, Charset charset)`
Parse an Avro schema from a file written with a specific character set.
`SchemaParser.ParseResult`
`parse(InputStream in)`
Parse an Avro schema from an input stream.
`SchemaParser.ParseResult`
`parse(InputStream in, Charset charset)`
Parse an Avro schema from an input stream.
`SchemaParser.ParseResult`
`parse(Reader in)`
Parse an Avro schema from an input reader.
`SchemaParser.ParseResult`
`parse(CharSequence text)`
Parse an Avro schema from a string.
`SchemaParser.ParseResult`
`parse(URI location, Charset charset)`
Parse an Avro schema from a file written with a specific character set.
`SchemaParser.ParseResult`
`parse(Path file)`
Parse an Avro schema from a file.
`SchemaParser.ParseResult`
`parse(Path file, Charset charset)`
Parse an Avro schema from a file written with a specific character set.
`Schema`
`resolve(SchemaParser.ParseResult result)`
Deprecated.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### SchemaParser

public SchemaParser()
Create a schema parser. Initially, the list of known (named) schemata is empty.

## Method Details

### parse

public SchemaParser.ParseResult parse(File file) throws IOException, SchemaParseException
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 read
  `SchemaParseException` - if parsing the schema failed; contains suppressed underlying parse exceptions if available
See Also:
  - `UtfTextUtils`

### 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 read
  `charset` - the character set of the file contents
Returns:
  the schema
Throws:
  `IOException` - when the schema cannot be read
  `SchemaParseException` - if parsing the schema failed; contains suppressed underlying parse exceptions if available

### parse

public SchemaParser.ParseResult parse(Path file) throws IOException, SchemaParseException
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 read
  `SchemaParseException` - if parsing the schema failed; contains suppressed underlying parse exceptions if available
See Also:
  - `UtfTextUtils`

### 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 read
  `charset` - the character set of the file contents
Returns:
  the schema
Throws:
  `IOException` - when the schema cannot be read
  `SchemaParseException` - 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 resource
  `charset` - the character set of the schema resource
Returns:
  the schema
Throws:
  `IOException` - when the schema cannot be read
  `SchemaParseException` - if parsing the schema failed; contains suppressed underlying parse exceptions if available

### parse

public SchemaParser.ParseResult parse(InputStream in) throws IOException, SchemaParseException
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 read
  `SchemaParseException` - if parsing the schema failed; contains suppressed underlying parse exceptions if available
See Also:
  - `UtfTextUtils`

### 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 read
  `charset` - the character set of the stream contents
Returns:
  the schema
Throws:
  `IOException` - when the schema cannot be read
  `SchemaParseException` - if parsing the schema failed; contains suppressed underlying parse exceptions if available

### parse

public SchemaParser.ParseResult parse(Reader in) throws IOException, SchemaParseException
Parse an Avro schema from an input reader.

Parameters:
  `in` - the stream to read
Returns:
  the schema
Throws:
  `IOException` - when the schema cannot be read
  `SchemaParseException` - if parsing the schema failed; contains suppressed underlying parse exceptions if available

### parse

public SchemaParser.ParseResult parse(CharSequence text) throws SchemaParseException
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

public List<Schema> getParsedNamedSchemas()
Get all parsed schemata.

Returns:
  all parsed schemas, in the order they were parsed

### resolve

@Deprecated public Schema resolve(SchemaParser.ParseResult result)
Deprecated.