public static SchemaDescription parseInputStream(final InputStream input, String description) throws SchemaException { if (input == null) { throw new NullPointerException("Input stream must not be null"); } SchemaDescriptionImpl desc = new SchemaDescriptionImpl("inputStream " + description); desc.path = null; desc.streamable = () -> input; desc.parseFromInputStream(); return desc; }
public static SchemaDescription parseNode(Node node, String sourceDescription) throws SchemaException { SchemaDescriptionImpl desc = new SchemaDescriptionImpl(sourceDescription); desc.node = node; desc.fetchBasicInfoFromSchema(); return desc; }
public static SchemaDescription parseResource(final String resourcePath) throws SchemaException { SchemaDescriptionImpl desc = new SchemaDescriptionImpl("system resource "+resourcePath); desc.path = resourcePath; desc.streamable = new InputStreamable() { @Override public InputStream openInputStream() { InputStream inputStream = SchemaRegistry.class.getClassLoader().getResourceAsStream(resourcePath); if (inputStream == null) { throw new IllegalStateException("Cannot fetch system resource for schema " + resourcePath); } return inputStream; } }; desc.parseFromInputStream(); return desc; }
public static SchemaDescription parseFile(final File file) throws FileNotFoundException, SchemaException { SchemaDescriptionImpl desc = new SchemaDescriptionImpl("file "+file.getPath()); desc.path = file.getPath(); desc.streamable = new InputStreamable() { @Override public InputStream openInputStream() { InputStream inputStream; try { inputStream = new FileInputStream(file); } catch (FileNotFoundException e) { throw new IllegalStateException("Cannot fetch file for schema " + file,e); } return inputStream; } }; desc.parseFromInputStream(); return desc; }
SchemaDescriptionImpl desc = new SchemaDescriptionImpl("schema #" + (number++) + " in system resource " + resourcePath); desc.node = schemaElement; desc.fetchBasicInfoFromSchema();