Construct a system resource from a string.
The resource is tried as classloader resource before being
treated as a normal resource.
175723
public static Resource newSystemResource(String resource)
        throws IOException
    {
        URL url=null;
        // Try to format as a URL?
        ClassLoader
            loader=Thread.currentThread().getContextClassLoader();
        if (loader!=null)
        {
            url=loader.getResource(resource);
            if (url==null && resource.startsWith("/"))
                url=loader.getResource(resource.substring(1));
        }
        if (url==null)
        {
            loader=Resource.class.getClassLoader();
            if (loader!=null)
            {
                url=loader.getResource(resource);
                if (url==null && resource.startsWith("/"))
                    url=loader.getResource(resource.substring(1));
            }
        }
        
        if (url==null)
        {
            url=ClassLoader.getSystemResource(resource);
            if (url==null && resource.startsWith("/"))
                url=loader.getResource(resource.substring(1));
        }
        
        if (url==null)
            return null;
        
        return newResource(url);
    }
1286664
def _build_resource(self):
        """"""
        resource = {"name": self.name}

        if self.dns_name is not None:
            resource["dnsName"] = self.dns_name

        if self.description is not None:
            resource["description"] = self.description

        if self.name_server_set is not None:
            resource["nameServerSet"] = self.name_server_set

        return resource
928784
public void createResource(final InputStream inputStream, final String resourceName)
        throws JaxRxException {
        synchronized (resourceName) {
            if (inputStream == null) {
                throw new JaxRxException(400, "Bad user request");
            } else {
                try {
                    shred(inputStream, resourceName);
                } catch (final TTException exce) {
                    throw new JaxRxException(exce);
                }
            }
        }
    }
16273
def class_from_string(name):
    '''
    
    '''
    module_name, class_name = name.rsplit('.', 1)
    __import__(module_name)
    module = sys.modules[module_name]
    return getattr(module, class_name)
962077
def resource(string: str):
        
        try:
            prefix, resulting_type = Naming.pop_prefix(string)
            prefix += Naming.RESOURCE_PREFIX
        except IndexError:
            prefix = ''
            resulting_type = string
        resulting_type = dasherize(underscore(resulting_type))
        return prefix + (pluralize(resulting_type) if Naming._pluralize(resulting_type) else resulting_type)
248024
public static InputStream openResourceStream(String resourceName) {
        InputStream stream = null;
        ClassLoader classLoader = Utils.class.getClassLoader();
        if (classLoader != null) {
            stream = classLoader.getResourceAsStream(resourceName);
        }

        if (stream == null) {
            stream = ClassLoader.getSystemResourceAsStream(resourceName);
        }
        return stream;
    }
181332
def get_resource(name):
    
    # get the resource
    resource = resource_string('trimesh',
                               os.path.join('resources', name))
    # make sure we return it as a string
    if hasattr(resource, 'decode'):
        return resource.decode('utf-8')
    return resource
1352264
def loads(cls, name):
        
        if not isinstance(name, six.string_types):
            raise TypeError(u'arguments to {classname} must be of type {string_types}'.format(
                classname=cls.__name__, string_types=repr(six.string_types)
            ))
        if not name or name.isspace():
            raise ValueError('name must not be empty')

        return cls(name)
915231
private Resource newResource(final String resourcePath) {
        return new Resource(this, /* length unknown */ -1L) {
            /** The module reader proxy. */
            private ModuleReaderProxy moduleReaderProxy;

            @Override
            public String getPath() {
                return resourcePath;
            }

            @Override
            public String getPathRelativeToClasspathElement() {
                return resourcePath;
            }

            @Override
            public synchronized ByteBuffer read() throws IOException {
                if (skipClasspathElement) {
                    // Shouldn't happen
                    throw new IOException("Module could not be opened");
                }
                markAsOpen();
                try {
                    moduleReaderProxy = moduleReaderProxyRecycler.acquire();
                    // ModuleReader#read(String name) internally calls:
                    // InputStream is = open(name); return ByteBuffer.wrap(is.readAllBytes());
                    byteBuffer = moduleReaderProxy.read(resourcePath);
                    length = byteBuffer.remaining();
                    return byteBuffer;

                } catch (final SecurityException | OutOfMemoryError e) {
                    close();
                    throw new IOException("Could not open " + this, e);
                }
            }

            @Override
            synchronized InputStreamOrByteBufferAdapter openOrRead() throws IOException {
                return new InputStreamOrByteBufferAdapter(open());
            }

            @Override
            public synchronized InputStream open() throws IOException {
                if (skipClasspathElement) {
                    // Shouldn't happen
                    throw new IOException("Module could not be opened");
                }
                markAsOpen();
                try {
                    moduleReaderProxy = moduleReaderProxyRecycler.acquire();
                    inputStream = new InputStreamResourceCloser(this, moduleReaderProxy.open(resourcePath));
                    // Length cannot be obtained from ModuleReader
                    length = -1L;
                    return inputStream;

                } catch (final SecurityException e) {
                    close();
                    throw new IOException("Could not open " + this, e);
                }
            }

            @Override
            public synchronized byte[] load() throws IOException {
                try {
                    read();
                    final byte[] byteArray = byteBufferToByteArray();
                    length = byteArray.length;
                    return byteArray;
                } finally {
                    close();
                }
            }

            @Override
            public synchronized void close() {
                super.close(); // Close inputStream
                if (byteBuffer != null) {
                    if (moduleReaderProxy != null) {
                        // Release any open ByteBuffer
                        moduleReaderProxy.release(byteBuffer);
                    }
                    byteBuffer = null;
                }
                if (moduleReaderProxy != null) {
                    // Recycle the (open) ModuleReaderProxy instance.
                    moduleReaderProxyRecycler.recycle(moduleReaderProxy);
                    // Don't call ModuleReaderProxy#close(), leave the ModuleReaderProxy open in the recycler.
                    // Just set the ref to null here. The ModuleReaderProxy will be closed by
                    // ClasspathElementModule#close().
                    moduleReaderProxy = null;
                }
                markAsClosed();
            }
        };
    }
1328210
private T loadFileOrResourceValue(final String str)
	{
		// Ideally we want to resolve str to a File so we can be smart about reloading it
		// N.B. Even if str is a classpath reference it's possible it could still be resolved to a file on disk
		// We can't be smart about reloading non-File classpath resources but we assume they will not change
		final File file;
		final URL resource;
		{
			// First consult the cache of str -> File (if present)
			if (lastFile != null && StringUtils.equals(str, lastResourceOrFile))
			{
				file = lastFile;
				resource = null;
			}
			else if (new File(str).exists())
			{
				file = new File(str);
				resource = null;
			}
			else
			{
				try
				{
					resource = getClass().getResource(str);

					if (resource == null)
						throw new IllegalArgumentException("JAXB config for " + name + ": no such file or resource: " + str);

					final URI uri = resource.toURI();

					if (StringUtils.equalsIgnoreCase(uri.getScheme(), "file"))
					{
						file = new File(uri);
					}
					else
					{
						file = null;
					}
				}
				catch (URISyntaxException e)
				{
					throw new IllegalArgumentException("Error processing classpath resource " +
					                                   str +
					                                   " from property " +
					                                   name +
					                                   ": URL to URI failed", e);
				}
			}
		}

		// Now resource the file or resource
		if (file == null)
		{
			assert (resource != null);

			// We reload the cached value ONLY if the resource path changes, we don't take into account the resolved URL
			if (cached == null || !StringUtils.equals(str, lastResourceOrFile))
			{
				lastResourceOrFile = str;

				return loadResourceValue(resource);
			}
			else
			{
				return cached;
			}
		}
		else
		{
			lastResourceOrFile = str;

			return loadFileValue(file);
		}
	}
633145
def construct_from_string(cls, string):
        
        if string == cls.name:
            return cls()
        raise TypeError("Cannot construct a '{}' from "
                        "'{}'".format(cls, string))
91542
def build_resource(klass, providedLabel)
      resource = klass.new
      resource.providedLabel = providedLabel
      resource
    end
1102424
private Object createResource(String refName, String className, String bindingName, ResourceInfo resourceRefInfo) throws Exception {
        String nameFilter = FilterUtils.createPropertyFilter(ResourceFactory.JNDI_NAME, bindingName);
        String createsFilter = className == null ? null : FilterUtils.createPropertyFilter(ResourceFactory.CREATES_OBJECT_CLASS, className);
        String filter = createsFilter == null ? nameFilter : "(&" + nameFilter + createsFilter + ")";
        ResourceInfo resInfo = resourceRefInfo != null ? resourceRefInfo : className != null ? new ResourceEnvRefInfo(refName, className) : null;
        return createResourceWithFilter(filter, resInfo);
    }
1178169
private static InputSource stringToSource(String str) {
        InputSource is = new InputSource(new StringReader(str));
        is.setEncoding("UTF-8");
        return is;
    }
289441
public String resource_to_string(base_resource resrc)
	{
		Gson gson = new Gson();
		return gson.toJson(resrc);
	}
1052767
public static URL getResource(Class<?> c, String resName) {
		URL url = constructResourceURL(c, resName);

		if (url == null)
			return c.getResource(resName);

		InputStream is = null;
		try {
			is = url.openStream();
			is.read();
		} catch (Exception e) {
			return c.getResource(resName);
		} finally {
			try {
				if (is != null)
					is.close();
			} catch (Exception e) {
			}
		}

		return url;
	}
232618
public static String readResource(String path) {
        final long start = System.nanoTime();
        try (InputStream is = UScale.class.getClassLoader().getResourceAsStream(path);) {
            int len = 0;
            byte[] buffer = new byte[2048];
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            while ((len = is.read(buffer)) >= 0) {
                baos.write(buffer, 0, len);
            }
            return new String(baos.toByteArray(), StandardCharsets.UTF_8);
        } catch (IOException e) {
            LOGGER.log(Level.WARNING, e, () -> "IOException loading resource " + path);
            throw new IllegalStateException("Unable to read class loaded stream " + path, e);
        } catch (RuntimeException re) {
            LOGGER.log(Level.WARNING, re, () -> "Unexpected exception loading resource " + path);
            throw re;
        } finally {
            LOGGER.fine(() -> String.format("Loaded resource %s in %.3fms", path,
                    (System.nanoTime() - start) / 1000000.0));
        }
    }