Java Code Examples for org.apache.jena.riot.tokens.Token#isWord()

The following examples show how to use org.apache.jena.riot.tokens.Token#isWord() . 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: RDFPatchReaderText.java    From rdf-delta with Apache License 2.0 6 votes vote down vote up
/** Read patch header. */
public static PatchHeader readerHeader(InputStream input) {
    Tokenizer tokenizer = TokenizerFactory.makeTokenizerUTF8(input);
    Map<String, Node> header = new LinkedHashMap<>();
    int lineNumber = 0;
    while(tokenizer.hasNext()) {
      Token tokCode = tokenizer.next();
      if ( tokCode.hasType(DOT) )
          throw exception(tokCode, "Empty header line");
      if ( ! tokCode.isWord() )
          throw exception(tokCode, "Expected keyword at start of patch header");
      String code = tokCode.getImage();
      lineNumber ++;
      if ( ! code.equals(PatchCodes.HEADER) )
          break;
      readHeaderLine(tokenizer, (f,n)->header.put(f, n));
  }
  return new PatchHeader(header);
}
 
Example 2
Source File: RDFPatchReaderText.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
/** Known-to-be-header line */
private static void readHeaderLine(Tokenizer tokenizer, BiConsumer<String, Node> action) {
    Token token2 = nextToken(tokenizer);
    if ( ! token2.isWord() && ! token2.isString() )
        throw exception(tokenizer, "Header does not have a key that is a word: "+token2);
    String field = token2.getImage();
    Node v = nextNode(tokenizer);
    skip(tokenizer, DOT);
    action.accept(field, v);
}