protected InputStream getLazyStream() throws IOException { return file.openStream(); } }
@Override public InputStream getDescriptorStream() throws IOException { return files.get(descriptorLocation).openStream(); }
@Override public InputStream getEntry(String entryPath) throws IOException { return files.containsKey(entryPath) ? files.get(entryPath).openStream() : null; }
@Override public Object resolveEntity(final String publicID, final String systemID, final String baseURI, final String namespace) throws XMLStreamException { try { return (jobXmlFiles.containsKey(systemID) ? jobXmlFiles.get(systemID).openStream() : null); } catch (IOException e) { throw new XMLStreamException(e); } } });
@Override public InputStream accessInputStream() { try { return virtualFile.openStream(); } catch (IOException e) { throw new ArchiveException( "Unable to open VirtualFile-based InputStream", e ); } }
@Override public InputStream accessInputStream() { try { return virtualFile.openStream(); } catch (IOException e) { throw new ArchiveException( "Unable to open VirtualFile-based InputStream", e ); } }
private static InputStream open(final VirtualFile file) throws DeploymentUnitProcessingException { try { return file.openStream(); } catch (IOException e) { throw new DeploymentUnitProcessingException(e); } }
@Override public InputStream accessInputStream() { try { return virtualFile.openStream(); } catch (IOException e) { throw new ArchiveException( "Unable to open VirtualFile-based InputStream", e ); } }
public static byte[] toBytes(VirtualFile r) throws IOException { byte [] buffer = new byte[1024]; InputStream is = r.openStream(); ByteArrayOutputStream os = new ByteArrayOutputStream(); int bytesRead = is.read(buffer); while( bytesRead > -1 ) { os.write(buffer, 0, bytesRead); bytesRead = is.read(buffer); } Utils.safelyClose(is); return os.toByteArray(); }
@Override public InputStream resolveJobXml(final String jobXml, final ClassLoader classLoader) throws IOException { if (jobXmlFiles.isEmpty() && jobXmlResolvers.isEmpty()) { return null; } for (JobXmlResolver resolver : jobXmlResolvers) { final InputStream in = resolver.resolveJobXml(jobXml, classLoader); if (in != null) { return in; } } final VirtualFile file = jobXmlFiles.get(jobXml); if (file == null) { return null; } if (WildFlySecurityManager.isChecking()) { return AccessController.doPrivileged((PrivilegedAction<InputStream>) () -> { try { return file.openStream(); } catch (IOException e) { throw new RuntimeException(e); } }); } return file.openStream(); }
@Override public InputStream accessInputStream() { try { return virtualFile.openStream(); } catch (IOException e) { throw JPA_LOGGER.cannotOpenVFSStream(e, virtualFile.getName()); } }
/** * @return * @throws IOException */ public InputStream limit(VirtualFile resource) throws IOException { InputStream is = resource.openStream(); long resourceSize = resource.getSize(); // if we're limiting and know we're not going to consume the whole file, we skip // ahead so that we get the tail of the file instead of the beginning of it, and we // toggle the done switch. if(limit != -1){ long leftToRead = limit - amountRead; if(leftToRead < resourceSize){ Utils.skip(is, resourceSize - leftToRead); done = true; } else { amountRead += resourceSize; } } return is; }
private void processExternalMounts(DeploymentUnit deploymentUnit, VirtualFile deploymentRoot) throws DeploymentUnitProcessingException { VirtualFile mounts = deploymentRoot.getChild(WEB_INF_EXTERNAL_MOUNTS); if(!mounts.exists()) { return; } try (InputStream data = mounts.openStream()) { String contents = FileUtils.readFile(data); String[] lines = contents.split("\n"); for(String line : lines) { String trimmed = line; int commentIndex = trimmed.indexOf("#"); if(commentIndex > -1) { trimmed = trimmed.substring(0, commentIndex); } trimmed = trimmed.trim(); if(trimmed.isEmpty()) { continue; } File path = new File(trimmed); if(path.exists()) { deploymentUnit.addToAttachmentList(UndertowAttachments.EXTERNAL_RESOURCES, path); } else { throw UndertowLogger.ROOT_LOGGER.couldNotFindExternalPath(path); } } } catch (IOException e) { throw new RuntimeException(e); } }
private void handleInfoFile(DeploymentUnit deploymentUnit, Module module) { final List<PredicatedHandler> handlerWrappers = new ArrayList<>(); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); try { ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); VirtualFile config = root.getRoot().getChild(WEB_INF); try { if (config.exists()) { handlerWrappers.addAll(PredicatedHandlersParser.parse(config.openStream(), module.getClassLoader())); } Enumeration<URL> paths = module.getClassLoader().getResources(META_INF); while (paths.hasMoreElements()) { URL path = paths.nextElement(); handlerWrappers.addAll(PredicatedHandlersParser.parse(path.openStream(), module.getClassLoader())); } } catch (IOException e) { throw new RuntimeException(e); } if (!handlerWrappers.isEmpty()) { deploymentUnit.putAttachment(PREDICATED_HANDLERS, handlerWrappers); } } finally { Thread.currentThread().setContextClassLoader(oldCl); } }
private EarMetaData handleSpecMetadata(VirtualFile deploymentFile, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException { final VirtualFile applicationXmlFile = deploymentFile.getChild(APPLICATION_XML); if (!applicationXmlFile.exists()) { return null; } InputStream inputStream = null; try { inputStream = applicationXmlFile.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream); return EarMetaDataParser.INSTANCE.parse(xmlReader, propertyReplacer); } catch (Exception e) { throw EeLogger.ROOT_LOGGER.failedToParse(e, applicationXmlFile); } finally { VFSUtils.safeClose(inputStream); } }
private JBossAppMetaData handleJbossMetadata(VirtualFile deploymentFile, final PropertyReplacer propertyReplacer, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException { final VirtualFile applicationXmlFile = deploymentFile.getChild(JBOSS_APP_XML); if (!applicationXmlFile.exists()) { //may have been in jboss-all.xml return deploymentUnit.getAttachment(AppJBossAllParser.ATTACHMENT_KEY); } InputStream inputStream = null; try { inputStream = applicationXmlFile.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream); return JBossAppMetaDataParser.INSTANCE.parse(xmlReader, propertyReplacer); } catch (Exception e) { throw EeLogger.ROOT_LOGGER.failedToParse(e, applicationXmlFile); } finally { VFSUtils.safeClose(inputStream); } }
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if(deploymentUnit.hasAttachment(Attachments.DEPLOYMENT_PROPERTIES)) { return; } final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT); final VirtualFile deploymentFile = deploymentRoot.getRoot(); final VirtualFile propertiesFile = deploymentFile.getChild(DEPLOYMENT_PROPERTIES); if (!propertiesFile.exists()) { return; } Properties properties = new Properties(); InputStream propertyFileStream = null; try { propertyFileStream = propertiesFile.openStream(); properties.load(propertyFileStream); } catch (IOException e) { throw EeLogger.ROOT_LOGGER.failedToLoadJbossProperties(e); } finally { VFSUtils.safeClose(propertyFileStream); } deploymentUnit.putAttachment(Attachments.DEPLOYMENT_PROPERTIES, properties); }
private TldMetaData parseTLD(VirtualFile tld) throws DeploymentUnitProcessingException { if (IMPLICIT_TLD.equals(tld.getName())) { // Implicit TLDs are different from regular TLDs return new TldMetaData(); } InputStream is = null; try { is = tld.openStream(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setXMLResolver(NoopXMLResolver.create()); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is); return TldMetaDataParser.parse(xmlReader); } catch (XMLStreamException e) { throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.toString(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()), e); } catch (IOException e) { throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(tld.toString()), e); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { // Ignore } } }
public static ConnectorXmlDescriptor process(boolean resolveProperties, VirtualFile file, VirtualFile alternateDescriptor, String deploymentName) throws DeploymentUnitProcessingException { // Locate the descriptor final VirtualFile serviceXmlFile; if (alternateDescriptor != null) { serviceXmlFile = alternateDescriptor; } else { serviceXmlFile = file.getChild("/META-INF/ra.xml"); } InputStream xmlStream = null; Connector result = null; try { if (serviceXmlFile != null && serviceXmlFile.exists()) { xmlStream = serviceXmlFile.openStream(); RaParser raParser = new RaParser(); raParser.setSystemPropertiesResolved(resolveProperties); result = raParser.parse(xmlStream); if (result == null) throw ConnectorLogger.ROOT_LOGGER.failedToParseServiceXml(serviceXmlFile); } File root = file.getPhysicalFile(); URL url = root.toURI().toURL(); return new ConnectorXmlDescriptor(result, root, url, deploymentName); } catch (Exception e) { throw ConnectorLogger.ROOT_LOGGER.failedToParseServiceXml(e, serviceXmlFile); } finally { VFSUtils.safeClose(xmlStream); } }
/** * Parse -jboss-beans.xml file. * * @param unit the deployment unit * @param beansXmlFile the beans xml file * @throws DeploymentUnitProcessingException * for any error */ protected void parseDescriptor(DeploymentUnit unit, VirtualFile beansXmlFile) throws DeploymentUnitProcessingException { if (beansXmlFile == null || beansXmlFile.exists() == false) return; InputStream xmlStream = null; try { xmlStream = beansXmlFile.openStream(); final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlStream); final ParseResult<KernelDeploymentXmlDescriptor> result = new ParseResult<KernelDeploymentXmlDescriptor>(); xmlMapper.parseDocument(result, reader); final KernelDeploymentXmlDescriptor xmlDescriptor = result.getResult(); if (xmlDescriptor != null) unit.addToAttachmentList(KernelDeploymentXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor); else throw PojoLogger.ROOT_LOGGER.failedToParse(beansXmlFile); } catch (DeploymentUnitProcessingException e) { throw e; } catch (Exception e) { throw PojoLogger.ROOT_LOGGER.parsingException(beansXmlFile, e); } finally { VFSUtils.safeClose(xmlStream); } }