本文整理汇总了Java中org.simpleframework.xml.core.Persister.read方法的典型用法代码示例。如果您正苦于以下问题:Java Persister.read方法的具体用法?Java Persister.read怎么用?Java Persister.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.simpleframework.xml.core.Persister
的用法示例。
在下文中一共展示了Persister.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSerialization
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
@Nonnull
public static <T> T testSerialization(@Nonnull Class<T> type, @Nonnull T in) throws Exception {
Persister persister = new Persister(new AnnotationStrategy(), newRegistryMatcher());
LOG.info("In: " + in);
ByteArrayOutputStream os = new ByteArrayOutputStream();
persister.write(in, os);
byte[] data = os.toByteArray();
LOG.info("Xml: " + new String(data, Charsets.UTF_8));
ByteArrayInputStream is = new ByteArrayInputStream(data);
T out = persister.read(type, is);
LOG.info("Out: " + out);
return out;
}
示例2: testEnvironmentFilter
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testEnvironmentFilter() throws Exception {
Filter filter = new EnvironmentFilter(null);
Persister persister = new Persister(filter);
Entry entry = persister.read(Entry.class, new StringReader(ENTRY));
assertEquals(entry.number, 1234);
assertEquals(entry.bool, true);
assertEquals(entry.name, "${example.name}");
assertEquals(entry.path, "${example.path}");
Filter systemFilter = new SystemFilter();
Filter environmentFilter = new EnvironmentFilter(systemFilter);
Persister environmentPersister = new Persister(environmentFilter);
Entry secondEntry = environmentPersister.read(Entry.class, new StringReader(ENTRY));
assertEquals(secondEntry.number, 1234);
assertEquals(secondEntry.bool, true);
assertEquals(secondEntry.name, "some name");
assertEquals(secondEntry.path, "/some/path");
assertEquals(secondEntry.constant, "some constant");
}
示例3: testAnnotationType
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testAnnotationType() throws Exception {
Strategy strategy = new AnnotationStrategy();
Persister persister = new Persister(strategy);
StringWriter writer = new StringWriter();
AnnotationExample example = persister.read(AnnotationExample.class, SOURCE);
persister.write(example, writer);
String text = writer.toString();
assertElementHasAttribute(text, "/annotationExample", "age", "10");
assertElementHasAttribute(text, "/annotationExample/name", "key", "name");
AnnotationExample result = persister.read(AnnotationExample.class, text);
assertEquals(example.name, result.name);
assertEquals(example.age, result.age);
validate(result, persister);
}
示例4: testComposite
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testComposite() throws Exception {
Persister persister = new Persister();
CompositeObject object = persister.read(CompositeObject.class, SOURCE);
CompositeEntry objectEntry = object.getObject();
CompositeEntry interfaceEntry = object.getInterface();
assertEquals(interfaceEntry.getName(), "name.1");
assertEquals(interfaceEntry.getName(), "name.1");
assertEquals(objectEntry.getName(), "name.2");
assertEquals(objectEntry.getValue(), "value.2");
List<Entry> interfaceList = object.getInterfaceList();
List<Object> objectList = object.getObjectList();
assertEquals(interfaceList.get(0).getName(), "a");
assertEquals(interfaceList.get(0).getValue(), "a");
assertEquals(interfaceList.get(1).getName(), "b");
assertEquals(interfaceList.get(1).getValue(), "b");
assertEquals(((Entry)objectList.get(0)).getName(), "a");
assertEquals(((Entry)objectList.get(0)).getName(), "a");
assertEquals(((Entry)objectList.get(1)).getName(), "b");
assertEquals(((Entry)objectList.get(1)).getName(), "b");
}
示例5: testHackJob
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testHackJob() throws Exception {
Class<?> type = Class.forName("org.simpleframework.xml.stream.DocumentProvider");
Constructor<?> constructor = type.getDeclaredConstructor();
constructor.setAccessible(true);
Object value = constructor.newInstance();
Field[] fields = NodeBuilder.class.getDeclaredFields();
for(Field field : fields) {
if(field.getName().equalsIgnoreCase("provider")) {
field.setAccessible(true);
field.set(null, value);
}
}
StringReader reader = new StringReader(SOURCE);
InputNode source = NodeBuilder.read(reader);
AnnotationStrategy strategy = new AnnotationStrategy();
Persister persister = new Persister(strategy);
Something something = persister.read(Something.class, source);
assertNotNull(something);
assertEquals(something.text, "some inner text");
assertEquals(something.child1, "11");
assertEquals(something.child2, "True");
}
示例6: testStrategy
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public void testStrategy() throws Exception {
Visitor visitor = new ClassToNamespaceVisitor();
Strategy strategy = new VisitorStrategy(visitor);
Persister persister = new Persister(strategy);
VisitorExample item = new VisitorExample();
StringWriter writer = new StringWriter();
item.put("1", "ONE");
item.put("2", "TWO");
item.add("A");
item.add("B");
persister.write(item, writer);
String text = writer.toString();
System.out.println(text);
VisitorExample recover = persister.read(VisitorExample.class, text);
assertTrue(recover.map.containsKey("1"));
assertTrue(recover.map.containsKey("2"));
assertTrue(recover.items.contains("A"));
assertTrue(recover.items.contains("B"));
validate(recover, persister);
}
示例7: assertAuthorParsing
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
@Test
public void assertAuthorParsing() throws Exception {
Persister persister = new Persister();
final GoodreadsResponse response = persister.read(GoodreadsResponse.class, xml);
final BookWrapper bookWrapper = response.getSearch().getResults().getBookWrappers().get(0);
final String otherBookAuthorName = response.getSearch().getResults()
.getBookWrappers().get(1).getBook().getAuthor().getName();
Assert.assertEquals("Orson Scott Card", bookWrapper.getBook().getAuthor().getName());
Assert.assertEquals("David Eddings", otherBookAuthorName);
}
示例8: parseRegionXML
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public static Region parseRegionXML(Context c, Persister serializer, String response) throws Exception {
Region regionResponse = serializer.read(Region.class, response);
regionResponse = ((Region) processRawFields(c, regionResponse));
// Convert poll text BBcode to HTML if it exists
if (regionResponse.poll != null) {
regionResponse.poll.text = SparkleHelper.transformBBCodeToHtml(c, regionResponse.poll.text);
}
return regionResponse;
}
示例9: parseRegionMessagesXML
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public static RegionMessages parseRegionMessagesXML(Context c, Persister serializer, String response) throws Exception {
RegionMessages messageResponse = serializer.read(RegionMessages.class, response);
if (messageResponse.posts != null && messageResponse.posts.size() > 0) {
for (int i=0; i < messageResponse.posts.size(); i++) {
messageResponse.posts.get(i).messageRaw = messageResponse.posts.get(i).message;
messageResponse.posts.get(i).message = SparkleHelper.transformBBCodeToHtml(c, messageResponse.posts.get(i).message, SparkleHelper.BBCODE_PERMISSIONS_RMB);
}
}
return messageResponse;
}
示例10: queryUserZombieData
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
/**
* Queries the user's zombie data.
*/
private void queryUserZombieData() {
String targetURL = String.format(Locale.US, ZombieControlData.QUERY, PinkaHelper.getActiveUser(this).nationId);
NSStringRequest stringRequest = new NSStringRequest(getApplicationContext(), Request.Method.GET, targetURL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Persister serializer = new Persister();
try {
userData = serializer.read(ZombieControlData.class, response);
queryRegionZombieData();
}
catch (Exception e) {
SparkleHelper.logError(e.toString());
SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_parsing));
mSwipeRefreshLayout.setRefreshing(false);
}
isInProgress = false;
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
SparkleHelper.logError(error.toString());
mSwipeRefreshLayout.setRefreshing(false);
isInProgress = false;
if (error instanceof TimeoutError || error instanceof NoConnectionError || error instanceof NetworkError) {
SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_no_internet));
} else {
SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_generic));
}
}
});
if (!DashHelper.getInstance(this).addRequest(stringRequest)) {
mSwipeRefreshLayout.setRefreshing(false);
isInProgress = false;
SparkleHelper.makeSnackbar(mView, getString(R.string.rate_limit_error));
}
}
示例11: queryRegionZombieData
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
/**
* Queries the user's region's zombie data.
*/
private void queryRegionZombieData() {
String targetURL = String.format(Locale.US, ZombieRegion.QUERY, SparkleHelper.getIdFromName(PinkaHelper.getRegionSessionData(this)));
NSStringRequest stringRequest = new NSStringRequest(getApplicationContext(), Request.Method.GET, targetURL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Persister serializer = new Persister();
try {
regionData = serializer.read(ZombieRegion.class, response);
queryZSuperweaponProgress();
}
catch (Exception e) {
SparkleHelper.logError(e.toString());
SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_parsing));
mSwipeRefreshLayout.setRefreshing(false);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
SparkleHelper.logError(error.toString());
mSwipeRefreshLayout.setRefreshing(false);
if (error instanceof TimeoutError || error instanceof NoConnectionError || error instanceof NetworkError) {
SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_no_internet));
} else {
SparkleHelper.makeSnackbar(mView, getString(R.string.login_error_generic));
}
}
});
if (!DashHelper.getInstance(this).addRequest(stringRequest)) {
mSwipeRefreshLayout.setRefreshing(false);
SparkleHelper.makeSnackbar(mView, getString(R.string.rate_limit_error));
}
}
示例12: queryUnreadCounts
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
/**
* Starts the process to get unread counts from the NS API.
*/
private void queryUnreadCounts() {
if (mNation != null) {
String target = String.format(Locale.US, UserData.UNREAD_QUERY, SparkleHelper.getIdFromName(mNation.name));
NSStringRequest stringRequest = new NSStringRequest(getApplicationContext(), Request.Method.GET, target,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Persister serializer = new Persister();
try {
UserData userData = serializer.read(UserData.class, response);
processUnreadCounts(userData.unread);
}
catch (Exception e) {
SparkleHelper.logError(e.toString());
// Do nothing for dat ~seamless experience~
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
SparkleHelper.logError(error.toString());
}
});
DashHelper.getInstance(this).addRequest(stringRequest);
}
}
示例13: main
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public static void main(String[] list) throws Exception {
Persister persister = new Persister();
File file = new File("example6/example6.xml");
Example example = persister.read(Example.class, file);
System.out.println(example.a);
System.out.println(example.b);
persister.write(example, System.out);
}
示例14: main
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public static void main(String[] list) throws Exception {
Persister persister = new Persister();
File file = new File("example11/example11.xml");
Example example = persister.read(Example.class, file);
System.out.println(example.value);
persister.write(example, System.out);
}
示例15: main
import org.simpleframework.xml.core.Persister; //导入方法依赖的package包/类
public static void main(String[] list) throws Exception {
Persister persister = new Persister();
File file = new File("example3/example3.xml");
Point example = persister.read(Point.class, file);
System.out.println(example.x);
System.out.println(example.y);
}