Java Code Examples for org.jboss.vfs.VirtualFile#openStream()

The following examples show how to use org.jboss.vfs.VirtualFile#openStream() . 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: ManagedDMRContentTypeResource.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void loadContent(byte[] initialHash) {
    VirtualFile vf = contentRepository.getContent(initialHash);
    if (vf == null) {
        throw ManagedDMRContentLogger.ROOT_LOGGER.noContentFoundWithHash(HashUtil.bytesToHexString(initialHash));
    }
    InputStream is = null;
    try {
        is = vf.openStream();
        ModelNode node = ModelNode.fromStream(is);
        if (node.isDefined()) {
            for (Property prop : node.asPropertyList()) {
                ModelNode value = prop.getValue();
                byte[] hash = hashContent(value);
                synchronized (content) {
                    content.put(prop.getName(), new ManagedContent(value, hash));
                }
            }
        }
        this.model.get(ModelDescriptionConstants.HASH).set(initialHash);
        contentRepository.addContentReference(new ContentReference(address.toCLIStyleString(), initialHash));
    } catch (IOException e) {
        throw new ContentStorageException(e);
    } finally {
        safeClose(is);
    }
}
 
Example 2
Source File: VfsResourceIterator.java    From web-data-extractor with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream next() throws IOException {
    while (true) {
        if (++index >= files.size()) {
            // no files
            return null;
        }
        final VirtualFile f = files.get(index);
        if (f.isFile() && f.getName().endsWith(".class")) {
            return f.openStream();
        }
    }
}
 
Example 3
Source File: ServiceLoaderProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void processRoot(final ResourceRoot resourceRoot, final Map<String, List<String>> foundServices) throws DeploymentUnitProcessingException {
    final VirtualFile virtualFile = resourceRoot.getRoot();
    final VirtualFile child = virtualFile.getChild("META-INF/services");
    for (VirtualFile serviceType : child.getChildren()) {
        final String name = serviceType.getName();
        try {
            List<String> list = foundServices.get(name);
            if (list == null) {
                foundServices.put(name, list = new ArrayList<String>());
            }
            final InputStream stream = serviceType.openStream();
            try {
                final BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
                String line;
                while ((line = reader.readLine()) != null) {
                    final int commentIdx = line.indexOf('#');
                    final String className;
                    if (commentIdx == -1) {
                        className = line.trim();
                    } else {
                        className = line.substring(0, commentIdx).trim();
                    }
                    if (className.length() == 0) {
                        continue;
                    }
                    list.add(className);
                }
            } finally {
                VFSUtils.safeClose(stream);
            }
        } catch (IOException e) {
            throw ServerLogger.ROOT_LOGGER.failedToReadVirtualFile(child, e);
        }
    }
}
 
Example 4
Source File: ScriptProviderDeploymentProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static ScriptProviderDescriptor readScriptProviderDescriptor(VirtualFile deploymentRoot) {
    VirtualFile metadataFile = deploymentRoot.getChild("META-INF/keycloak-scripts.json");

    if (!metadataFile.exists()) {
        return null;
    }

    try (InputStream inputStream = metadataFile.openStream()) {
        return JsonSerialization.readValue(inputStream, ScriptProviderDescriptor.class);
    } catch (IOException cause) {
        throw new RuntimeException("Failed to read providers metadata", cause);
    }
}
 
Example 5
Source File: VfsProcessApplicationScanner.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void addResource(VirtualFile virtualFile, VirtualFile processArchiveRoot, Map<String, byte[]> resources) {
  String resourceName = virtualFile.getPathNameRelativeTo(processArchiveRoot);
  try {
    InputStream inputStream = virtualFile.openStream();
    byte[] bytes = IoUtil.readInputStream(inputStream, resourceName);
    IoUtil.closeSilently(inputStream);
    resources.put(resourceName, bytes);
  }
  catch (IOException e) {
    LOG.cannotReadInputStreamForFile(resourceName, processArchiveRoot, e);
  }
}