private void parseFile(File file) { try (FileInputStream in = new FileInputStream(file); BufferedInputStream delegate = new BufferedInputStream(in); InputStream is = DocumentSources.wrap(delegate);) { currentFile = file; // Using the default expansion limit. If the ontology IRI cannot be // found before 64000 entities are expanded, the file is too // expensive to parse. SAXParsers.initParserWithOWLAPIStandards(null, "64000").parse(is, this); } catch (SAXException | IOException e) { // if we can't parse a file, then we can't map it LOGGER.debug("Exception reading file", e); } }
/** * Select the available input source and, if it is not already a Reader, wrap it in a Reader. * This method removes the duplication of code required for each caller to figure out if a * reader or an inputstream is available. The returned Reader will be buffered. * * @param source ontology source * @param configuration loader configuration to use of the reader must be built form the input * IRI * @param encoding character encoding if a new Reader needs to be created. * @return A Reader for the input; if no Reader can be obtained, an * OWLOntologyInputSourceException is thrown. * @throws OWLOntologyInputSourceException if an IO related exception is thrown. */ public static Reader wrapInputAsReader(OWLOntologyDocumentSource source, OWLOntologyLoaderConfiguration configuration, Charset encoding) throws OWLOntologyInputSourceException { Optional<Reader> reader = source.getReader(); if (reader.isPresent()) { return new BufferedReader(reader.get()); } return new BufferedReader( new InputStreamReader(wrap(wrapInput(source, configuration)), encoding)); }
/** * Select the available input source and, if it is not already a Reader, wrap it in a Reader. * This method removes the duplication of code required for each caller to figure out if a * reader or an inputstream is available. The returned Reader will be buffered. * * @param source ontology source * @param configuration loader configuration to use of the reader must be built form the input * IRI * @param encoding character encoding if a new Reader needs to be created. * @return A Reader for the input; if no Reader can be obtained, an * OWLOntologyInputSourceException is thrown. * @throws OWLOntologyInputSourceException if an IO related exception is thrown. */ public static Reader wrapInputAsReader(OWLOntologyDocumentSource source, OWLOntologyLoaderConfiguration configuration, Charset encoding) throws OWLOntologyInputSourceException { Optional<Reader> reader = source.getReader(); if (reader.isPresent()) { return new BufferedReader(reader.get()); } return new BufferedReader( new InputStreamReader(wrap(wrapInput(source, configuration)), encoding)); }
private void parseFile(File file) { try (FileInputStream in = new FileInputStream(file); BufferedInputStream delegate = new BufferedInputStream(in); InputStream is = DocumentSources.wrap(delegate);) { currentFile = file; // Using the default expansion limit. If the ontology IRI cannot be // found before 64000 entities are expanded, the file is too // expensive to parse. SAXParsers.initParserWithOWLAPIStandards(null, "64000").parse(is, this); } catch (SAXException | IOException e) { // if we can't parse a file, then we can't map it LOGGER.debug("Exception reading file", e); } }
/** * Select the available input source and, if it is not already a Reader, wrap it in a Reader. * This method removes the duplication of code required for each caller to figure out if a * reader or an inputstream is available. The returned Reader will be buffered. * * @param source ontology source * @param configuration loader configuration to use of the reader must be built form the input * IRI * @param encoding character encoding if a new Reader needs to be created. * @return A Reader for the input; if no Reader can be obtained, an * OWLOntologyInputSourceException is thrown. * @throws OWLOntologyInputSourceException if an IO related exception is thrown. */ public static Reader wrapInputAsReader(OWLOntologyDocumentSource source, OWLOntologyLoaderConfiguration configuration, Charset encoding) throws OWLOntologyInputSourceException { Optional<Reader> reader = source.getReader(); if (reader.isPresent()) { return new BufferedReader(reader.get()); } return new BufferedReader( new InputStreamReader(wrap(wrapInput(source, configuration)), encoding)); }
private void parseFile(File file) { try (FileInputStream in = new FileInputStream(file); BufferedInputStream delegate = new BufferedInputStream(in); InputStream is = DocumentSources.wrap(delegate);) { currentFile = file; // Using the default expansion limit. If the ontology IRI cannot be // found before 64000 entities are expanded, the file is too // expensive to parse. SAXParsers.initParserWithOWLAPIStandards(null, "64000").parse(is, this); } catch (SAXException | IOException e) { // if we can't parse a file, then we can't map it LOGGER.debug("Exception reading file", e); } }
@Override public Optional<Reader> getReader() { if (streamAvailable) { return emptyOptional(); } try { return optional(new InputStreamReader( DocumentSources.wrap(new GZIPInputStream(new ByteArrayInputStream( byteBuffer))), encoding)); } catch (IOException e) { LOGGER.error("Buffer cannot be opened", e); failedOnStreams.set(true); return emptyOptional(); } } }
@Override public Optional<Reader> getReader() { if (streamAvailable) { return emptyOptional(); } try { return optional(new InputStreamReader( DocumentSources.wrap(new GZIPInputStream(new ByteArrayInputStream( byteBuffer))), encoding)); } catch (IOException e) { LOGGER.error("Buffer cannot be opened", e); failedOnStreams.set(true); return emptyOptional(); } } }
@Override public Optional<Reader> getReader() { if (streamAvailable) { return emptyOptional(); } try { return optional(new InputStreamReader( DocumentSources.wrap(new GZIPInputStream(new ByteArrayInputStream( byteBuffer))), encoding)); } catch (IOException e) { LOGGER.error("Buffer cannot be opened", e); failedOnStreams.set(true); return emptyOptional(); } } }
private static InputStream getInputStreamFromContentEncoding(URLConnection conn, @Nullable String contentEncoding) throws IOException { InputStream in = conn.getInputStream(); if (contentEncoding != null) { InputStream toReturn = handleKnownContentEncodings(contentEncoding, in); if (toReturn != null) { return toReturn; } } String fileName = getFileNameFromContentDisposition(conn); if (fileName == null && conn.getURL() != null) { fileName = conn.getURL().toString(); } if (fileName != null) { if (fileName.endsWith(".gz")) { LOGGER.info("URL connection has no content encoding but name ends with .gz"); return new BufferedInputStream(new GZIPInputStream(in)); } if (fileName.endsWith(".xz")) { LOGGER.info("URL connection has no content encoding but name ends with .xz"); return new BufferedInputStream(new XZInputStream(in)); } } return wrap(in); }
private static InputStream getInputStreamFromContentEncoding(URLConnection conn, @Nullable String contentEncoding) throws IOException { InputStream in = conn.getInputStream(); if (contentEncoding != null) { InputStream toReturn = handleKnownContentEncodings(contentEncoding, in); if (toReturn != null) { return toReturn; } } String fileName = getFileNameFromContentDisposition(conn); if (fileName == null && conn.getURL() != null) { fileName = conn.getURL().toString(); } if (fileName != null) { if (fileName.endsWith(".gz")) { LOGGER.info("URL connection has no content encoding but name ends with .gz"); return new BufferedInputStream(new GZIPInputStream(in)); } if (fileName.endsWith(".xz")) { LOGGER.info("URL connection has no content encoding but name ends with .xz"); return new BufferedInputStream(new XZInputStream(in)); } } return wrap(in); }
private static InputStream getInputStreamFromContentEncoding(URLConnection conn, @Nullable String contentEncoding) throws IOException { InputStream in = conn.getInputStream(); if (contentEncoding != null) { InputStream toReturn = handleKnownContentEncodings(contentEncoding, in); if (toReturn != null) { return toReturn; } } String fileName = getFileNameFromContentDisposition(conn); if (fileName == null && conn.getURL() != null) { fileName = conn.getURL().toString(); } if (fileName != null) { if (fileName.endsWith(".gz")) { LOGGER.info("URL connection has no content encoding but name ends with .gz"); return new BufferedInputStream(new GZIPInputStream(in)); } if (fileName.endsWith(".xz")) { LOGGER.info("URL connection has no content encoding but name ends with .xz"); return new BufferedInputStream(new XZInputStream(in)); } } return wrap(in); }