<p>

</p>

@param resource
@return
@throws ProtocolException
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);
	}
462513
public static InputStream getResourceAsInputStream(String resource) {
        InputStream in = classLoaderWrapper.getResourceAsStream(resource);
        if (in == null) {
            return null;
        }
        return in;
    }
1000479
public URL copyWithProtocol(String protocol) {
        return new URL(protocol, this.adapterAddress, this.deviceAddress, this.deviceAttributes, this.serviceUUID,
                this.characteristicUUID, this.fieldName);
    }
894265
public URLStreamHandler createURLStreamHandler (String protocol)
    {
        Class<? extends URLStreamHandler> handler = _handlers.get(protocol.toLowerCase());
        if (handler != null) {
            try {
                return handler.newInstance();
            } catch (Exception e) {
                log.warning("Unable to instantiate URLStreamHandler", "protocol", protocol,
                            "cause", e);
            }
        }
        return null;
    }
162327
public static PropertiesSettings from(String resource) throws IOException
    {
        return from(resource, Thread.currentThread().getContextClassLoader());
    }
1267865
public static File getResourceAsFile(String resource) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        try {
            return new File(URLDecoder.decode(cl.getResource(resource)
                    .getFile(), "UTF-8"));
        } catch (UnsupportedEncodingException uee) {
            return null;
        }
    }
1203208
public static <F> Protocol.Builder<F> builder(final String name) {
        return new ProtocolImpl<F>(name);
    }
895214
@Override
	public HttpCommandProcessor getCommandProcessor(Protocol protocol) {
		String commandProcessorName = commandProcessorNames.get(protocol);

        if (commandProcessorName == null) {
			throw new PanicInTheCougar("No HTTP Command Processor has been configured for protocol " + protocol);
        }

        HttpCommandProcessor commandProcessor = (HttpCommandProcessor)applicationContext.getBean(commandProcessorName);

        if (commandProcessor == null) {
			throw new PanicInTheCougar("No HTTP Command Processor has been configured for the name " + commandProcessorName);
        }

		return commandProcessor;
	}
833231
public static Layout parseResource(String resource) {
        int i = resource.indexOf(":");

        if (i > 0) {
            String loaderId = resource.substring(0, i);
            ILayoutLoader layoutLoader = LayoutLoaderRegistry.getInstance().get(loaderId);

            if (layoutLoader != null) {
                String name = resource.substring(i + 1);
                return layoutLoader.loadLayout(name);
            }
        }

        InputStream strm = ExecutionContext.getSession().getServletContext().getResourceAsStream(resource);
        
        if (strm == null) {
            throw new CWFException("Unable to locate layout resource: " + resource);
        }
        
        return parseStream(strm);
    }
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);
    }
40129
@Pure
	protected String formatResource(XtextResource resource) {
		assert resource != null;
		try {
			final ITextRegionAccess regionAccess = this.regionAccessBuilder.get().forNodeModel(resource).create();
			final FormatterRequest formatterRequest = new FormatterRequest();
			formatterRequest.setAllowIdentityEdits(false);
			formatterRequest.setTextRegionAccess(regionAccess);
			final IPreferenceValues preferenceValues = FormatterFacade.this.configurationProvider
					.getPreferenceValues(resource);
			formatterRequest.setPreferences(TypedPreferenceValues.castOrWrap(preferenceValues));
			final List<ITextReplacement> replacements = this.formatter.format(formatterRequest);
			return regionAccess.getRewriter().renderToString(replacements);
		} catch (Exception exception) {
			throw Exceptions.sneakyThrow(exception);
		}
	}
1036847
public static List<Protos.Resource> resources(Protos.Resource... resources) {
		checkNotNull(resources);
		return Arrays.asList(resources);
	}
294207
public static String readFromResource(String resource) throws IOException {

        InputStream in = getResourceAsStream(resource);
        if (in == null) {
            return null;
        }
        try {
            return read(in);
        } finally {
            closeQuietly(in);
        }
    }
250819
public static ProtocolServer create(String protocol, Context context, ClassLoader classLoader, String netimpl) {
        if (netimpl != null) netimpl = netimpl.trim();
        if ("TCP".equalsIgnoreCase(protocol)) {
            if (netimpl == null || netimpl.isEmpty()) {
                return new TcpAioProtocolServer(context);
            } else if ("aio".equalsIgnoreCase(netimpl)) {
                return new TcpAioProtocolServer(context);
            } else if ("nio".equalsIgnoreCase(netimpl)) {
                return null;//  return new TcpNioProtocolServer(context);
            }
        } else if ("UDP".equalsIgnoreCase(protocol)) {
            if (netimpl == null || netimpl.isEmpty()) {
                return null;// return new UdpBioProtocolServer(context);
            } else if ("bio".equalsIgnoreCase(netimpl)) {
                return null;// return new UdpBioProtocolServer(context);
            }
        } else if (netimpl == null || netimpl.isEmpty()) {
            throw new RuntimeException("ProtocolServer not support protocol " + protocol);
        }
        try {
            if (classLoader == null) classLoader = Thread.currentThread().getContextClassLoader();
            Class clazz = classLoader.loadClass(netimpl);
            return (ProtocolServer) clazz.getDeclaredConstructor(Context.class).newInstance(context);
        } catch (Exception e) {
            throw new RuntimeException("ProtocolServer(netimple=" + netimpl + ") newinstance error", e);
        }
    }
788775
@Nullable
    public static InputStream getResourceAsStream(@NotNull String resource) {
        final ClassLoader classLoader = FileUtils.class.getClassLoader();
        final InputStream inputStream = classLoader != null
                ? classLoader.getResourceAsStream(resource)
                : ClassLoader.getSystemResourceAsStream(resource);

        if (inputStream == null) {
            try {
                return new FileInputStream(resource);
            } catch (final FileNotFoundException e) {
                LOGGER.error("Unable to create an Input Stream for " + resource, e);
            }
        }
        return inputStream;
    }
1023309
public static byte[] readByteArrayFromResource(String resource) throws IOException {
        InputStream in = getResourceAsStream(resource);
        if (in == null) {
            return null;
        }

        try {
            return readByteArray(in);
        } finally {
            closeQuietly(in);
        }
    }
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;
    }