Jsapi10SpokenInput implements SpokenInput, StreamableSpokenInput { @Override public GrammarImplementation<?> loadGrammar(final URI uri, final GrammarType type) throws NoresourceError, IOException, UnsupportedFormatError { if (recognizer == null) { throw new NoresourceError("No recognizer available!"); } if (type != GrammarType.JSGF) { throw new UnsupportedFormatError( "JSAPI 1.0 implementation supports only type " + GrammarType.JSGF.getType()); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("loading grammar from URI '" + uri + "'"); } final RuleGrammar grammar; try { final URL url = uri.toURL(); InputStream input = url.openStream(); final BufferedInputStream bufferedInput = new BufferedInputStream( input); bufferedInput.mark(Integer.MAX_VALUE); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final byte[] buffer = new byte[256]; int read = 0; do { read = bufferedInput.read(buffer); if (read > 0) { out.write(buffer, 0, read); } } while (read >= 0); bufferedInput.reset(); final InputStreamReader reader = new InputStreamReader(bufferedInput); grammar = recognizer.loadJSGF(reader); } catch (javax.speech.recognition.GrammarException ge) { throw new UnsupportedFormatError(ge.getMessage(), ge); } return new RuleGrammarImplementation(grammar, uri); } Jsapi10SpokenInput(final RecognizerModeDesc defaultDescriptor); void open(); void close(); void addListener(final SpokenInputListener inputListener); void removeListener(final SpokenInputListener inputListener); Collection<BargeInType> getSupportedBargeInTypes(); @Override GrammarImplementation<?> loadGrammar(final URI uri,
            final GrammarType type); void activateGrammars(
            final Collection<GrammarImplementation<? extends Object>> grammars); void deactivateGrammars(
            final Collection<GrammarImplementation<? extends Object>> grammars); @Override void startRecognition(
            final DataModel model,
            final SpeechRecognizerProperties speech,
            final DtmfRecognizerProperties dtmf); void stopRecognition(); void activate(); void passivate(); void connect(final ConnectionInformation connectionInformation); void disconnect(final ConnectionInformation connectionInformation); String getType(); Collection<GrammarType> getSupportedGrammarTypes(); void setSpokenInputConnectionHandler(
            final SpokenInputConnectionHandler connectionHandler); URI getUriForNextSpokenInput(); boolean isBusy(); void setStreamableSpokenInput(final StreamableSpokenInput streamable); void writeRecognizerStream(final byte[] buffer, final int offset,
            final int length);  }
@Test public void testLoadGrammar() throws Exception, JVoiceXMLEvent { final String lf = System.getProperty("line.separator"); final String grammar = "#JSGF V1.0;" + lf + "grammar test;" + lf + "public <test> = a|b|c;"; final File file = File.createTempFile("jvxmltest", ".gram"); final URI uri = writeToFile(file, grammar); final RuleGrammarImplementation impl = (RuleGrammarImplementation) recognizer .loadGrammar(uri, GrammarType.JSGF); Assert.assertNotNull(impl); final RuleGrammar ruleGrammar = impl.getGrammarDocument(); Assert.assertEquals("test", ruleGrammar.getName()); final RuleAlternatives alternatives = (RuleAlternatives) ruleGrammar .getRule("test"); Assert.assertNotNull(alternatives); final Rule[] rules = alternatives.getRules(); Assert.assertEquals(3, rules.length); Assert.assertEquals("a", rules[0].toString()); Assert.assertEquals("b", rules[1].toString()); Assert.assertEquals("c", rules[2].toString()); }