org.redisson.config.Config.fromJSON()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(288)

本文整理了Java中org.redisson.config.Config.fromJSON()方法的一些代码示例,展示了Config.fromJSON()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.fromJSON()方法的具体详情如下:
包路径:org.redisson.config.Config
类名称:Config
方法名:fromJSON

Config.fromJSON介绍

[英]Read config object stored in JSON format from File
[中]从File读取JSON格式存储的配置对象

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Read config object stored in JSON format from <code>File</code>
 *
 * @param file object
 * @return config
 * @throws IOException error
 */
public static Config fromJSON(File file) throws IOException {
  return fromJSON(file, null);
}

代码示例来源:origin: redisson/redisson

/**
 * Read config object stored in JSON format from <code>File</code>
 *
 * @param file object
 * @return config
 * @throws IOException error
 */
public static Config fromJSON(File file) throws IOException {
  return fromJSON(file, null);
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(String configPath) {
  try {
    return Config.fromJSON(new File(configPath));
  } catch (IOException e) {
    // trying next format
    try {
      return Config.fromYAML(new File(configPath));
    } catch (IOException e1) {
      throw new CacheException("Can't parse default yaml config", e1);
    }
  }
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(String configPath) {
  try {
    return Config.fromJSON(new File(configPath));
  } catch (IOException e) {
    // trying next format
    try {
      return Config.fromYAML(new File(configPath));
    } catch (IOException e1) {
      throw new CacheException("Can't parse default yaml config", e1);
    }
  }
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(String configPath) {
  try {
    return Config.fromJSON(new File(configPath));
  } catch (IOException e) {
    // trying next format
    try {
      return Config.fromYAML(new File(configPath));
    } catch (IOException e1) {
      throw new CacheException("Can't parse default yaml config", e1);
    }
  }
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(String configPath) {
  try {
    return Config.fromJSON(new File(configPath));
  } catch (IOException e) {
    // trying next format
    try {
      return Config.fromYAML(new File(configPath));
    } catch (IOException e1) {
      throw new CacheException("Can't parse default yaml config", e1);
    }
  }
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(ClassLoader classLoader, String fileName) {
  InputStream is = classLoader.getResourceAsStream(fileName);
  if (is != null) {
    try {
      return Config.fromJSON(is);
    } catch (IOException e) {
      try {
        is = classLoader.getResourceAsStream(fileName);
        return Config.fromYAML(is);
      } catch (IOException e1) {
        throw new CacheException("Can't parse yaml config", e1);
      }
    }
  }
  return null;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(URI uri) {
  Config config = null;
  try {
    URL jsonUrl = null;
    if (DEFAULT_URI_PATH.equals(uri.getPath())) {
      jsonUrl = JCachingProvider.class.getResource("/redisson-jcache.json");
    } else {
      jsonUrl = uri.toURL();
    }
    if (jsonUrl == null) {
      throw new IOException();
    }
    config = Config.fromJSON(jsonUrl);
  } catch (IOException e) {
    try {
      URL yamlUrl = null;
      if (DEFAULT_URI_PATH.equals(uri.getPath())) {
        yamlUrl = JCachingProvider.class.getResource("/redisson-jcache.yaml");
      } else {
        yamlUrl = uri.toURL();
      }
      if (yamlUrl != null) {
        config = Config.fromYAML(yamlUrl);
      }
    } catch (IOException e2) {
      // skip
    }
  }
  return config;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(ClassLoader classLoader, String fileName) {
  InputStream is = classLoader.getResourceAsStream(fileName);
  if (is != null) {
    try {
      return Config.fromJSON(is);
    } catch (IOException e) {
      try {
        is = classLoader.getResourceAsStream(fileName);
        return Config.fromYAML(is);
      } catch (IOException e1) {
        throw new CacheException("Can't parse yaml config", e1);
      }
    }
  }
  return null;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(ClassLoader classLoader, String fileName) {
  InputStream is = classLoader.getResourceAsStream(fileName);
  if (is != null) {
    try {
      return Config.fromJSON(is);
    } catch (IOException e) {
      try {
        is = classLoader.getResourceAsStream(fileName);
        return Config.fromYAML(is);
      } catch (IOException e1) {
        throw new CacheException("Can't parse yaml config", e1);
      }
    }
  }
  return null;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(ClassLoader classLoader, String fileName) {
  InputStream is = classLoader.getResourceAsStream(fileName);
  if (is != null) {
    try {
      return Config.fromJSON(is);
    } catch (IOException e) {
      try {
        is = classLoader.getResourceAsStream(fileName);
        return Config.fromYAML(is);
      } catch (IOException e1) {
        throw new CacheException("Can't parse yaml config", e1);
      }
    }
  }
  return null;
}

代码示例来源:origin: redisson/redisson

private Config loadConfig(URI uri) {
  Config config = null;
  try {
    URL jsonUrl = null;
    if (DEFAULT_URI_PATH.equals(uri.getPath())) {
      jsonUrl = JCachingProvider.class.getResource("/redisson-jcache.json");
    } else {
      jsonUrl = uri.toURL();
    }
    if (jsonUrl == null) {
      throw new IOException();
    }
    config = Config.fromJSON(jsonUrl);
  } catch (IOException e) {
    try {
      URL yamlUrl = null;
      if (DEFAULT_URI_PATH.equals(uri.getPath())) {
        yamlUrl = JCachingProvider.class.getResource("/redisson-jcache.yaml");
      } else {
        yamlUrl = uri.toURL();
      }
      if (yamlUrl != null) {
        config = Config.fromYAML(yamlUrl);
      }
    } catch (IOException e2) {
      // skip
    }
  }
  return config;
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient(String configPath) throws NamingException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      NamingException ex = new NamingException("Can't parse yaml config " + configPath);
      ex.initCause(e1);
      throw ex;
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    NamingException ex = new NamingException();
    ex.initCause(e);
    throw ex;
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient(String configPath) throws NamingException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      NamingException ex = new NamingException("Can't parse yaml config " + configPath);
      ex.initCause(e1);
      throw ex;
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    NamingException ex = new NamingException();
    ex.initCause(e);
    throw ex;
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient() throws LifecycleException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      log.error("Can't parse json config " + configPath, e);
      throw new LifecycleException("Can't parse yaml config " + configPath, e1);
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    throw new LifecycleException(e);
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient() throws LifecycleException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      log.error("Can't parse json config " + configPath, e);
      throw new LifecycleException("Can't parse yaml config " + configPath, e1);
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    throw new LifecycleException(e);
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient() throws LifecycleException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      log.error("Can't parse json config " + configPath, e);
      throw new LifecycleException("Can't parse yaml config " + configPath, e1);
    }
  }
  
  try {
    return Redisson.create(config);
  } catch (Exception e) {
    throw new LifecycleException(e);
  }
}

代码示例来源:origin: redisson/redisson

protected RedissonClient buildClient() throws LifecycleException {
  Config config = null;
  try {
    config = Config.fromJSON(new File(configPath), getClass().getClassLoader());
  } catch (IOException e) {
    // trying next format
    try {
      config = Config.fromYAML(new File(configPath), getClass().getClassLoader());
    } catch (IOException e1) {
      log.error("Can't parse json config " + configPath, e);
      throw new LifecycleException("Can't parse yaml config " + configPath, e1);
    }
  }
  
  try {
    try {
    Config c = new Config(config);
    Codec codec = c.getCodec().getClass().getConstructor(ClassLoader.class)
            .newInstance(Thread.currentThread().getContextClassLoader());
    config.setCodec(codec);
    } catch (Exception e) {
      throw new IllegalStateException("Unable to initialize codec with ClassLoader parameter", e);
    }
    
    return Redisson.create(config);
  } catch (Exception e) {
    throw new LifecycleException(e);
  }
}

代码示例来源:origin: redisson/redisson

try {
  InputStream is = getConfigStream();
  config = Config.fromJSON(is);
} catch (IOException e) {

代码示例来源:origin: Nepxion/Aquarius

public static Config createJsonConfig(String jsonConfigContent) throws IOException {
    return Config.fromJSON(jsonConfigContent);
  }
}

相关文章