Java Code Examples for org.springframework.core.io.Resource#getDescription()

The following examples show how to use org.springframework.core.io.Resource#getDescription() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Determines the name to be used for the provided resource.
 * 
 * @param resource
 *          the resource to get the name for
 * @return the name of the resource
 */
protected String determineResourceName(final Resource resource) {
  String resourceName = null;

  if (resource instanceof ContextResource) {
    resourceName = ((ContextResource) resource).getPathWithinContext();

  } else if (resource instanceof ByteArrayResource) {
    resourceName = resource.getDescription();

  } else {
    try {
      resourceName = resource.getFile().getAbsolutePath();
    } catch (IOException e) {
      resourceName = resource.getFilename();
    }
  }
  return resourceName;
}
 
Example 2
/**
 * Determines the name to be used for the provided resource.
 * 
 * @param resource
 *          the resource to get the name for
 * @return the name of the resource
 */
protected String determineResourceName(final Resource resource) {
  String resourceName = null;

  if (resource instanceof ContextResource) {
    resourceName = ((ContextResource) resource).getPathWithinContext();

  } else if (resource instanceof ByteArrayResource) {
    resourceName = resource.getDescription();

  } else {
    try {
      resourceName = resource.getFile().getAbsolutePath();
    } catch (IOException e) {
      resourceName = resource.getFilename();
    }
  }
  return resourceName;
}
 
Example 3
/**
 * Determines the name to be used for the provided resource.
 *
 * @param resource the resource to get the name for
 * @return the name of the resource
 */
protected String determineResourceName(final Resource resource) {
    String resourceName = null;

    if (resource instanceof ContextResource) {
        resourceName = ((ContextResource) resource).getPathWithinContext();

    } else if (resource instanceof ByteArrayResource) {
        resourceName = resource.getDescription();

    } else {
        try {
            resourceName = resource.getFile().getAbsolutePath();
        } catch (IOException e) {
            resourceName = resource.getFilename();
        }
    }
    return resourceName;
}
 
Example 4
/**
 * Determines the name to be used for the provided resource.
 * 
 * @param resource
 *            the resource to get the name for
 * @return the name of the resource
 */
protected String determineResourceName(final Resource resource) {
    String resourceName = null;

    if (resource instanceof ContextResource) {
        resourceName = ((ContextResource) resource).getPathWithinContext();

    } else if (resource instanceof ByteArrayResource) {
        resourceName = resource.getDescription();

    } else {
        try {
            resourceName = resource.getFile().getAbsolutePath();
        } catch (IOException e) {
            resourceName = resource.getFilename();
        }
    }
    return resourceName;
}
 
Example 5
Source Project: olat   File: DatabaseSetup.java    License: Apache License 2.0 6 votes vote down vote up
private static void addHibernateFilesMatching(final String resourcePath, List<String> filesAlreadyAdded, List<String> ignoredFiles) {
    Resource[] ress = CoreSpringFactory.getResources(resourcePath);
    for (int i = 0; i < ress.length; i++) {
        Resource res = ress[i];
        InputStream is;
        String fileName = res.getFilename();
        if (ignoredFiles.contains(fileName)) {
            // then ignore it - dont log either
            continue;
        }
        if (!filesAlreadyAdded.contains(fileName)) {
            filesAlreadyAdded.add(fileName);
            try {
                log.info("Start adding hibernate mapping (xml mapping stream): " + res.getDescription());
                is = res.getInputStream();
                cf.addInputStream(is);
                log.info("Loaded hibernate mapping (xml mapping stream): " + res.getDescription());
            } catch (IOException e) {
                throw new AssertException("i/o error while getting inputstream of resource:" + res.getDescription());
            }
        } else {
            log.warn("Douplicate hibernate mapping file::" + fileName + " found on classpath, skipping " + res.toString());
        }
    }
}
 
Example 6
Source Project: olat   File: DatabaseSetup.java    License: Apache License 2.0 6 votes vote down vote up
private static void addHibernateFilesMatching(final String resourcePath, List<String> filesAlreadyAdded, List<String> ignoredFiles) {
    Resource[] ress = CoreSpringFactory.getResources(resourcePath);
    for (int i = 0; i < ress.length; i++) {
        Resource res = ress[i];
        InputStream is;
        String fileName = res.getFilename();
        if (ignoredFiles.contains(fileName)) {
            // then ignore it - dont log either
            continue;
        }
        if (!filesAlreadyAdded.contains(fileName)) {
            filesAlreadyAdded.add(fileName);
            try {
                log.info("Start adding hibernate mapping (xml mapping stream): " + res.getDescription());
                is = res.getInputStream();
                cf.addInputStream(is);
                log.info("Loaded hibernate mapping (xml mapping stream): " + res.getDescription());
            } catch (IOException e) {
                throw new AssertException("i/o error while getting inputstream of resource:" + res.getDescription());
            }
        } else {
            log.warn("Douplicate hibernate mapping file::" + fileName + " found on classpath, skipping " + res.toString());
        }
    }
}
 
Example 7
/**
 * Return the description for the given Resource; if the description is
 * empty, return the class name of the resource plus its identity hash code.
 * @see org.springframework.core.io.Resource#getDescription()
 */
private static String getNameForResource(Resource resource) {
	String name = resource.getDescription();
	if (!StringUtils.hasText(name)) {
		name = resource.getClass().getSimpleName() + "@" + System.identityHashCode(resource);
	}
	return name;
}
 
Example 8
Source Project: mPaaS   File: ResourceLoadFactory.java    License: Apache License 2.0 5 votes vote down vote up
private String getNameForResource(Resource resource) {
    String name = resource.getDescription();
    if (!StringUtils.hasText(name)) {
        name = resource.getClass().getSimpleName() + "@" + System.identityHashCode(resource);
    }
    return name;
}
 
Example 9
Source Project: mPass   File: ResourceLoadFactory.java    License: Apache License 2.0 5 votes vote down vote up
private String getNameForResource(Resource resource) {
    String name = resource.getDescription();
    if (!StringUtils.hasText(name)) {
        name = resource.getClass().getSimpleName() + "@" + System.identityHashCode(resource);
    }
    return name;
}
 
Example 10
/**
 * Return the description for the given Resource; if the description is
 * empty, return the class name of the resource plus its identity hash code.
 * @see org.springframework.core.io.Resource#getDescription()
 */
private static String getNameForResource(Resource resource) {
	String name = resource.getDescription();
	if (!StringUtils.hasText(name)) {
		name = resource.getClass().getSimpleName() + "@" + System.identityHashCode(resource);
	}
	return name;
}
 
Example 11
/**
 * Return the description for the given Resource; if the description is
 * empty, return the class name of the resource plus its identity hash code.
 * @see org.springframework.core.io.Resource#getDescription()
 */
private static String getNameForResource(Resource resource) {
	String name = resource.getDescription();
	if (!StringUtils.hasText(name)) {
		name = resource.getClass().getSimpleName() + "@" + System.identityHashCode(resource);
	}
	return name;
}
 
Example 12
/**
 * Return the description for the given Resource; if the description is
 * empty, return the class name of the resource plus its identity hash code.
 * @see org.springframework.core.io.Resource#getDescription()
 */
private static String getNameForResource(Resource resource) {
	String name = resource.getDescription();
	if (!StringUtils.hasText(name)) {
		name = resource.getClass().getSimpleName() + "@" + System.identityHashCode(resource);
	}
	return name;
}
 
Example 13
private String getNameForResource(Resource resource) {
    String name = resource.getDescription();

    if (!StringUtils.hasText(name)) {
        name = resource.getClass().getSimpleName() + "@" + System.identityHashCode(resource);
    }

    return name;
}
 
Example 14
@Override
public URLClassLoader createAppClassLoader(Resource app) {
	try {
		return new BootClassLoaderFactory(resolveAsArchive(app), parent).createClassLoader();
	}
	catch (IOException e) {
		throw new RuntimeException("Failed to resolve application resource: " + app.getDescription(), e);
	}
}
 
Example 15
protected Properties loadProperties(Resource resource) {
	try {
		return PropertiesLoaderUtils.loadProperties(resource);
	}
	catch (IOException e) {
		throw new RuntimeException("Error reading from " + resource.getDescription(), e);
	}
}
 
Example 16
private Stream<String> resourceAsLines(Resource resource) {
	try {
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
		return bufferedReader.lines();
	}
	catch (Exception e) {
		throw new RuntimeException("Error reading from " + resource.getDescription(), e);
	}
}
 
Example 17
private URL toUrl(Resource resource) {
    try {
        return resource.getURL();
    } catch (IOException e) {
        throw new IllegalStateException("Failed to get url from " + resource.getDescription(), e);
    }
}
 
Example 18
protected void autoDeployResources(ProcessEngine processEngine) {
  if (deploymentResources!=null && deploymentResources.length>0) {
    RepositoryService repositoryService = processEngine.getRepositoryService();

    DeploymentBuilder deploymentBuilder = repositoryService
      .createDeployment()
      .enableDuplicateFiltering(deployChangedOnly)
      .name(deploymentName)
      .tenantId(deploymentTenantId);

    for (Resource resource : deploymentResources) {
      String resourceName = null;

      if (resource instanceof ContextResource) {
        resourceName = ((ContextResource) resource).getPathWithinContext();

      } else if (resource instanceof ByteArrayResource) {
        resourceName = resource.getDescription();

      } else {
        resourceName = getFileResourceName(resource);
      }

      try {
        if ( resourceName.endsWith(".bar")
             || resourceName.endsWith(".zip")
             || resourceName.endsWith(".jar") ) {
          deploymentBuilder.addZipInputStream(new ZipInputStream(resource.getInputStream()));
        } else {
          deploymentBuilder.addInputStream(resourceName, resource.getInputStream());
        }
      } catch (IOException e) {
        throw new ProcessEngineException("couldn't auto deploy resource '"+resource+"': "+e.getMessage(), e);
      }
    }

    deploymentBuilder.deploy();
  }
}
 
Example 19
Source Project: tensorflow   File: ModelExtractor.java    License: Apache License 2.0 4 votes vote down vote up
public byte[] getModel(Resource modelResource) {

		Assert.notNull(modelResource, "Not null model resource is required!");

		try (InputStream is = modelResource.getInputStream();
			 InputStream bi = new BufferedInputStream(is)) {

			String[] archiveCompressor = detectArchiveAndCompressor(modelResource.getFilename());
			String archive = archiveCompressor[0];
			String compressor = archiveCompressor[1];
			String fragment = modelResource.getURI().getFragment();

			if (StringUtils.hasText(compressor)) {
				try (CompressorInputStream cis = new CompressorStreamFactory().createCompressorInputStream(compressor, bi)) {
					if (StringUtils.hasText(archive)) {
						try (ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(archive, cis)) {
							// Compressor with Archive
							return findInArchiveStream(fragment, ais);
						}
					}
					else { // Compressor only
						return StreamUtils.copyToByteArray(cis);
					}
				}
			}
			else if (StringUtils.hasText(archive)) { // Archive only
				try (ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(archive, bi)) {
					return findInArchiveStream(fragment, ais);
				}
			}
			else {
				// No compressor nor Archive
				return StreamUtils.copyToByteArray(bi);
			}
		}
		catch (Exception e) {
			throw new IllegalStateException("Failed to extract a model from: " + modelResource.getDescription(), e);
		}
	}