Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DC333200CD1 for ; Wed, 12 Jul 2017 03:33:40 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id DADF1167B18; Wed, 12 Jul 2017 01:33:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2BF94167B17 for ; Wed, 12 Jul 2017 03:33:40 +0200 (CEST) Received: (qmail 50476 invoked by uid 500); 12 Jul 2017 01:33:39 -0000 Mailing-List: contact dev-help@any23.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@any23.apache.org Delivered-To: mailing list dev@any23.apache.org Received: (qmail 50465 invoked by uid 99); 12 Jul 2017 01:33:39 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Jul 2017 01:33:39 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id DC84D192386 for ; Wed, 12 Jul 2017 01:33:38 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id Gmh1oTctmKFr for ; Wed, 12 Jul 2017 01:33:37 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id C26F9629A6 for ; Tue, 11 Jul 2017 23:05:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id D20B1E0D9E for ; Tue, 11 Jul 2017 23:05:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 3FF8A246FE for ; Tue, 11 Jul 2017 23:05:00 +0000 (UTC) Date: Tue, 11 Jul 2017 23:05:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@any23.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (ANY23-308) Adding option "-d" to yaml file parsing gives error MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 12 Jul 2017 01:33:41 -0000 [ https://issues.apache.org/jira/browse/ANY23-308?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16083143#comment-16083143 ] ASF GitHub Bot commented on ANY23-308: -------------------------------------- Github user ansell commented on a diff in the pull request: https://github.com/apache/any23/pull/42#discussion_r126829476 --- Diff: utils/src/main/java/org/apache/any23/extractor/yaml/YAMLValidator.java --- @@ -0,0 +1,105 @@ +/* + * Copyright 2017 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.any23.extractor.yaml; + +import com.google.common.collect.Iterables; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Scanner; +import java.util.regex.Pattern; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + +/** + * Utility class provides static methods for YAML validation. + * + * @author Jacek Grzebyta (grzebyta.dev [at] gmail.com) + */ +public class YAMLValidator { + + private static final Logger log = LoggerFactory.getLogger(YAMLValidator.class); + + private static final Pattern YAML_PATTERN = Pattern.compile("^%YAML.*", Pattern.CASE_INSENSITIVE); + + /** + * Detects if is contains valid YAML content. + *

+ * In the first instance it checks if there is "%YAML" head. If not check + * using the brute force method by parsing input stream with yaml parser. + *

+ *

+ * NB. Only "false" results are trusted. Even if result is "true" you cannot + * be sure that InputStream contains YAML intentional context because + * comma-separated-values are pars-able by YAML parser as well. + *

+ * + * @param is {@link InputStream} + * @return + * @throws IOException + */ + public static boolean isYAML(InputStream is) throws IOException { + if (is == null) { + return false; + } + + if (!is.markSupported()) { + is = new BufferedInputStream(is); + } + + boolean result = false; --- End diff -- A variable isn't a great idea in the default false case, as you can simply return true whenever you decide it is try (and rely on try-finally to cleanup), and then return false at the end of the method. > Adding option "-d" to yaml file parsing gives error > --------------------------------------------------- > > Key: ANY23-308 > URL: https://issues.apache.org/jira/browse/ANY23-308 > Project: Apache Any23 > Issue Type: Bug > Components: rover > Affects Versions: 2.0 > Reporter: Jacek > Assignee: Jacek > Priority: Minor > Fix For: 2.1 > > > Command > {code:none} > any23 rover -e yaml -d "urn:test#" -f turtle some_yaml_file.yaml > {code} > gives `No suitable extractors found`. -- This message was sent by Atlassian JIRA (v6.4.14#64029)