org.yaml.snakeyaml.scanner.ScannerException的实例源码

项目:jpa-unit    文件YamlDataSetProducerTest.java   
@Test
public void testProduceDataSetUsingNotYamlStream() throws DataSetException {
    // GIVEN
    final IDataSetConsumer consumer = mock(IDataSetConsumer.class);
    final IDataSetProducer producer = new YamlDataSetProducer(jsonStream);
    producer.setConsumer(consumer);

    // WHEN
    try {
        producer.produce();
        fail("DataSetException expected");
    } catch (final DataSetException e) {
        // THEN
        assertthat(e.getCause(),instanceOf(ScannerException.class));
    }
}
项目:NovaGuilds    文件MessageManager.java   
/**
 * Loads messages
 *
 * @throws FatalNovaGuildsException when something goes wrong
 */
public void load() throws FatalNovaGuildsException {
    setupDirectories();

    try {
        detectLanguage();
        messages = Lang.loadConfiguration(messagesFile);

        //Fork,edit and compile NovaGuilds on your own if you want not to use the original prefix
        restorePrefix();

        prefix = Message.CHAT_PREFIX.get();
        prefixColor = ChatColor.getByChar(ChatColor.getLastColors(prefix).charat(1));

        LoggerUtils.info("Messages loaded: " + Config.LANG_NAME.getString());
    }
    catch(ScannerException | IOException e) {
        throw new FatalNovaGuildsException("Failed to load messages",e);
    }
}
项目:cloud-slang    文件ParserExceptionHandler.java   
public String getErrorMessage(Throwable e) {
    String errorMessage = e.getMessage();
    if (e instanceof ScannerException &&
            (errorMessage.startsWith(MAPPING_VALUES_NOT_ALLOWED_HERE_ERROR) ||
                    errorMessage.startsWith(SCANNING_A_SIMPLE_KEY_ERROR))) {
        errorMessage += KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG;
    } else if (e instanceof ConstructorException && errorMessage.startsWith(CANNOT_CREATE_PROPERTY_ERROR)) {
        if (errorMessage.contains(UNABLE_TO_FIND_PROPERTY_ERROR)) {
            //parse for undefined property name
            String truncatedErrorMessage = errorMessage.substring(errorMessage.indexOf(TruncATION_BEGINNING),errorMessage.indexOf(TruncATION_END));
            String undefinedProperty = truncatedErrorMessage.substring(truncatedErrorMessage.indexOf("\'") + 1,truncatedErrorMessage.lastIndexOf("\'"));
            errorMessage += "Property \'" + undefinedProperty + "\' is not supported by CloudSlang. Check that \'" +
                    undefinedProperty + "\' is indented properly.";

        } else if (errorMessage.contains(MAP_CONSTRUCTOR_NOT_FOUND_ERROR)) {
            errorMessage += KEY_VALUE_PAIR_MISSING_OR_INDENTATION_PROBLEM_MSG;
        }
    }
    return errorMessage;
}
项目:spring4-understanding    文件YamlProcessorTests.java   
@Test
public void testBadResource() throws Exception {
    this.processor.setResources(new ByteArrayResource(
            "foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
    this.exception.expect(ScannerException.class);
    this.exception.expectMessage("line 3,column 1");
    this.processor.process(new MatchCallback() {
        @Override
        public void process(Properties properties,Map<String,Object> map) {
        }
    });
}
项目:spring4-understanding    文件YamlPropertiesfactorybeanTests.java   
@Test
public void testBadResource() throws Exception {
    YamlPropertiesfactorybean factory = new YamlPropertiesfactorybean();
    factory.setResources(new ByteArrayResource(
            "foo: bar\ncd\nspam:\n  foo: baz".getBytes()));
    this.exception.expect(ScannerException.class);
    this.exception.expectMessage("line 3,column 1");
    factory.getobject();
}
项目:appengine-plugins-core    文件CloudSdkAppEngineFlexibleStaging.java   
@VisibleForTesting
static String findRuntime(StageFlexibleConfiguration config) throws IOException {
  try {
    // verification for app.yaml that contains runtime:java
    Path appYaml = config.getAppEngineDirectory().toPath().resolve(APP_YAML);
    return new AppYaml(appYaml).getRuntime();
  } catch (ScannerException | ParserException ex) {
    throw new AppEngineException("Malformed 'app.yaml'.",ex);
  }
}
项目:cfg4j    文件YamlBasedPropertiesProvider.java   
/**
 * Get {@link Properties} for a given {@code inputStream} treating it as a YAML file.
 *
 * @param inputStream input stream representing YAML file
 * @return properties representing values from {@code inputStream}
 * @throws IllegalStateException when unable to read properties
 */
@Override
public Properties getProperties(InputStream inputStream) {
  requireNonNull(inputStream);

  Yaml yaml = new Yaml();

  Properties properties = new Properties();

  try (Reader reader = new UnicodeReader(inputStream)) {

    Object object = yaml.load(reader);

    if (object != null) {
      Map<String,Object> yamlAsMap = convertToMap(object);
      properties.putAll(flatten(yamlAsMap));
    }

    return properties;

  } catch (IOException | ScannerException e) {
    throw new IllegalStateException("Unable to load yaml configuration from provided stream",e);
  }
}
项目:google-cloud-intellij    文件DefaultAppEngineProjectService.java   
/**
 * Returns the value of a key-value pair for a given {@code key},on the file located at {@code
 * appYamlPathString}.
 *
 * @return a String with the value,or an empty Optional if app.yaml isn't a regular file,or if
 *     there is any error getting the value
 * @throws MalformedYamlFileException when an app.yaml isn't syntactically well formed
 */
private Optional<String> getValueFromAppYaml(
    @NotNull String appYamlPathString,@NotNull String key) throws MalformedYamlFileException {
  Yaml yamlParser = new Yaml();

  Path appYamlPath = Paths.get(appYamlPathString);
  if (!Files.isRegularFile(appYamlPath)) {
    return Optional.empty();
  }

  try (BufferedReader reader = Files.newBufferedReader(appYamlPath,Charset.defaultCharset())) {
    Object parseResult = yamlParser.load(reader);

    if (!(parseResult instanceof Map)) {
      return Optional.empty();
    }

    // It's possible to get rid of this unchecked cast using a loadAs(file,// AppEngineYamlWebApp.class) sort of approach.
    Map<String,String> yamlMap = (Map<String,String>) parseResult;

    return yamlMap.containsKey(key) ? Optional.of(yamlMap.get(key)) : Optional.empty();
  } catch (ScannerException se) {
    throw new MalformedYamlFileException(se);
  } catch (InvalidpathException | IOException ioe) {
    return Optional.empty();
  }
}
项目:karamel    文件ClusterDeFinitionService.java   
public static YamlCluster yamlToYamlObject(String ymlString) throws KaramelException {
  try {
    Yaml yaml = new Yaml(new Constructor(YamlCluster.class));
    Object document = yaml.load(ymlString);
    return ((YamlCluster) document);
  } catch (ScannerException ex) {
    throw new KaramelException("Syntax error in the yaml!!",ex);
  }
}
项目:halyard    文件ParseConfigException.java   
public ParseConfigException(ScannerException e) {
  Problem problem = new ConfigProblemBuilder(Problem.Severity.FATAL,"Could not parse your halconfig: " + e.getMessage()).build();
  getProblems().add(problem);
}
项目:restcommander    文件YAMLException.java   
public YAMLException(ScannerException e,VirtualFile yaml) {
    super(e.getMessage() + " (in file " + yaml.relativePath() + " line " + (e.getProblemmark().getLine() + 1) + ",column " + (e.getProblemmark().getColumn() + 1) + ")",e);
    this.e = e;
    this.yaml = yaml;
}

相关文章

买水果
比较全面的redis工具类
gson 反序列化到多态子类
java 版本的 mb_strwidth
JAVA 反转字符串的最快方法,大概比StringBuffer.reverse()性...
com.google.gson.internal.bind.ArrayTypeAdapter的实例源码...