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

The following examples show how to use org.springframework.core.io.Resource#getDescription() . 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
Source File: DatabaseSetup.java    From olat with 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 2
Source File: AbstractAutoDeploymentStrategy.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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
Source File: AbstractAutoDeploymentStrategy.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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
Source File: DatabaseSetup.java    From olat with 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 5
Source File: CommonAutoDeploymentStrategy.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * 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 6
Source File: AbstractAutoDeploymentStrategy.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * 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 7
Source File: SpringTransactionsProcessEngineConfiguration.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
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 8
Source File: ResourcePropertySource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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 9
Source File: ServerTraceMetadataLoaderService.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private URL toUrl(Resource resource) {
    try {
        return resource.getURL();
    } catch (IOException e) {
        throw new IllegalStateException("Failed to get url from " + resource.getDescription(), e);
    }
}
 
Example 10
Source File: DefaultAppRegistryService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
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 11
Source File: DefaultAppRegistryService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
protected Properties loadProperties(Resource resource) {
	try {
		return PropertiesLoaderUtils.loadProperties(resource);
	}
	catch (IOException e) {
		throw new RuntimeException("Error reading from " + resource.getDescription(), e);
	}
}
 
Example 12
Source File: BootApplicationConfigurationMetadataResolver.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@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 13
Source File: YamlPropertySourceFactory.java    From moon-api-gateway with MIT License 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 14
Source File: ResourcePropertySource.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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 15
Source File: ResourcePropertySource.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 16
Source File: ResourcePropertySource.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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 17
Source File: ResourceLoadFactory.java    From mPass with 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 18
Source File: ResourceLoadFactory.java    From mPaaS with 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 19
Source File: ModelExtractor.java    From tensorflow with 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);
		}
	}