本文整理汇总了Java中com.thoughtworks.xstream.io.HierarchicalStreamReader.close方法的典型用法代码示例。如果您正苦于以下问题:Java HierarchicalStreamReader.close方法的具体用法?Java HierarchicalStreamReader.close怎么用?Java HierarchicalStreamReader.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thoughtworks.xstream.io.HierarchicalStreamReader
的用法示例。
在下文中一共展示了HierarchicalStreamReader.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createObjectInputStream
import com.thoughtworks.xstream.io.HierarchicalStreamReader; //导入方法依赖的package包/类
/**
* Creates an ObjectInputStream that deserializes a stream of objects from a reader using XStream. <h3>Example</h3>
*
* <pre>
* ObjectInputStream in = xstream.createObjectOutputStream(aReader);
* int a = out.readInt();
* Object b = out.readObject();
* Object c = out.readObject();
* </pre>
*
* @see #createObjectOutputStream(com.thoughtworks.xstream.io.HierarchicalStreamWriter, String)
* @since 1.0.3
*/
public ObjectInputStream createObjectInputStream(final HierarchicalStreamReader reader) throws IOException {
return new CustomObjectInputStream(new CustomObjectInputStream.StreamCallback() {
@Override
public Object readFromStream() throws EOFException {
if (!reader.hasMoreChildren()) {
throw new EOFException();
}
reader.moveDown();
final Object result = unmarshal(reader);
reader.moveUp();
return result;
}
@Override
public Map<String, Object> readFieldsFromStream() throws IOException {
throw new NotActiveException("not in call to readObject");
}
@Override
public void defaultReadObject() throws NotActiveException {
throw new NotActiveException("not in call to readObject");
}
@Override
public void registerValidation(final ObjectInputValidation validation, final int priority)
throws NotActiveException {
throw new NotActiveException("stream inactive");
}
@Override
public void close() {
reader.close();
}
}, classLoaderReference);
}
示例2: fromXML
import com.thoughtworks.xstream.io.HierarchicalStreamReader; //导入方法依赖的package包/类
/**
* Deserialize an object from a file, populating the fields of the given root object instead of instantiating a new
* one. Note, that this is a special use case! With the ReflectionConverter XStream will write directly into the raw
* memory area of the existing object. Use with care! Depending on the parser implementation, some might take the
* file path as SystemId to resolve additional references.
*
* @throws XStreamException if the object cannot be deserialized
* @since 1.4
*/
public <T> T fromXML(final File file, final T root) {
final HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(file);
try {
return unmarshal(reader, root);
} finally {
reader.close();
}
}