Example usage for org.springframework.core.io Resource isReadable

List of usage examples for org.springframework.core.io Resource isReadable

Introduction

In this page you can find the example usage for org.springframework.core.io Resource isReadable.

Prototype

default boolean isReadable() 

Source Link

Document

Indicate whether non-empty contents of this resource can be read via #getInputStream() .

Usage

From source file:com.haulmont.cuba.core.sys.ResourcesImplTest.java

public void testGetResource() {
    Resource resource;

    resource = resources.getResource("blablabla");
    assertNotNull(resource);/*  w  ww  . j av a  2  s .c o m*/
    assertFalse(resource.exists());
    assertFalse(resource.isReadable());

    resource = resources.getResource("com/haulmont/cuba/core/sys/ResourcesImplTest.class");
    assertNotNull(resource);
    assertTrue(resource.exists());
    assertTrue(resource.isReadable());

    resource = resources.getResource("/com/haulmont/cuba/core/sys/ResourcesImplTest.class");
    assertNotNull(resource);
    assertTrue(resource.exists());
    assertTrue(resource.isReadable());
}

From source file:org.globus.security.stores.ResourceSecurityWrapperStore.java

private boolean loadResources(String locationPattern, Set<V> updatedList, Map<String, T> newWrapperMap)
        throws ResourceStoreException {
    boolean changed = false;
    try {//from   ww  w .ja  va 2s. c  o  m
        Resource[] resources = resolver.getResources(locationPattern);
        for (Resource resource : resources) {
            URI uri = resource.getURI();
            if (!resource.isReadable()) {
                getLogger().warning("Cannot read: " + uri.toASCIIString());
                continue;
            }
            changed = load(resource, updatedList, newWrapperMap);
        }
    } catch (IOException e) {
        throw new ResourceStoreException(e);
    }
    return changed;
}

From source file:org.mitre.jose.TestJWKSetKeyStore.java

@Test
public void ksEmptyConstructorkLoc() {

    JWKSetKeyStore ks = new JWKSetKeyStore();

    File file = new File(ks_file);

    Resource loc = new FileSystemResource(file);
    assertTrue(loc.exists());/*w w  w .  jav  a 2s  .  co m*/
    assertTrue(loc.isReadable());

    ks.setLocation(loc);

    assertEquals(loc.getFilename(), ks.getLocation().getFilename());
}

From source file:com.vilt.minium.jasmine.MiniumJasmineTestRunner.java

private Object getVal(JsVariable jsVariable, Class<?> clazz, Object object) {
    try {// www . j  ava2  s.  c  om
        if (StringUtils.isNotEmpty(jsVariable.resource())) {
            Resource resource = resourceLoader.getResource(jsVariable.resource());
            checkState(resource.exists() && resource.isReadable());

            if (clazz == String.class) {
                InputStream is = resource.getInputStream();
                try {
                    return IOUtils.toString(is, Charsets.UTF_8.name());
                } finally {
                    IOUtils.closeQuietly(is);
                }
            } else {
                Object val = parseJson(rhinoContext, resource);
                checkState(clazz.isAssignableFrom(val.getClass()));
                return val;
            }
        } else {
            return object;
        }
    } catch (IOException e) {
        throw propagate(e);
    } catch (ParseException e) {
        throw propagate(e);
    }
}

From source file:com.haulmont.chile.jpa.loader.JPAAnnotationsLoader.java

@Override
protected List<Class<?>> getClasses(Resource[] resources) {
    List<Class<?>> result = super.getClasses(resources);

    for (Resource resource : resources) {
        if (resource.isReadable()) {
            MetadataReader metadataReader;
            try {
                metadataReader = metadataReaderFactory.getMetadataReader(resource);
            } catch (IOException e) {
                throw new RuntimeException("Unable to read metadata resource", e);
            }//from w  ww .jav  a 2  s .c om

            AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();

            boolean isAnnotated = isEntityClass(annotationMetadata) || isEmbeddableClass(annotationMetadata);
            if (isAnnotated) {
                ClassMetadata classMetadata = metadataReader.getClassMetadata();
                Class c = ReflectionHelper.getClass(classMetadata.getClassName());
                result.add(c);
            }
        }
    }

    return result;
}

From source file:org.globus.security.stores.ResourceSecurityWrapperStore.java

private boolean load(Resource resource, Set<V> currentRoots, Map<String, T> newWrapperMap)
        throws ResourceStoreException {
    if (!resource.isReadable()) {
        throw new ResourceStoreException("Cannot read file");
    }//from  www  .  j a  va  2  s .c o m
    try {
        if (resource.getFile().isDirectory()) {
            File directory = resource.getFile();
            currentRoots.addAll(addCredentials(directory));
            return true;
        }
    } catch (IOException e) {
        // This is ok, it just means the resource is not a
        // filesystemresources
        logger.log(Level.FINE, "Not a filesystem resource", e);
    }
    try {
        String resourceUri = resource.getURL().toExternalForm();
        T fbo = this.wrapperMap.get(resourceUri);
        if (fbo == null) {
            fbo = create(resource);
        }
        V target = fbo.create(resource);
        newWrapperMap.put(resourceUri, fbo);
        currentRoots.add(target);
        return true;
    } catch (IOException e) {
        throw new ResourceStoreException(e);
    }

}

From source file:de.hybris.platform.acceleratorservices.process.strategies.impl.DefaultEmailTemplateTranslationStrategy.java

protected Map loadPropertyfile(final String path) {
    final Properties properties = new Properties();
    Reader reader = null;/*from w ww. j ava 2 s .  c  o m*/
    try {
        final Resource propertyResource = getApplicationContext().getResource(path);
        if (propertyResource != null && (propertyResource.exists()) && (propertyResource.isReadable())) {
            reader = new InputStreamReader(new BOMInputStream(propertyResource.getInputStream()), "UTF-8");
            properties.load(reader);
        }
    } catch (final IOException e) {
        throw new RendererException("Problem during rendering", e);
    } finally {
        IOUtils.closeQuietly(reader);
    }

    return properties;
}

From source file:org.brekka.stillingar.spring.snapshot.ResourceSnapshotManager.java

/**
 * Perform the load operation that will convert a resource into a snapshot.
 * @param resourceToLoad the resouce to load into a snapshot
 * @return the snapshot loaded from the specified resource
 * @throws ConfigurationException if something goes wrong such as an IO error.
 *//*from ww  w .  ja  va 2  s  . c om*/
protected Snapshot performLoad(Resource resourceToLoad) {
    Snapshot snapshot = null;
    if (resourceToLoad != null && resourceToLoad.exists() && resourceToLoad.isReadable()) {
        InputStream sourceStream = null;
        try {
            sourceStream = resourceToLoad.getInputStream();
            long timestamp = resourceToLoad.lastModified();
            ConfigurationSource configurationSource = configurationSourceLoader.parse(sourceStream, null);
            snapshot = new ResourceSnapshot(configurationSource, new Date(timestamp), resourceToLoad);
        } catch (IOException e) {
            throw new ConfigurationException(format("Resouce '%s'", resourceToLoad), e);
        } catch (RuntimeException e) {
            // Wrap to include location details
            throw new ConfigurationException(format("Resouce '%s' processing problem", resourceToLoad), e);
        } finally {
            closeQuietly(sourceStream);
        }
    }
    return snapshot;
}

From source file:org.globus.security.stores.ResourceSigningPolicyStore.java

private void loadSigningPolicy(Resource policyResource, Map<X500Principal, SigningPolicy> policyMapToLoad,
        Map<URI, ResourceSigningPolicy> currentPolicyFileMap) throws SigningPolicyStoreException {

    URI uri;//from   ww  w  . j  a  v  a  2 s .c  om
    if (!policyResource.isReadable()) {
        throw new SigningPolicyStoreException("Cannot read file");
    }
    try {
        uri = policyResource.getURI();
    } catch (IOException e) {
        throw new SigningPolicyStoreException(e);
    }

    ResourceSigningPolicy filePolicy = this.signingPolicyFileMap.get(uri);
    if (filePolicy == null) {
        try {
            filePolicy = new ResourceSigningPolicy(policyResource);
        } catch (ResourceStoreException e) {
            throw new SigningPolicyStoreException(e);
        }
    }
    Collection<SigningPolicy> policies = filePolicy.getSigningPolicies();

    currentPolicyFileMap.put(uri, filePolicy);
    if (policies != null) {
        for (SigningPolicy policy : policies) {
            policyMapToLoad.put(policy.getCASubjectDN(), policy);
        }
    }
}