Return the entity of a resource

@param resource the resource
@param <T>      the type of the resource's entity
@param <R>      the resource type
@return the resource's entity
510691
public static <T, R extends Resource<T>> T getEntity(R resource) {
        return resource.getEntity();
    }
1271957
public static Resource getGenericResource(String resource) {
        log.trace("retrieving resource -> " + resource);
        try {

            final File file = normFile(resource);
            if (file.exists()) {
                return new ResourceImpl(file.toURI().toURL());
            }

            if (resource.startsWith("/")) {
                throw new IllegalArgumentException("Classpath resource cannot start with '/': " + resource);
            }
            if (resource.indexOf('\\') != -1) {
                throw new IllegalArgumentException("Classpath resource cannot contain '\\': " + resource);
            }
            URL url = getLoader().getResource(resource);
            if (url == null) {
                return null;
            }
            return new ResourceImpl(url);
        } catch (Exception e) {
            log.error("Could not retrieve resource: " + e.getMessage(), e);
            return null;
        }
    }
1218226
public static Enumeration<URL> getResources(String resource) {
        Enumeration<URL> urls = null;
        try {
            urls = ClassUtils.getContextClassLoader().getResources(resource);
        } catch (IOException e) {
            //noop
        }
        if (urls == null) {
            try {
                urls = IOUtils.class.getClassLoader().getResources(resource);
            } catch (IOException e) {
                //noop
            }
        }

        if (urls == null) {
            URL url = IOUtils.class.getResource(resource);
            if (url != null) {
                final Iterator<URL> it = Lists.newArrayList(url).iterator();
                urls = new Enumeration<URL>() {
                    public boolean hasMoreElements() {
                        return it.hasNext();
                    }

                    public URL nextElement() {
                        return it.next();
                    }
                };
            }
        }

        if (urls == null) {
            File file = new File(resource);
            if (file.isFile()) {
                try {
                    final Iterator<URL> it = Lists.newArrayList(file.toURI().toURL()).iterator();
                    urls = new Enumeration<URL>() {
                        public boolean hasMoreElements() {
                            return it.hasNext();
                        }

                        public URL nextElement() {
                            return it.next();
                        }
                    };
                } catch (MalformedURLException e) {
                    //no op
                }
            }
        }

        return urls == null ? new Enumeration<URL>() {
            public boolean hasMoreElements() {
                return false;
            }

            public URL nextElement() {
                return null;
            }
        } : urls;
    }
965986
public static synchronized I18n getI18n(String resource) {
        I18n instance = (I18n)mapping.get(resource);
        if (instance == null) {
            instance = new I18n(ResourceBundle.getBundle(resource,
                                                         Locale.getDefault(),
                                                         getClassLoader()));
            mapping.put(resource, instance);
        }
        return instance;
    }
1053877
public ResponseBuilder initialize(final Resource resource) {

        if (MISSING_RESOURCE.equals(resource)) {
            throw new NotFoundException();
        } else if (DELETED_RESOURCE.equals(resource)) {
            throw new ClientErrorException(GONE);
        }

        LOGGER.debug("Acceptable media types: {}", getRequest().getAcceptableMediaTypes());

        this.syntax = getSyntax(getServices().getIOService(),
            getRequest().getAcceptableMediaTypes(), resource.getBinaryMetadata()
                .filter(b -> !DESCRIPTION.equals(getRequest().getExt()))
                .map(b -> b.getMimeType().orElse(APPLICATION_OCTET_STREAM)).orElse(null));

        if (ACL.equals(getRequest().getExt()) && !resource.hasAcl()) {
            throw new NotFoundException();
        }

        setResource(resource);
        return ok();
    }
1056950
@Nullable
  @VisibleForTesting
  static Resource toResourceProto(@Nullable io.opencensus.resource.Resource resource) {
    if (resource == null || resource.getType() == null) {
      return null;
    } else {
      Resource.Builder resourceProtoBuilder = Resource.newBuilder();
      resourceProtoBuilder.setType(resource.getType());
      for (Entry<String, String> keyValuePairs : resource.getLabels().entrySet()) {
        resourceProtoBuilder.putLabels(keyValuePairs.getKey(), keyValuePairs.getValue());
      }
      return resourceProtoBuilder.build();
    }
  }
297355
public static function toObject($resource) {
		if (self::isObject($resource)) {
			return $resource;

		} else if (self::isArray($resource)) {
			return self::buildObject($resource);

		} else if (self::isJson($resource)) {
			return json_decode($resource);

		} else if ($ser = self::isSerialized($resource)) {
			return self::toObject($ser);

		} else if ($xml = self::isXml($resource)) {
			return $xml;
		}

		return $resource;
	}
869000
public static String getClassName(Resource resource) {
        try {
            return getClassName(resource.getFile().getAbsolutePath());
        } catch (IOException e) {
            return null;
        }
    }
643644
protected final Connection<T> createConnectionForResource(T resource)
    {
        if(resource==null)
        {
            throw new FaxException("Connection resource not provided.");
        }

        //create new connection
        Connection<T> connection=new ConnectionImpl<T>(resource,this);
        
        return connection;
    }
1347310
public T loadXml(DataResource resource) {

    if (isXIncludeAware()) {
      XMLStreamReader streamReader = getStaxUtil().createXmlStreamReader(resource, true);
      try {
        Object unmarshalledObject = getOrCreateUnmarshaller().unmarshal(streamReader);
        T jaxbBean = this.xmlBeanClass.cast(unmarshalledObject);
        validate(jaxbBean);
        return jaxbBean;
      } catch (Exception e) {
        throw new XmlInvalidException(e, resource);
      } finally {
        try {
          streamReader.close();
        } catch (XMLStreamException e) {
          throw new IllegalStateException("Failed to close stream reader.", e);
        }
      }
    } else {
      InputStream inputStream = resource.openStream();
      try {
        return loadXml(inputStream, resource);
      } catch (RuntimeException e) {
        throw new XmlInvalidException(e, resource.getUri());
      } finally {
        try {
          inputStream.close();
        } catch (Exception e) {
          // ignore...
        }
      }
    }
  }
563430
public <T extends ApiObject> EntityResponse<T> query(Request<T> request)
    {
        return executeRequest(request, objectMapper.getTypeFactory()
                .constructParametrizedType(EntityResponse.class, EntityResponse.class, request.getEntityType()));
    }
43142
private AbstractRESTEntity asEntity(byte[] responseBody, Class<?> clazz)
        throws Exception {

        AbstractRESTEntity entity = null;

        entity = (AbstractRESTEntity) mapper.readValue(responseBody, clazz);

        return entity;
    }
325591
public static ProtocolStrategy getStrategy(Resource resource)
			throws ProtocolException {
		if (resource == null) {
			throw new ProtocolException(
					"Unable to find implementation with resource : " + resource);
		}
		// search by url
		ProtocolStrategy retval = findStrategyByUrl(resource);
		if (retval != null) {
			return retval;
		}
		throw new ProtocolException(
				"This protocol has not yet been implemented : " + resource);
	}
895750
@Override
   @SuppressWarnings("unchecked")
   public <E, T extends Resource<E>> T getChildOfType(final Class<T> type, final String name) throws ResourceException
   {
      T result;
      Resource<?> child = getChild(name);
      if (type.isAssignableFrom(child.getClass()))
      {
         result = (T) child;
      }
      else if (child.exists())
      {
         throw new ResourceException("Requested resource [" + name + "] was not of type [" + type.getName()
                  + "], but was instead [" + child.getClass().getName() + "]");
      }
      else
      {
         E underlyingResource = (E) child.getUnderlyingResourceObject();
         result = getResourceFactory().create(type, underlyingResource);
      }
      return result;
   }
709653
public static InputStream getResourceAsStream(String resource) {
        InputStream in = ClassUtils.getContextClassLoader().getResourceAsStream(resource);
        if (in == null) {
            in = IOUtils.class.getResourceAsStream(resource);
        }

        return in;
    }
217060
public static Resource getResource(String location) {
        Resource resource = resolver.getResource(location);
        return resource.exists() ? resource : null;
    }
50859
public static URL getResource(String resource, Class<?> baseClass) {
		return (null != baseClass) ? baseClass.getResource(resource) : ClassLoaderUtil.getClassLoader().getResource(resource);
	}