Read Caduceus program.

@param resource the resource
@return the lyre program
@throws IOException the io exception
184376
public static CaduceusProgram read(@NonNull Resource resource) throws IOException {
      CaduceusProgram program = new CaduceusProgram();

      try (Reader reader = resource.reader()) {
         List<Object> rules = ensureList(new Yaml().load(reader), "Caduceus rules should be specified in a list");

         for (Object entry : rules) {
            Map<String, Object> ruleMap = ensureMap(entry, "Rule entry should be a map");
            String ruleName = Val.of(ruleMap.get("name")).asString();
            String pattern = Val.of(ruleMap.get("pattern")).asString();
            if (StringUtils.isNullOrBlank(pattern)) {
               throw new IOException("No pattern specified: " + entry);
            }
            if (StringUtils.isNullOrBlank(ruleName)) {
               throw new IOException("No rule name specified: " + entry);
            }

            List<CaduceusAnnotationProvider> annotationProviders = new LinkedList<>();
            if (ruleMap.containsKey("annotations")) {
               List<Object> annotationList = ensureList(ruleMap.get("annotations"),
                                                        "Annotations should be specified as a list.");
               for (Object o : annotationList) {
                  annotationProviders.add(CaduceusAnnotationProvider.fromMap(
                     ensureMap(o, "Annotation entries should be specified as a map."), resource.descriptor(),
                     ruleName));
               }
            }

            List<CaduceusRelationProvider> relationProviders = new LinkedList<>();
            if (ruleMap.containsKey("relations")) {
               List<Object> relations = ensureList(ruleMap.get("relations"),
                                                   "Relations should be specified as a list.");
               for (Object o : relations) {
                  relationProviders.add(
                     CaduceusRelationProvider.fromMap(ensureMap(o, "Relation entries should be specified as a map.")));
               }
            }

            try {
               program.rules.add(new CaduceusRule(resource.descriptor(),
                                                  ruleName,
                                                  TokenRegex.compile(pattern),
                                                  annotationProviders,
                                                  relationProviders));
            } catch (ParseException e) {
               throw new IOException("Invalid pattern for rule " + ruleName);
            }

         }

      }
      return program;
   }
1039862
public NfsReaddirplusResponse readdirplus(long cookie, long cookieverf, int dircount, int maxcount)
            throws IOException {
        return getNfs().wrapped_getReaddirplus(makeReaddirplusRequest(cookie, cookieverf, dircount, maxcount));
    }
329161
public static InputStream getInputStream(final File resource) throws IOException {
		if (resource.exists()) {
			return new FileInputStream(resource);
		}
		LOG.info("Could not find file '" + resource.getAbsolutePath() + "' in the file system. Trying to load it from the classpath...");

		String path = FilenameUtils.separatorsToUnix(resource.getPath());
		ClassLoader cl = Thread.currentThread().getContextClassLoader();

		InputStream is = cl.getResourceAsStream(path);

		if (is == null) {
			if (path.startsWith("/")) {
				LOG.info("Could not find file '" + resource
						+ " in the file system. Trying to load it from the classpath without the leading slash...");
				is = cl.getResourceAsStream(path.substring(1));
			}

			if (is == null) {
				// If configs are to be loaded from the classpath, we also try it directly
				// stripping of the config directory
				String configDir = new File(getConfigDir()).getName();
				if (path.startsWith(configDir)) {
					is = cl.getResourceAsStream(StringUtils.substringAfter(path, configDir + '/'));
				}
			}

			if (is == null) {
				throw new FileNotFoundException("Could not load file '" + resource + "'");
			}
		}

		return is;
	}
321589
public ProjectBuilder read(final URI file) throws IOException {
        try (InputStream in = file.toURL().openStream()) {
            return read(in, file);
        }
    }
916893
static void createFileFromResource(String resource, Resource file) throws IOException {
	createFileFromResource(resource, file, null);
    }
41572
public void loadFromResource(String resource, Candidate.CandidateType type) throws IOException {
      InputStream candidatesConfig = classloader.getResourceAsStream(resource);
      if(candidatesConfig == null) {
         throw new IOException("Resource '" + resource + "' not found");
      }
      try {
         loadFrom(candidatesConfig, type);
      }
      finally {
         candidatesConfig.close();
      }
   }
1103526
public static LocalResource createLocalResourceOfFile(YarnConfiguration yarnConf,
      String resource) throws IOException {
    LocalResource localResource = Records.newRecord(LocalResource.class);

    Path resourcePath = new Path(resource);

    FileStatus jarStat = FileSystem.get(resourcePath.toUri(), yarnConf).getFileStatus(resourcePath);
    localResource.setResource(ConverterUtils.getYarnUrlFromPath(resourcePath));
    localResource.setSize(jarStat.getLen());
    localResource.setTimestamp(jarStat.getModificationTime());
    localResource.setType(LocalResourceType.FILE);
    localResource.setVisibility(LocalResourceVisibility.PUBLIC);
    return localResource;
  }
216757
public static BufferedReader getConfigBufferedReader(final String resource, final String encoding) throws IOException {
		return new BufferedReader(getConfigInputStreamReader(resource, encoding));
	}
1198756
public Nfs3ReaddirplusResponse getReaddirplus(NfsReaddirplusRequest request) throws IOException {
        Nfs3ReaddirplusResponse response = new Nfs3ReaddirplusResponse();
        _rpcWrapper.callRpcNaked(request, response);
        return response;
    }
934273
public static Document read(@NonNull Resource resource) throws IOException {
      Type mapType = new TypeToken<Map<String, Object>>() {
      }.getType();
      Gson gson = new Gson();
      //Load the document to a map
      Map<String, Object> json = gson.fromJson(resource.readToString(), mapType);

      //Create the initial document using raw content
      Document doc = DocumentFactory.getInstance().createRaw(json.getOrDefault("id", Val.NULL).toString(),
                                                             json.getOrDefault("content", "").toString());

      //Add document attributes
      if (json.containsKey("attributes")) {
         Map<String, Object> attributes = Cast.as(json.get("attributes"));
         attributes.forEach((k, av) -> {
            AttributeType attrType = Types.attribute(k);
            Object val = attrType.getValueType().decode(av);
            if (val != null) {
               doc.put(attrType, val);
            }
         });
      }

      //Set completed annotations
      if (json.containsKey("completed")) {
         Map<String, Object> completed = Cast.as(json.get("completed"));
         completed
            .forEach((k, av) -> {
               AnnotatableType type = Types.from(k);
               doc.getAnnotationSet().setIsCompleted(type, true, av.toString());
            });
      }

      //Create the annotations
      AtomicLong maxAnnotationId = new AtomicLong(-1);
      if (json.containsKey("annotations")) {
         List<Object> annotations = Cast.as(json.get("annotations"));
         annotations
            .forEach(v -> {
               Map<String, Object> vv = Cast.as(v);

               //Create new annotation
               Annotation annotation = doc.annotationBuilder()
                                          .type(AnnotationType.create(vv.get("type").toString()))
                                          .start(((Number) vv.get("start")).intValue())
                                          .end(((Number) vv.get("end")).intValue())
                                          .createAttached();

               //Read in and set id and update max id value
               annotation.setId(((Number) vv.get("id")).longValue());
               maxAnnotationId.getAndUpdate(old -> old < annotation.getId() ? annotation.getId() : old);

               //Read in the attributes (map of types and values)
               Cast.<Map<String, Object>>as(vv.getOrDefault("attributes", Collections.emptyMap())).forEach(
                  (k, av) -> {
                     AttributeType attrType = Types.attribute(k);
                     Object val = attrType.getValueType().decode(av);
                     if (val != null) {
                        annotation.put(attrType, val);
                     }
                  });

               if (vv.containsKey("relations")) {
                  //Read in the relations (a list of maps containing type, value, and target)
                  Cast.<List<Object>>as(vv.get("relations"))
                     .stream()
                     .map(Cast::<Map<String, Object>>as)
                     .forEach(rel -> annotation.add(new Relation(RelationType.create(rel.get("type").toString()),
                                                                 rel.get("value").toString(),
                                                                 ((Number) rel.get("target")).longValue())));
               }
            });

         //Set the next annotation id
         doc.idGenerator.set(maxAnnotationId.get() + 1);
      }

      return doc;
   }
329040
public static SeLionDataProvider getDataProvider(DataResource resource)
            throws IOException {
        logger.entering(resource);

        if(resource == null) {
            return null;
        }

        switch (resource.getType().toUpperCase()) {
        case "XML":
            return new XmlDataProviderImpl((XmlDataSource) resource);
        case "JSON":
            return new JsonDataProviderImpl(resource);
        case "YAML":
        case "YML":
            return new YamlDataProviderImpl(resource);
        case "XLSX":
        case "XLS":
            return new ExcelDataProviderImpl(resource);
        default:
            return null;
        }
     }
400105
public static URL getResourceURL(String resource) throws IOException {
    URL url = null;
    ClassLoader loader = ResourcesUtils.class.getClassLoader();
    if (loader != null) {
      url = loader.getResource(resource);
    }
    if (url == null) {
      url = ClassLoader.getSystemResource(resource);
    }
    if (url == null) {
      throw new IOException("Could not find resource " + resource);
    }
    return url;
  }
960839
public static InputStream loadResource(final String resource) throws FileNotFoundException {
        final boolean hasLeadingSlash = resource.startsWith("/");
        final String stripped = hasLeadingSlash ? resource.substring(1) : resource;

        InputStream stream = null;

        final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader != null) {
            stream = classLoader.getResourceAsStream(resource);
            if (stream == null && hasLeadingSlash) {
                stream = classLoader.getResourceAsStream(stripped);
            }
        }

        if (stream == null) {
            throw new FileNotFoundException("resource " + resource + " not found");
        }

        return stream;
    }
1233465
@Nullable
  public static Properties loadPropertiesFromResource(URL resource) {
    try (InputStream stream = resource.openStream()) {
      return loadProperties(stream);
    } catch (IOException e) {
      LOG.warn("Failed to read properties from {}: {}", resource, e.toString());
      return null;
    }
  }
877558
public static void checkGetInputStreamOK(Resource resource) throws IOException {
	if (!resource.exists()) throw new IOException("file [" + resource.getPath() + "] does not exist");

	if (resource.isDirectory()) throw new IOException("can't read directory [" + resource.getPath() + "] as a file");

    }
90607
private Reader getResourceReader(String resource) throws ResourceNotFoundException {
		List<Class<?>> excluded = new ArrayList<>();
		excluded.add(ILessCssResourceGenerator.class);
		return rsReaderHandler.getResource(bundle, resource, false, excluded);
	}
1140177
private String readResource(final String resourceName) throws IOException {
      return new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(resourceName), DEFAULT_CHARSET)).lines().collect(Collectors.joining("\n"));
   }