Example usage for java.io StringBufferInputStream StringBufferInputStream

List of usage examples for java.io StringBufferInputStream StringBufferInputStream

Introduction

In this page you can find the example usage for java.io StringBufferInputStream StringBufferInputStream.

Prototype

public StringBufferInputStream(String s) 

Source Link

Document

Creates a string input stream to read data from the specified string.

Usage

From source file:com.knowgate.dfs.FileSystem.java

/**
 * Download an HTML page and all its referenced files into a ZIP
 * @param sBasePath String Base path for page and its referenced files
 * @param sFilePath String File path from sBasePath
 * @param oOutStrm OutputStream where ZIP is written
 * @param sDefaultEncoding Character encoding of file to be downloaded
 * @throws IOException/*  w  w w.j  a v a  2s  .  co  m*/
 * @since 7.0
 */
public void downloadhtmlpage(String sBasePath, String sFilePath, OutputStream oOutStrm, String sDefaultEncoding)
        throws IOException {

    if (DebugFile.trace) {
        DebugFile.writeln("Begin FileSystem.downloadhtmlpage(" + sBasePath + "," + sFilePath
                + ",[OutputStream]," + sDefaultEncoding + ")");
        DebugFile.incIdent();
    }

    String sEncoding = sDefaultEncoding;
    String sBaseHref = "";
    boolean bAutoDetectEncoding = (sDefaultEncoding == null);
    TreeSet<String> oFiles = new TreeSet<String>();
    TreeSet<String> oEntries = new TreeSet<String>();
    Perl5Matcher oMatcher = new Perl5Matcher();
    Perl5Matcher oReplacer = new Perl5Matcher();
    Perl5Compiler oCompiler = new Perl5Compiler();

    if (sDefaultEncoding == null)
        sDefaultEncoding = "ASCII";

    try {
        String sHtml = readfilestr(sBasePath + sFilePath, sDefaultEncoding);

        if (null == sHtml) {
            if (DebugFile.trace) {
                DebugFile.writeln("Could not read file " + sBasePath + sFilePath);
                DebugFile.decIdent();
                throw new IOException("Could not read file " + sBasePath + sFilePath);
            }
        }

        if (DebugFile.trace) {
            DebugFile.writeln(
                    String.valueOf(sHtml.length()) + " characters readed from file " + sBasePath + sFilePath);
        }

        if (bAutoDetectEncoding) {
            if (oMatcher.contains(sHtml, oCompiler.compile(
                    "<meta\\x20+http-equiv=(\"|')?Content-Type(\"|')?\\x20+content=(\"|')?text/html;\\x20+charset=(\\w|-){3,32}(\"|')?>",
                    Perl5Compiler.CASE_INSENSITIVE_MASK))) {
                if (DebugFile.trace)
                    DebugFile.writeln("<meta http-equiv> tag found");
                String sHttpEquiv = oMatcher.getMatch().toString();
                int iCharset = Gadgets.indexOfIgnoreCase(sHttpEquiv, "charset=");
                if (iCharset > 0) {
                    int iQuoute = sHttpEquiv.indexOf('"', iCharset);
                    if (iQuoute < 0)
                        iQuoute = sHttpEquiv.indexOf((char) 39, iCharset);
                    if (iQuoute < 0) {
                        bAutoDetectEncoding = true;
                    } else {
                        sEncoding = sHttpEquiv.substring(iCharset + 8, iQuoute);
                        if (DebugFile.trace)
                            DebugFile.writeln("setting charset encoding to " + sEncoding);
                        bAutoDetectEncoding = false;
                        try {
                            byte[] aTest = new String("Test").getBytes(sEncoding);
                        } catch (UnsupportedEncodingException uex) {
                            bAutoDetectEncoding = true;
                        }
                    }
                } else {
                    bAutoDetectEncoding = true;
                }
            } else {
                bAutoDetectEncoding = true;
            }
        }

        if (bAutoDetectEncoding) {
            if (DebugFile.trace)
                DebugFile.writeln("Autodetecting encoding");
            ByteArrayInputStream oHtmlStrm = new ByteArrayInputStream(sHtml.getBytes(sDefaultEncoding));
            sEncoding = new CharacterSetDetector().detect(oHtmlStrm, sDefaultEncoding);
            oHtmlStrm.close();
            if (DebugFile.trace)
                DebugFile.writeln("Encoding set to " + sEncoding);
        }

        Pattern oPattern = oCompiler.compile("<base(\\x20)+href=(\"|')?([^'\"\\r\\n]+)(\"|')?(\\x20)*/?>",
                Perl5Compiler.CASE_INSENSITIVE_MASK);
        if (oMatcher.contains(sHtml, oPattern)) {
            sBaseHref = Gadgets.chomp(oMatcher.getMatch().group(3), "/");
            if (DebugFile.trace)
                DebugFile.writeln("<base href=" + sBaseHref + ">");
        }

        PatternMatcherInput oMatchInput = new PatternMatcherInput(sHtml);
        oPattern = oCompiler.compile(
                "\\x20(src=|background=|background-image:url\\x28)(\"|')?([^'\"\\r\\n]+)(\"|')?(\\x20|\\x29|/|>)",
                Perl5Compiler.CASE_INSENSITIVE_MASK);
        StringSubstitution oSrcSubs = new StringSubstitution();
        int nMatches = 0;
        while (oMatcher.contains(oMatchInput, oPattern)) {
            nMatches++;
            String sMatch = oMatcher.getMatch().toString();
            String sAttr = oMatcher.getMatch().group(1);
            String sQuo = oMatcher.getMatch().group(2);
            if (sQuo == null)
                sQuo = "";
            String sSrc = oMatcher.getMatch().group(3);
            if (DebugFile.trace)
                DebugFile.writeln("Source file found at " + sSrc);
            String sEnd = oMatcher.getMatch().group(5);
            if (!oFiles.contains(sSrc))
                oFiles.add(sSrc);
            String sFilename = sSrc.substring(sSrc.replace('\\', '/').lastIndexOf('/') + 1);
            if (DebugFile.trace)
                DebugFile.writeln("StringSubstitution.setSubstitution(" + sMatch + " replace with "
                        + sMatch.substring(0, sAttr.length() + 1) + sQuo + sFilename + sQuo + sEnd + ")");
            oSrcSubs.setSubstitution(sMatch.substring(0, sAttr.length() + 1) + sQuo + sFilename + sQuo + sEnd);
            sHtml = Util.substitute(oReplacer, oCompiler.compile(sMatch), oSrcSubs, sHtml, Util.SUBSTITUTE_ALL);
        } //wend

        oMatchInput = new PatternMatcherInput(sHtml);
        oPattern = oCompiler.compile(
                "<link\\x20+(rel=(\"|')?stylesheet(\"|')?\\x20+)?(type=(\"|')?text/css(\"|')?\\x20+)?href=(\"|')?([^'\"\\r\\n]+)(\"|')?");
        while (oMatcher.contains(oMatchInput, oPattern)) {
            nMatches++;
            String sMatch = oMatcher.getMatch().toString();
            String sSrc = oMatcher.getMatch().group(8);
            String sFilename = sSrc.substring(sSrc.replace('\\', '/').lastIndexOf('/') + 1);
            if (!oFiles.contains(sSrc))
                oFiles.add(sSrc);
            if (DebugFile.trace)
                DebugFile.writeln("StringSubstitution.setSubstitution(" + sMatch + " replace with "
                        + Gadgets.replace(sMatch, sSrc, sFilename) + ")");
            oSrcSubs.setSubstitution(Gadgets.replace(sMatch, sSrc, sFilename));
            sHtml = Util.substitute(oReplacer, oCompiler.compile(sMatch), oSrcSubs, sHtml);
        } // wend     

        if (DebugFile.trace) {
            DebugFile.writeln(String.valueOf(nMatches) + " matches found");
            DebugFile.write("\n" + sHtml + "\n");
        }

        ZipOutputStream oZOut = new ZipOutputStream(oOutStrm);
        String sLocalName = sFilePath.substring(sFilePath.replace('\\', '/').lastIndexOf('/') + 1);
        int iDot = sLocalName.lastIndexOf('.');
        if (iDot > 0)
            sLocalName = Gadgets.ASCIIEncode(sLocalName.substring(0, iDot)).toLowerCase() + ".html";
        else
            sLocalName = Gadgets.ASCIIEncode(sLocalName).toLowerCase();
        oEntries.add(sLocalName);
        if (DebugFile.trace)
            DebugFile.writeln("Putting entry " + sLocalName + " into ZIP");
        oZOut.putNextEntry(new ZipEntry(sLocalName));
        StringBufferInputStream oHtml = new StringBufferInputStream(sHtml);
        new StreamPipe().between(oHtml, oZOut);
        oHtml.close();
        oZOut.closeEntry();

        for (String sName : oFiles) {
            String sZipEntryName = sName.substring(sName.replace('\\', '/').lastIndexOf('/') + 1);
            if (!oEntries.contains(sZipEntryName)) {
                oEntries.add(sZipEntryName);
                if (DebugFile.trace)
                    DebugFile.writeln("Putting entry " + sZipEntryName + " into ZIP");
                oZOut.putNextEntry(new ZipEntry(sZipEntryName));
                if (sName.startsWith("http://") || sName.startsWith("https://") || sName.startsWith("file://")
                        || sBaseHref.length() > 0) {
                    try {
                        new StreamPipe().between(new ByteArrayInputStream(readfilebin(sBaseHref + sName)),
                                oZOut);
                    } catch (IOException ioe) {
                        if (DebugFile.trace) {
                            DebugFile.decIdent();
                            DebugFile.writeln("Could not download file " + sName);
                        }
                    }
                } else {
                    try {
                        byte[] aFile = readfilebin(
                                sBasePath + (sName.startsWith("/") ? sName.substring(1) : sName));
                        if (null != aFile) {
                            if (aFile.length > 0)
                                new StreamPipe().between(new ByteArrayInputStream(aFile), oZOut);
                        } else {
                            DebugFile.writeln("Could not find file " + sBasePath
                                    + (sName.startsWith("/") ? sName.substring(1) : sName));
                        }
                    } catch (IOException ioe) {
                        if (DebugFile.trace) {
                            DebugFile.decIdent();
                            DebugFile.writeln("Could not download file " + sBasePath
                                    + (sName.startsWith("/") ? sName.substring(1) : sName));
                        }
                    }
                }
                oZOut.closeEntry();
            } // fi (sName!=sLocalName)
        } // next
        oZOut.close();

    } catch (MalformedPatternException mpe) {

    } catch (FTPException ftpe) {

    }

    if (DebugFile.trace) {
        DebugFile.decIdent();
        DebugFile.writeln("End FileSystem.downloadhtmlpage()");
    }
}

From source file:org.acmsl.dotparser.antlr.DotParserTest.java

/**
 * Tests the DotParser./*from w ww  .  j  a v  a2  s.co  m*/
 */
public void testParser() {
    try {
        DotLexer t_DotLexer = new DotLexer(new StringBufferInputStream(TEST_INPUT_1));

        assertNotNull(t_DotLexer);

        TokenBuffer t_TokenBuffer = new TokenBuffer(t_DotLexer);

        assertNotNull(t_TokenBuffer);

        DotParser t_DotParser = new DotParser(t_TokenBuffer);

        assertNotNull(t_DotParser);

        t_DotParser.graph();

        assertNotNull(t_DotParser.getAST());

        t_DotLexer = new DotLexer(new StringBufferInputStream(TEST_INPUT_2));

        assertNotNull(t_DotLexer);

        t_TokenBuffer = new TokenBuffer(t_DotLexer);

        assertNotNull(t_TokenBuffer);

        t_DotParser = new DotParser(t_TokenBuffer);

        assertNotNull(t_DotParser);

        t_DotParser.graph();

        assertNotNull(t_DotParser.getAST());

        t_DotLexer = new DotLexer(new StringBufferInputStream(TEST_INPUT_3));

        assertNotNull(t_DotLexer);

        t_TokenBuffer = new TokenBuffer(t_DotLexer);

        assertNotNull(t_TokenBuffer);

        t_DotParser = new DotParser(t_TokenBuffer);

        assertNotNull(t_DotParser);

        t_DotParser.graph();

        assertNotNull(t_DotParser.getAST());

        antlr.debug.misc.ASTFrame frame = new antlr.debug.misc.ASTFrame("AST JTree Example",
                t_DotParser.getAST());
        frame.setVisible(true);

        while (true)
            ;
    } catch (final Throwable throwable) {
        LogFactory.getLog(getClass()).fatal(throwable);

        fail("" + throwable);
    }
}

From source file:org.acmsl.dotparser.GraphManagerTest.java

/**
 * Tests <code>GraphManager.getGraph()</code> method, with the
 * input defined in <code>DotParserTest.TEST_INPUT_1</code>.
 * @see org.acmsl.dotparser.GraphManager#getGraph()
 * @see org.acmsl.dotparser.antlr.DotParserTest#TEST_INPUT_1
 *//*from www. ja  v a 2s . c om*/
public void testParse1() {
    try {
        InputStream t_isDotInput = new StringBufferInputStream(DotParserTest.TEST_INPUT_1);

        GraphManager t_GraphManager = new GraphManager(t_isDotInput);

        assertNotNull(t_GraphManager);

        Graph t_Graph = t_GraphManager.getGraph();

        assertNotNull(t_Graph);

        assertEquals("nlpMessagingGenerator", t_Graph.getName());
        assertTrue(t_Graph.getDirected() == false);

        List t_lNodes = t_Graph.getNodes();

        assertNotNull(t_lNodes);

        Node[] t_aNodes = (Node[]) t_lNodes.toArray(new Node[0]);

        assertTrue(t_aNodes.length == 8);
        int t_iIndex = 0;

        testNode(t_aNodes[t_iIndex], "start");
        testArg(t_aNodes[t_iIndex], "label", "");
        testArg(t_aNodes[t_iIndex], "shape", "circle");
        testArg(t_aNodes[t_iIndex], "fillcolor", "black");
        testArg(t_aNodes[t_iIndex], "fixedsize", "true");
        testArg(t_aNodes[t_iIndex++], "width", "0.2");

        testNode(t_aNodes[t_iIndex], "readXml");
        testArg(t_aNodes[t_iIndex++], "label", "Read XML");

        testNode(t_aNodes[t_iIndex], "retrieveNextCommType");
        testArg(t_aNodes[t_iIndex++], "label", "Retrieve next\nCommunication Type");

        testNode(t_aNodes[t_iIndex], "checkCommType");
        testArg(t_aNodes[t_iIndex++], "label", "Check whether\nCommunication Type\nexists");

        testNode(t_aNodes[t_iIndex], "createCommType");
        testArg(t_aNodes[t_iIndex++], "label", "Create Communication Type");

        testNode(t_aNodes[t_iIndex], "createTemplate");
        testArg(t_aNodes[t_iIndex++], "label", "Create Template");

        testNode(t_aNodes[t_iIndex], "error");
        testArg(t_aNodes[t_iIndex], "label", "Error");
        testArg(t_aNodes[t_iIndex], "layer", "error");
        testArg(t_aNodes[t_iIndex++], "fillcolor", "red");

        testNode(t_aNodes[t_iIndex], "end");
        testArg(t_aNodes[t_iIndex], "label", "");
        testArg(t_aNodes[t_iIndex], "shape", "doublecircle");
        testArg(t_aNodes[t_iIndex], "fillcolor", "black");
        testArg(t_aNodes[t_iIndex], "fixedsize", "true");
        testArg(t_aNodes[t_iIndex++], "width", "0.2");

        List t_lEdges = t_Graph.getEdges();
        Edge[] t_aEdges = (Edge[]) t_lEdges.toArray(new Edge[0]);

        assertTrue(t_aEdges.length == 14);
        t_iIndex = 0;
        Node t_LeftNode = null;
        Node t_RightNode = null;

        testEdge(t_aEdges[t_iIndex], t_aNodes[0], t_aNodes[1], false);
        testArg(t_aEdges[t_iIndex++], "label", "0");

        testEdge(t_aEdges[t_iIndex], t_aNodes[1], t_aNodes[2], false);
        testArg(t_aEdges[t_iIndex++], "label", "0");

        testEdge(t_aEdges[t_iIndex], t_aNodes[1], t_aNodes[6], false);
        testArg(t_aEdges[t_iIndex], "label", "-1");
        testArg(t_aEdges[t_iIndex], "layer", "error");
        testArg(t_aEdges[t_iIndex], "color", "gray85");
        testArg(t_aEdges[t_iIndex++], "fontcolor", "gray85");

        testEdge(t_aEdges[t_iIndex], t_aNodes[2], t_aNodes[3], false);
        testArg(t_aEdges[t_iIndex], "label", "0");
        testArg(t_aEdges[t_iIndex++], "decorate", "true");

        testEdge(t_aEdges[t_iIndex], t_aNodes[2], t_aNodes[7], false);
        testArg(t_aEdges[t_iIndex], "label", "1");
        testArg(t_aEdges[t_iIndex], "color", "darkgoldenrod4");
        testArg(t_aEdges[t_iIndex++], "fontcolor", "darkgoldenrod4");

        testEdge(t_aEdges[t_iIndex], t_aNodes[2], t_aNodes[6], false);
        testArg(t_aEdges[t_iIndex], "label", "-1");
        testArg(t_aEdges[t_iIndex], "layer", "error");
        testArg(t_aEdges[t_iIndex], "color", "gray85");
        testArg(t_aEdges[t_iIndex++], "fontcolor", "gray85");

        testEdge(t_aEdges[t_iIndex], t_aNodes[3], t_aNodes[2], false);
        testArg(t_aEdges[t_iIndex++], "label", "0");

        testEdge(t_aEdges[t_iIndex], t_aNodes[3], t_aNodes[4], false);
        testArg(t_aEdges[t_iIndex], "label", "1");
        testArg(t_aEdges[t_iIndex], "color", "darkgoldenrod4");
        testArg(t_aEdges[t_iIndex++], "fontcolor", "darkgoldenrod4");

        testEdge(t_aEdges[t_iIndex], t_aNodes[3], t_aNodes[6], false);
        testArg(t_aEdges[t_iIndex], "label", "-1");
        testArg(t_aEdges[t_iIndex], "layer", "error");
        testArg(t_aEdges[t_iIndex], "color", "gray85");
        testArg(t_aEdges[t_iIndex++], "fontcolor", "gray85");

        testEdge(t_aEdges[t_iIndex], t_aNodes[4], t_aNodes[5], false);
        testArg(t_aEdges[t_iIndex++], "label", "0");

        testEdge(t_aEdges[t_iIndex], t_aNodes[4], t_aNodes[6], false);
        testArg(t_aEdges[t_iIndex], "label", "-1");
        testArg(t_aEdges[t_iIndex], "layer", "error");
        testArg(t_aEdges[t_iIndex], "color", "gray85");
        testArg(t_aEdges[t_iIndex++], "fontcolor", "gray85");

        testEdge(t_aEdges[t_iIndex], t_aNodes[5], t_aNodes[2], false);
        testArg(t_aEdges[t_iIndex++], "label", "0");

        testEdge(t_aEdges[t_iIndex], t_aNodes[5], t_aNodes[6], false);
        testArg(t_aEdges[t_iIndex], "label", "-1");
        testArg(t_aEdges[t_iIndex], "layer", "error");
        testArg(t_aEdges[t_iIndex], "color", "gray85");
        testArg(t_aEdges[t_iIndex++], "fontcolor", "gray85");

        testEdge(t_aEdges[t_iIndex], t_aNodes[6], t_aNodes[7], false);
        testArg(t_aEdges[t_iIndex], "label", "0");
        testArg(t_aEdges[t_iIndex], "layer", "error");
        testArg(t_aEdges[t_iIndex], "color", "gray85");
        testArg(t_aEdges[t_iIndex++], "fontcolor", "gray85");
    } catch (final Throwable throwable) {
        throwable.printStackTrace(System.err);

        LogFactory.getLog(getClass()).fatal(throwable);

        fail("" + throwable);
    }
}

From source file:org.apache.geode.internal.cache.GemFireCacheImpl.java

/**
 * Initializes the contents of this <code>Cache</code> according to the declarative caching XML
 * file specified by the given <code>DistributedSystem</code>. Note that this operation cannot be
 * performed in the constructor because creating regions in the cache, etc. uses the cache itself
 * (which isn't initialized until the constructor returns).
 *
 * @throws CacheXmlException If something goes wrong while parsing the declarative caching XML
 *         file./*from  w  w w  .  j  a  va 2 s  .  c  om*/
 * @throws TimeoutException If a {@link org.apache.geode.cache.Region#put(Object, Object)}times
 *         out while initializing the cache.
 * @throws CacheWriterException If a <code>CacheWriterException</code> is thrown while
 *         initializing the cache.
 * @throws RegionExistsException If the declarative caching XML file desribes a region that
 *         already exists (including the root region).
 * @throws GatewayException If a <code>GatewayException</code> is thrown while initializing the
 *         cache.
 * 
 * @see #loadCacheXml
 */
private void initializeDeclarativeCache()
        throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException {
    URL url = getCacheXmlURL();
    String cacheXmlDescription = this.cacheConfig.getCacheXMLDescription();
    if (url == null && cacheXmlDescription == null) {
        if (isClient()) {
            determineDefaultPool();
            initializeClientRegionShortcuts(this);
        } else {
            initializeRegionShortcuts(this);
        }
        initializePdxRegistry();
        readyDynamicRegionFactory();
        return; // nothing needs to be done
    }

    try {
        logCacheXML(url, cacheXmlDescription);
        InputStream stream = null;
        if (cacheXmlDescription != null) {
            if (logger.isTraceEnabled()) {
                logger.trace("initializing cache with generated XML: {}", cacheXmlDescription);
            }
            stream = new StringBufferInputStream(cacheXmlDescription);
        } else {
            stream = url.openStream();
        }
        loadCacheXml(stream);
        try {
            stream.close();
        } catch (IOException ignore) {
        }
    } catch (IOException ex) {
        throw new CacheXmlException(
                LocalizedStrings.GemFireCache_WHILE_OPENING_CACHE_XML_0_THE_FOLLOWING_ERROR_OCCURRED_1
                        .toLocalizedString(new Object[] { url.toString(), ex }));

    } catch (CacheXmlException ex) {
        CacheXmlException newEx = new CacheXmlException(
                LocalizedStrings.GemFireCache_WHILE_READING_CACHE_XML_0_1
                        .toLocalizedString(new Object[] { url, ex.getMessage() }));
        newEx.setStackTrace(ex.getStackTrace());
        newEx.initCause(ex.getCause());
        throw newEx;
    }
}

From source file:org.apache.storm.command.rebalance.java

private static HashMap<String, Integer> parseExecutor(String str) {
    str = org.apache.commons.lang.StringUtils.deleteWhitespace(str);
    HashMap<String, Integer> executor = new HashMap<String, Integer>();
    String[] strs = str.split(",");
    Properties properties = new Properties();
    try {//from  ww w . ja  v  a  2  s. c om
        for (String s : strs) {
            properties.load(new StringBufferInputStream(s));
            for (final String name : properties.stringPropertyNames()) {
                Integer value = CoreUtil.parseInt(properties.getProperty(name));
                executor.put(name, value.intValue());
            }
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    return executor;
}

From source file:org.dataconservancy.dcs.access.server.TransformerServiceImpl.java

@Override
public SchemaType.Name validateXML(String inputXml, String schemaURI) {

    if (schemaURI == null)
        return null;
    for (SchemaType.Name schemaName : SchemaType.Name.values()) {
        if (Pattern.compile(Pattern.quote(schemaName.nameValue()), Pattern.CASE_INSENSITIVE).matcher(schemaURI)
                .find()) {//from   w  w  w . j  a v  a 2s  . co  m
            DocumentBuilder parser;
            Document document;
            try {

                parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();

                document = parser.parse(new StringBufferInputStream(inputXml));

                SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

                Source schemaFile = new StreamSource(
                        new File(getServletContext().getContextPath() + "xml/" + schemaName.name() + ".xsd"));
                Schema schema = factory.newSchema(schemaFile);

                Validator validator = schema.newValidator();
                validator.validate(new DOMSource(document));
                return schemaName;
            } catch (Exception e) {
                e.printStackTrace();

            }

        }
    }
    return null;

}

From source file:org.eclipse.emf.teneo.hibernate.HbEntityDataStore.java

/**
 * Maps an ecore model of one ore more epackages into a hibernate xml String
 * which is added to the passed configuration
 *///from w  w  w . ja v  a2  s.c om
protected void mapModel() {
    if (getPersistenceOptions().isUseMappingFile() || getPersistenceOptions().getMappingFilePath() != null) {
        if (log.isDebugEnabled()) {
            log.debug("Searching hbm files in class paths of epackages");
        }
        final String[] fileList = getMappingFileList();
        for (String element : fileList) {
            if (log.isDebugEnabled()) {
                log.debug("Adding file " + element + " to Hibernate Configuration");
            }
            final PersistenceFileProvider pfp = getExtensionManager()
                    .getExtension(PersistenceFileProvider.class);
            final InputStream is = pfp.getFileContent(this.getClass(), element);
            if (is == null) {
                throw new HbStoreException("Path to mapping file: " + element + " does not exist!");
            }
            getConfiguration().addInputStream(is);
        }
    } else {
        setMappingXML(mapEPackages());

        boolean hasEAVMapping = false;
        for (PAnnotatedEPackage aPackage : getPaModel().getPaEPackages()) {
            for (PAnnotatedEClass aClass : aPackage.getPaEClasses()) {
                if (aClass.getEavMapping() != null) {
                    hasEAVMapping = true;
                    break;
                }
            }
        }
        if (hasEAVMapping) {
            try {
                if (getPersistenceOptions().getEAVMappingFile() != null) {
                    final PersistenceFileProvider pfp = getExtensionManager()
                            .getExtension(PersistenceFileProvider.class);
                    final InputStream is = pfp.getFileContent(this.getClass(),
                            getPersistenceOptions().getEAVMappingFile());
                    getConfiguration().addInputStream(processEAV(is));
                    is.close();
                } else {
                    final PersistenceFileProvider pfp = getExtensionManager()
                            .getExtension(PersistenceFileProvider.class);
                    final InputStream is = pfp.getFileContent(EAVGenericIDUserType.class, "eav.hbm.xml");
                    getConfiguration().addInputStream(processEAV(is));
                    is.close();
                }
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }

        // TODO replace this
        final StringBufferInputStream is = new StringBufferInputStream(getMappingXML());
        getConfiguration().addInputStream(is);
    }
}

From source file:org.eclipse.emf.teneo.hibernate.HbEntityDataStore.java

protected InputStream processEAV(InputStream is) {
    return new StringBufferInputStream(processEAVMapping(is));
}

From source file:org.gbif.dwca.action.ValidateAction.java

private InputStream getEmlInputStream() throws FileNotFoundException {
    InputStream src = null;//from www  .j  a  v  a  2  s .  c  o m
    if (file != null) {
        // file upload
        src = new FileInputStream(file);
    } else {
        // copy paste in this.meta
        src = new StringBufferInputStream(meta);
    }
    return src;
}

From source file:org.gluu.saml.metadata.SAMLMetadataParser.java

public static EntityIDHandler parseMetadata(String metadata) {
    if (metadata == null)
        return null;

    InputStream is = new StringBufferInputStream(metadata);
    return parseMetadata(is);
}