ClassUtil.getResourceAsStream
Code IndexAdd Codota to your IDE (free)

Best code snippets using org.milyn.util.ClassUtil.getResourceAsStream(Showing top 15 results out of 315)

origin: org.milyn/milyn-commons

public InputStream getResource(String uri) throws IllegalArgumentException {
  if (uri == null) {
    throw new IllegalArgumentException("null 'uri' arg in method call.");
  } else if (uri.charAt(0) != '/') {
    throw new IllegalArgumentException(
        "classpath 'uri' must be a valid classpath with a leading '/' char on the path i.e. specified relative to the root of the classpath.");
  }
  return ClassUtil.getResourceAsStream(uri, getClass());
}
origin: org.milyn/milyn-commons

private Source getNamespaceSource(URI namespace) throws SAXException {
  String resourcePath = "/META-INF" + namespace.getPath();
  InputStream xsdStream = ClassUtil.getResourceAsStream(resourcePath, getClass());
  if(xsdStream == null) {
    throw new SAXException("Failed to locate XSD resource '" + resourcePath + "' on classpath. Namespace: '" + namespace + "'.");
  }
  return new StreamSource(xsdStream);
}
origin: org.milyn/milyn-smooks-javabean

protected InputSource resolveSchemaLocation(String systemId) throws SAXException {
  String namespaceId = Descriptor.getNamespaceId(systemId, descriptors);
  
  if(namespaceId != null) {
    String schemaLocation = Descriptor.getSchemaLocation(namespaceId, descriptors);
    
    if(schemaLocation == null) {
      throw new SAXException("Failed to resolve schemaLocation for namespace '" + systemId + "'.");
    }
    
    InputStream stream = ClassUtil.getResourceAsStream(schemaLocation, classLoader);

    if(stream == null) {
      throw new SAXException("schemaLocation '" + schemaLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource.");
    }
    
    return new InputSource(stream);
  } else {
    return null;
  }
}
origin: org.milyn/milyn-smooks-core

/**
 * Register the pre-installed CDU Creator classes.
 * @param resourceFile Installed (internal) resource config file.
 */
private void registerInstalledResources(String resourceFile) {
  InputStream resource = ClassUtil.getResourceAsStream(resourceFile, getClass());
  if(resource == null) {
    throw new IllegalStateException("Failed to load " + resourceFile + ".  Expected to be in the same package as " + getClass().getName());
  }
  try {
    SmooksResourceConfigurationList resourceList = registerResources(resourceFile, resource);            
    for(int i = 0; i < resourceList.size(); i++) {
      resourceList.get(i).setDefaultResource(true);
    }
    resourceList.setSystemConfigList(true);
  } catch (Exception e) {
    throw new IllegalStateException("Error processing resource file '" + resourceFile + "'.", e);
  }
}
origin: org.milyn/milyn-commons

/**
 * Get the specified resource as a stream.
 *
 * @param resourceName
 *            The name of the class to load.
 * @param caller
 *            The class of the caller.
 * @return The input stream for the resource or null if not found.
 */
public static InputStream getResourceAsStream(final String resourceName, final Class caller) {
  final String resource;
  if (!resourceName.startsWith("/")) {
    final Package callerPackage = caller.getPackage();
    if (callerPackage != null) {
      resource = callerPackage.getName().replace('.', '/') + '/'
          + resourceName;
    } else {
      resource = resourceName;
    }
    return getResourceAsStream(resource, caller.getClassLoader());
  } else {
    return getResourceAsStream(resourceName, caller.getClassLoader());            
  }
}
origin: smooks/smooks

@Override
protected void loadTemplate(SmooksResourceConfiguration resourceConfig) throws IOException, TransformerConfigurationException {
  TransformerFactory transformerFactory = TransformerFactory.newInstance();
  StreamSource xslStreamSource;
  boolean isInlineXSL = resourceConfig.isInline();
  byte[] xslBytes = resourceConfig.getBytes();
  xslString = new String(xslBytes, getEncoding().name());
  // If it's not a full XSL template, we need to make it so by wrapping it...
  isTemplatelet = isTemplatelet(isInlineXSL, new String(xslBytes));
  if (isTemplatelet) {
    String templateletWrapper = new String(StreamUtils.readStream(ClassUtil.getResourceAsStream("doc-files/templatelet.xsl", getClass())));
    String templatelet = new String(xslBytes);
    templateletWrapper = StringUtils.replace(templateletWrapper, "@@@templatelet@@@", templatelet);
    xslBytes = templateletWrapper.getBytes();
    xslString = new String(xslBytes, getEncoding().name());
  }
  boolean failOnWarning = resourceConfig.getBoolParameter("failOnWarning", true);
  xslStreamSource = new StreamSource(new StringReader(xslString));
  transformerFactory.setErrorListener(new XslErrorListener(failOnWarning));
  xslTemplate = transformerFactory.newTemplates(xslStreamSource);
}
origin: smooks/smooks

private void assertExtendedConfigOK(String configNamespace, String resourcePath) {
  InputStream resourceStream = ClassUtil.getResourceAsStream(resourcePath, classLoader);
  if (resourceStream == null) {
    throw new SmooksConfigurationException("Unable to locate Smooks digest configuration '" + resourcePath + "' for extended resource configuration namespace '" + configNamespace + "'.  This resource must be available on the classpath.");
  }
  Document configDoc;
  try {
    configDoc = XmlUtil.parseStream(resourceStream);
  } catch (Exception e) {
    throw new SmooksConfigurationException("Unable to parse namespace URI '" + configNamespace + "'.", e);
  }
  XsdDOMValidator validator;
  try {
    validator = new XsdDOMValidator(configDoc);
  } catch (SAXException e) {
    throw new SmooksConfigurationException("Unable to create XsdDOMValidator instance for extended resource config '" + resourcePath + "'.", e);
  }
  String defaultNS = validator.getDefaultNamespace().toString();
  if (!XSD_V10.equals(defaultNS) && !XSD_V11.equals(defaultNS)) {
    throw new SmooksConfigurationException("Extended resource configuration '" + resourcePath + "' default namespace must be a valid Smooks configuration namespace.");
  }
  if(validator.getNamespaces().size() > 1) {
    throw new SmooksConfigurationException("Extended resource configuration '" + resourcePath + "' defines configurations from multiple namespaces.  This is not permitted.  Only use configurations from the base Smooks config namespaces e.g. '" + XSD_V11 + "'.");
  }
}
origin: org.milyn/milyn-smooks-javabean

  protected InputSource resolveBindingConfigLocation(String systemId) throws SAXException {
    String namespaceId = Descriptor.getNamespaceId(systemId, descriptors);
    
    if(namespaceId != null) {
      String bindingConfigLocation = Descriptor.getBindingConfigLocation(namespaceId, descriptors);
      
      if(bindingConfigLocation == null) {
        throw new SAXException("Failed to resolve bindingConfigLocation for namespace '" + systemId + "'.");
      }
      
      InputStream stream = ClassUtil.getResourceAsStream(bindingConfigLocation, classLoader);
  
      if(stream == null) {
        throw new SAXException("bindingConfigLocation '" + bindingConfigLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource.");
      }
      
      return new InputSource(stream);
    } else {
      return null;
    }
  }
}
origin: smooks/smooks

public InputStream getResource(String uri) throws IllegalArgumentException {
  if (uri == null) {
    throw new IllegalArgumentException("null 'uri' arg in method call.");
  } else if (uri.charAt(0) != '/') {
    throw new IllegalArgumentException(
        "classpath 'uri' must be a valid classpath with a leading '/' char on the path i.e. specified relative to the root of the classpath.");
  }
  return ClassUtil.getResourceAsStream(uri, getClass());
}
origin: smooks/smooks

private Source getNamespaceSource(URI namespace) throws SAXException {
  String resourcePath = "/META-INF" + namespace.getPath();
  InputStream xsdStream = ClassUtil.getResourceAsStream(resourcePath, getClass());
  if(xsdStream == null) {
    throw new SAXException("Failed to locate XSD resource '" + resourcePath + "' on classpath. Namespace: '" + namespace + "'.");
  }
  return new StreamSource(xsdStream);
}
origin: smooks/smooks

protected InputSource resolveSchemaLocation(String systemId) throws SAXException {
  String namespaceId = Descriptor.getNamespaceId(systemId, descriptors);
  
  if(namespaceId != null) {
    String schemaLocation = Descriptor.getSchemaLocation(namespaceId, descriptors);
    
    if(schemaLocation == null) {
      throw new SAXException("Failed to resolve schemaLocation for namespace '" + systemId + "'.");
    }
    
    InputStream stream = ClassUtil.getResourceAsStream(schemaLocation, classLoader);

    if(stream == null) {
      throw new SAXException("schemaLocation '" + schemaLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource.");
    }
    
    return new InputSource(stream);
  } else {
    return null;
  }
}
origin: smooks/smooks

  protected InputSource resolveBindingConfigLocation(String systemId) throws SAXException {
    String namespaceId = Descriptor.getNamespaceId(systemId, descriptors);
    
    if(namespaceId != null) {
      String bindingConfigLocation = Descriptor.getBindingConfigLocation(namespaceId, descriptors);
      
      if(bindingConfigLocation == null) {
        throw new SAXException("Failed to resolve bindingConfigLocation for namespace '" + systemId + "'.");
      }
      
      InputStream stream = ClassUtil.getResourceAsStream(bindingConfigLocation, classLoader);
  
      if(stream == null) {
        throw new SAXException("bindingConfigLocation '" + bindingConfigLocation + "' for namespace '" + systemId + "' does not resolve to a Classpath resource.");
      }
      
      return new InputSource(stream);
    } else {
      return null;
    }
  }
}
origin: smooks/smooks

/**
 * Register the pre-installed CDU Creator classes.
 * @param resourceFile Installed (internal) resource config file.
 */
private void registerInstalledResources(String resourceFile) {
  InputStream resource = ClassUtil.getResourceAsStream(resourceFile, getClass());
  if(resource == null) {
    throw new IllegalStateException("Failed to load " + resourceFile + ".  Expected to be in the same package as " + getClass().getName());
  }
  try {
    SmooksResourceConfigurationList resourceList = registerResources(resourceFile, resource);            
    for(int i = 0; i < resourceList.size(); i++) {
      resourceList.get(i).setDefaultResource(true);
    }
    resourceList.setSystemConfigList(true);
  } catch (Exception e) {
    throw new IllegalStateException("Error processing resource file '" + resourceFile + "'.", e);
  }
}
origin: org.milyn/milyn-smooks-core

private void assertExtendedConfigOK(String configNamespace, String resourcePath) {
  InputStream resourceStream = ClassUtil.getResourceAsStream(resourcePath, classLoader);
  if (resourceStream == null) {
    throw new SmooksConfigurationException("Unable to locate Smooks digest configuration '" + resourcePath + "' for extended resource configuration namespace '" + configNamespace + "'.  This resource must be available on the classpath.");
  }
  Document configDoc;
  try {
    configDoc = XmlUtil.parseStream(resourceStream);
  } catch (Exception e) {
    throw new SmooksConfigurationException("Unable to parse namespace URI '" + configNamespace + "'.", e);
  }
  XsdDOMValidator validator;
  try {
    validator = new XsdDOMValidator(configDoc);
  } catch (SAXException e) {
    throw new SmooksConfigurationException("Unable to create XsdDOMValidator instance for extended resource config '" + resourcePath + "'.", e);
  }
  String defaultNS = validator.getDefaultNamespace().toString();
  if (!XSD_V10.equals(defaultNS) && !XSD_V11.equals(defaultNS)) {
    throw new SmooksConfigurationException("Extended resource configuration '" + resourcePath + "' default namespace must be a valid Smooks configuration namespace.");
  }
  if(validator.getNamespaces().size() > 1) {
    throw new SmooksConfigurationException("Extended resource configuration '" + resourcePath + "' defines configurations from multiple namespaces.  This is not permitted.  Only use configurations from the base Smooks config namespaces e.g. '" + XSD_V11 + "'.");
  }
}
origin: smooks/smooks

/**
 * Get the specified resource as a stream.
 *
 * @param resourceName
 *            The name of the class to load.
 * @param caller
 *            The class of the caller.
 * @return The input stream for the resource or null if not found.
 */
public static InputStream getResourceAsStream(final String resourceName, final Class caller) {
  final String resource;
  if (!resourceName.startsWith("/")) {
    final Package callerPackage = caller.getPackage();
    if (callerPackage != null) {
      resource = callerPackage.getName().replace('.', '/') + '/'
          + resourceName;
    } else {
      resource = resourceName;
    }
    return getResourceAsStream(resource, caller.getClassLoader());
  } else {
    return getResourceAsStream(resourceName, caller.getClassLoader());            
  }
}
org.milyn.utilClassUtilgetResourceAsStream

Javadoc

Get the specified resource as a stream.

Popular methods of ClassUtil

  • getResources
  • forName
    Load the specified class.
  • getSetterMethod
  • toSetterName
  • getAnnotatedFields
  • getClasses
    Will try to create a List of classes that are listed in the passed in file. The fileName is expected
  • getGetterMethod
  • indexOffFirstAssignableClass
  • toGetterName
  • toIsGetterName
  • addClasses
  • close
  • addClasses,
  • close,
  • contains,
  • containsAssignableClass,
  • findAnnotatedWith,
  • findInstancesOf,
  • getField,
  • getGetterMethodByProperty,
  • setField

Popular classes and methods

  • getSupportFragmentManager (FragmentActivity)
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • putExtra (Intent)
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • URL (java.net)
    Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web.
  • TimerTask (java.util)
    A task that can be scheduled for one-time or repeated execution by a Timer.
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Pattern (java.util.regex)
    Emulation of the Pattern class, uses RegExp as internal implementation.
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec

For IntelliJ IDEA and
Android Studio

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)