Java Code Examples for org.drools.core.util.StringUtils#readFileAsString()

The following examples show how to use org.drools.core.util.StringUtils#readFileAsString() . 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
private static String getPomPropertiesFromZipFile(String rootPath) {
    File actualZipFile = new File( rootPath );
    if ( !actualZipFile.exists() ) {
        log.error( "Unable to load pom.properties from" + rootPath + " as jarPath cannot be found\n" + rootPath );
        return null;
    }

    try (ZipFile zipFile = new ZipFile( actualZipFile )) {
        String file = KieBuilderImpl.findPomProperties( zipFile );
        if ( file == null ) {
            log.warn( "Unable to find pom.properties in " + rootPath );
            return null;
        }
        ZipEntry zipEntry = zipFile.getEntry( file );

        String pomProps = StringUtils.readFileAsString(
                new InputStreamReader( zipFile.getInputStream( zipEntry ), IoUtils.UTF8_CHARSET ) );
        log.debug( "Found and used pom.properties " + file);
        return pomProps;
    } catch ( Exception e ) {
        log.error( "Unable to load pom.properties from " + rootPath + "\n" + e.getMessage() );
    }
    return null;
}
 
Example 2
Source Project: kogito-runtimes   File: ConfigGenerator.java    License: Apache License 2.0 6 votes vote down vote up
private MethodDeclaration generateAddonsMethod() {
    MethodCallExpr asListOfAddons = new MethodCallExpr(new NameExpr("java.util.Arrays"), "asList");
    try {
        Enumeration<URL> urls = classLoader.getResources("META-INF/kogito.addon");
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            String addon = StringUtils.readFileAsString(new InputStreamReader(url.openStream()));
            asListOfAddons.addArgument(new StringLiteralExpr(addon));
        }
    } catch (IOException e) {
        LOGGER.warn("Unexpected exception during loading of kogito.addon files", e);
    }

    BlockStmt body = new BlockStmt().addStatement(new ReturnStmt(
            newObject(Addons.class, asListOfAddons)
    ));

    return method(Keyword.PUBLIC, Addons.class, "addons", body);
}
 
Example 3
public String findPomProperties() {
    for( Entry<String, InternalResource> content : fileContents.entrySet() ) {
        if ( content.getKey().endsWith( "pom.properties" ) && content.getKey().startsWith( "META-INF/maven/" ) ) {
            try (InputStream resourceStream = content.getValue().getInputStream()) {
                return StringUtils.readFileAsString( new InputStreamReader( resourceStream, IoUtils.UTF8_CHARSET ) );
            } catch (IOException ioe) {
                throw new RuntimeException( ioe );
            }
        }
    }
    return null;
}
 
Example 4
@Test
public void testParseCollect() throws Exception {
    final XmlPackageReader xmlPackageReader = getXmReader();
    xmlPackageReader.read( new InputStreamReader( getClass().getResourceAsStream( "test_ParseCollect.xml" ) ) );
    final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();

    String expected = StringUtils.readFileAsString( new InputStreamReader( getClass().getResourceAsStream( "test_ParseCollect.drl" ) ) );
    String expectedWithoutHeader = removeLicenseHeader( expected );
    String actual = new DrlDumper().dump( packageDescr );
    
    assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}
 
Example 5
@Test
public void testParseRule() throws Exception {
    final XmlPackageReader xmlPackageReader = getXmReader();
    xmlPackageReader.read( new InputStreamReader( getClass().getResourceAsStream( "test_ParseRule.xml" ) ) );
    final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();

    String expected = StringUtils.readFileAsString( new InputStreamReader( getClass().getResourceAsStream( "test_ParseRule.drl" ) ) );
    // remove license header as that one is not stored in the XML
    String expectedWithoutHeader = removeLicenseHeader(expected);
    System.out.println(expectedWithoutHeader);
    String actual = new DrlDumper().dump( packageDescr );
    
    assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}
 
Example 6
@Test
public void testParseLhs() throws Exception {
    final XmlPackageReader xmlPackageReader = getXmReader();
    xmlPackageReader.read( new InputStreamReader( getClass().getResourceAsStream( "test_ParseLhs.xml" ) ) );
    final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();

    String expected = StringUtils.readFileAsString( new InputStreamReader( getClass().getResourceAsStream( "test_ParseLhs.drl" ) ) );
    String expectedWithoutHeader = removeLicenseHeader( expected );
    String actual = new DrlDumper().dump( packageDescr );

    assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}
 
Example 7
public static String readWorkflowFile(Reader reader) {
    return StringUtils.readFileAsString(reader);
}