|
31 | 31 | * {@link IonReader}s parse incrementally, so syntax errors in the input data |
32 | 32 | * will not be detected as side effects of any of the {@code build} methods |
33 | 33 | * in this class. |
| 34 | + * |
| 35 | + * <h2>Obtaining and Usage</h2> |
| 36 | + * An {@code IonReaderBuilder} with the default configuration may be constructed |
| 37 | + * as follows. This builder will construct {@code IonReader} instances which |
| 38 | + * can read both text and binary Ion data and is appropriate for simple use |
| 39 | + * cases or when no IonCatalog is in use. |
| 40 | + * {@snippet : |
| 41 | + * IonReaderBuilder readerBuilder = IonReaderBuilder.standard(); |
| 42 | + * } |
| 43 | + * {@code IonReaderBuilder}s can be configured by chaining calls to {@code with*()} |
| 44 | + * configuration methods. Below is an example of a builder configured to |
| 45 | + * incrementally read Ion binary data, use a custom initial buffer size, throw |
| 46 | + * on inputs that would require a buffer over a specified size, and use a |
| 47 | + * user-provided IonCatalog. |
| 48 | + * {@snippet : |
| 49 | + * // Create an IonCatalog and IonBufferConfiguration to use with IonReaderBuilder |
| 50 | + * final IonCatalog catalog = new SimpleCatalog(); |
| 51 | + * final IonBufferConfiguration bufferConfiguration = IonBufferConfiguration.Builder.standard() |
| 52 | + * .onOversizedSymbolTable(() -> { throw new IllegalStateException("Oversized system table encountered"); }) |
| 53 | + * .onOversizedValue(() -> { throw new IllegalStateException("Oversized value encountered"); }) |
| 54 | + * .withInitialBufferSize(1024) |
| 55 | + * .withMaximumBufferSize(1024 * 1024) |
| 56 | + * .build(); |
| 57 | + * |
| 58 | + * IonReaderBuilder readerBuilder = IonReaderBuilder.standard() |
| 59 | + * .withIncrementalReadingEnabled(true) |
| 60 | + * .withBufferConfiguration(bufferConfiguration) |
| 61 | + * .withCatalog(catalog); |
| 62 | + * } |
| 63 | + * |
| 64 | + * <h3>Building a Reader over a Data Source</h3> |
| 65 | + * An {@code IonReader} may be obtained from a builder by calling {@code build} |
| 66 | + * over the appropriate data source. Below is an example of a reader being constructed |
| 67 | + * over a string containing Ion text from a builder with the default configuration. |
| 68 | + * {@snippet : |
| 69 | + * IonReaderBuilder readerBuilder = IonReaderBuilder.standard(); |
| 70 | + * final String helloWorld = "{hello: \"world\"}"; |
| 71 | + * try (final IonReader reader = readerBuilder.build(helloWorld)) { |
| 72 | + * reader.next(); |
| 73 | + * reader.stepIn(); |
| 74 | + * reader.next(); |
| 75 | + * System.out.println(reader.getFieldName() + " " + reader.stringValue()); // prints "hello world" |
| 76 | + * } |
| 77 | + * } |
| 78 | + * Builders can build an IonReader over a string, {@code byte[]} array, |
| 79 | + * {@link java.io.InputStream}, {@link java.io.Reader}, or existing {@link com.amazon.ion.IonValue} |
| 80 | + * data model. Building a reader over a byte array allows specifying the start |
| 81 | + * index and length of the data to be read. Readers built over {@code byte[]} |
| 82 | + * arrays or {@code InputStream}s are capable of reading both binary and text |
| 83 | + * Ion; readers built over strings and {@code Reader} instances are only capable of |
| 84 | + * reading text Ion. |
34 | 85 | */ |
35 | 86 | @SuppressWarnings("deprecation") |
36 | 87 | public abstract class IonReaderBuilder |
|
0 commit comments