本文整理匯總了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();
}
}