开发者

Has anyone else seen the Java XML FastInfoset library corrupt text?

开发者 https://www.devze.com 2023-02-02 07:14 出处:网络
I read the claims from Sun people about the wonderful space economy of not only using FastInfoSet, but using it with an external vocab. The code for this purpose is include in the most recent version

I read the claims from Sun people about the wonderful space economy of not only using FastInfoSet, but using it with an external vocab. The code for this purpose is include in the most recent version (1.2.8) but it is not exactly fully documented.

For many files, this works just great for me. However, we've come up with an XML file which, when serialized from DOM with开发者_C百科 the vocab I created (using the generator in the FI library), and then read back into DOM, mismatches. The mismatches are all in PC-data.

I just call setVocabulary on the serializer and setExternalVocabulary with a map from URI to vocabulary on the reader.

I had to invent my own mechanism to actually serialize a vocabulary; there didn't seem to be one anywhere in the FI library.

One fiddly bit of business is that the org.jvnet.fastinfoset.Vocabulary class is what the generator gives you, but it's not what the parsers and serializers eat. I made arrangements to serialize these, and then use the code below to turn them into the needed objects:

private static void initializeAnalysis() {
    InputStream is = FastInfosetUtils.class.getResourceAsStream(ANALYSIS_VOCAB_CLASSPATH);
    try {
        ObjectInputStream ois = new ObjectInputStream(is);
        analysisJvnetVocab = (SerializableVocabulary) ois.readObject();
        ois.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    analysisSerializerVocab = new SerializerVocabulary(analysisJvnetVocab.getVocabulary(), false);
    analysisParserVocab = new ParserVocabulary(analysisJvnetVocab.getVocabulary());
}

and then, to actually write a document:

 SerializerVocabulary fullVocab = new SerializerVocabulary();
 fullVocab.setExternalVocabulary(ANALYSIS_VOCAB_URI, analysisSerializerVocab, false);
 // pass fullVocab to setVocabulary.

and to read:

 Map<Object, Object> vocabMap = new HashMap<Object, Object>();
 vocabMap.put(ANALYSIS_VOCAB_URI, analysisParserVocab);
 // pass map into setExternalVocabulary

I could easily imagine that the recipe for creating serialization vocabularies is not right, it's not like I was reading a tutorial. Anyone happen to know?

UPDATE

Since no one 'round here had anything to add to this question, I make a test case and filed a bug report. Somewhat to my surprise, it turned out that it was, in fact, a bug, and a fix has been made.

0

精彩评论

暂无评论...
验证码 换一张
取 消