private static void setPersistenceDelegates(XMLEncoder encoder,
Class<?>[] types) {
if (types != null && types.length > 0) {
PersistenceDelegate persistenceDelegate = new EnumPersistenceDelegate();
for (int i = 0; i < types.length; i++) {
encoder.setPersistenceDelegate(types[i], persistenceDelegate);
}
}
// Handle "BiGDecimal" manually (has no default constructor)
encoder.setPersistenceDelegate(BigDecimal.class,
new BigDecimalPersistenceDelegate());
encoder.setPersistenceDelegate(byte[].class,
new ByteArrayPersistenceDelegate());
encoder.setPersistenceDelegate(UUID.class, new UUIDDelegate());
}
java类java.beans.XMLEncoder的实例源码
XMLSerializer.java 文件源码
项目:development
阅读 22
收藏 0
点赞 0
评论 0
PriceModelResource.java 文件源码
项目:development
阅读 16
收藏 0
点赞 0
评论 0
/**
* Get the price model data for the given context and locales
*
* @return the price model data as an XML encoded list of strings
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response getPriceModel() {
FileBilling fb = new FileBilling();
splitParametersToList(contextKeys);
splitParametersToList(contextValues);
List<String> priceModelContent = fb.getPriceModel(contextKeys,
contextValues, locales);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (XMLEncoder xmlEncoder = new XMLEncoder(bos)) {
xmlEncoder.writeObject(priceModelContent);
}
String serializedList = "";
try {
serializedList = bos.toString(StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
}
return Response.ok(serializedList).build();
}
EventData.java 文件源码
项目:bartleby
阅读 19
收藏 0
点赞 0
评论 0
/**
* Serialize all the EventData items into an XML representation.
*
* @param map the Map to transform
* @return an XML String containing all the EventDAta items.
*/
public static String toXML(Map<String, Object> map) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
XMLEncoder encoder = new XMLEncoder(baos);
encoder.setExceptionListener(new ExceptionListener() {
public void exceptionThrown(Exception exception) {
exception.printStackTrace();
}
});
encoder.writeObject(map);
encoder.close();
return baos.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
PainterUtil.java 文件源码
项目:swingx
阅读 20
收藏 0
点赞 0
评论 0
@Override
protected void initialize(Class type, Object oldInstance,
Object newInstance, Encoder out) {
// p("image painter delegate called");
super.initialize(type, oldInstance, newInstance, out);
//p("old instance = " + oldInstance);
//p("owner = " + ((XMLEncoder)out).getOwner());
PersistenceOwner owner = (PersistenceOwner)((XMLEncoder)out).getOwner();
ImagePainter ip = (ImagePainter)oldInstance;
// p("need to convert string: " + ip.getImageString());
// String s = owner.toXMLURL(ip.getImageString());
// p("converted to: " + s);
//out.writeExpression(new Expression(oldInstance,owner,"fromXMLURL",new Object[]{ip.getImageString()}));
//out.writeStatement(new Statement(owner,"fromXMLURL",new Object[]{ip.getImageString()}));
//out.writeStatement(new Statement(oldInstance,"setImageString",new Object[]{
//new Expression(oldInstance,owner,"fromXMLURL",new Object[]{ip.getImageString()})
//}));
out.writeStatement(new Statement(oldInstance,"setResolver",new Object[]{owner}));
// out.writeStatement(new Statement(oldInstance,"setImageString",new Object[]{s}));
}
SerializationDeserialization.java 文件源码
项目:Telepathology
阅读 17
收藏 0
点赞 0
评论 0
/**
* @param original
* @return
*/
public T serializeAndDeserialize(T original)
{
java.io.ByteArrayOutputStream out = new DebuggingByteArrayOutputStream(4096);
XMLEncoder encoder = new XMLEncoder(out);
encoder.writeObject(original);
encoder.close();
dumpByteArray(out.toByteArray());
java.io.ByteArrayInputStream in = new java.io.ByteArrayInputStream(out.toByteArray());
XMLDecoder decoder = new XMLDecoder(in);
T deserialized = (T)decoder.readObject();
decoder.close();
return deserialized;
}
TestArtifactSourceMemento.java 文件源码
项目:Telepathology
阅读 16
收藏 0
点赞 0
评论 0
public void testArtifactRepositoryImplSerialization()
throws MalformedURLException
{
ArtifactSource as = new ArtifactSourceImpl(
WellKnownOID.VA_DOCUMENT.getCanonicalValue(),
"42",
new URL[]{new URL("http://localhost/app/file")},
new URL[]{new URL("http://localhost/app/file")}
);
ArtifactSourceMemento asm = as.getMemento();
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder( out );
encoder.writeObject(asm);
encoder.close();
System.out.println( new String(out.toByteArray()) );
XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(out.toByteArray()));
ArtifactSourceMemento asm2 = (ArtifactSourceMemento)decoder.readObject();
assertEquals(asm, asm2);
}
TestArtifactSourceMemento.java 文件源码
项目:Telepathology
阅读 16
收藏 0
点赞 0
评论 0
public void testSiteImplSerialization()
throws MalformedURLException
{
ArtifactSource as = new SiteImpl(
"660", "Name", "Nm",
"localhost", 9300,
"localhist", 8080,
"42"
);
ArtifactSourceMemento asm = as.getMemento();
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder( out );
encoder.writeObject(asm);
encoder.close();
System.out.println( new String(out.toByteArray()) );
XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(out.toByteArray()));
ArtifactSourceMemento asm2 = (ArtifactSourceMemento)decoder.readObject();
assertEquals(asm, asm2);
}
UserSettings.java 文件源码
项目:sp16-ceg3120
阅读 19
收藏 0
点赞 0
评论 0
/**
* Saves the state of the UserSettings to an XML file.
*
* @param xmlFileName
* Path to saved object
* @return if the settings could be saved
*/
public boolean saveXmlEncodedBean(String xmlFileName) {
boolean succeeded = false;
try (XMLEncoder encoder = new XMLEncoder(
new BufferedOutputStream(new FileOutputStream(xmlFileName)))) {
encoder.writeObject(this);
succeeded = true;
} catch (FileNotFoundException e) {
System.err.println("Failed to write file " + xmlFileName + ".");
}
return succeeded;
}
VirtualFileSystemFile.java 文件源码
项目:drftpd3
阅读 17
收藏 0
点赞 0
评论 0
/**
* Configure the serialization of the File.
*/
@Override
protected void setupXML(XMLEncoder enc) {
super.setupXML(enc);
PropertyDescriptor[] pdArr;
try {
pdArr = Introspector.getBeanInfo(VirtualFileSystemFile.class)
.getPropertyDescriptors();
} catch (IntrospectionException e) {
logger.error("I don't know what to do here", e);
throw new RuntimeException(e);
}
for (PropertyDescriptor pd : pdArr) {
// logger.debug("PropertyDescriptor - VirtualFileSystemFile - "
// + pd.getDisplayName());
if (transientListFile.contains(pd.getName())) {
pd.setValue("transient", Boolean.TRUE);
}
}
// needed to create a VFSFile object during unserialization
enc.setPersistenceDelegate(VirtualFileSystemFile.class,
new DefaultPersistenceDelegate(new String[] { "username",
"group", "size", "slaves" }));
}
VirtualFileSystemLink.java 文件源码
项目:drftpd3
阅读 20
收藏 0
点赞 0
评论 0
@Override
protected void setupXML(XMLEncoder enc) {
super.setupXML(enc);
PropertyDescriptor[] pdArr;
try {
pdArr = Introspector.getBeanInfo(VirtualFileSystemLink.class)
.getPropertyDescriptors();
} catch (IntrospectionException e) {
logger.error("I don't know what to do here", e);
throw new RuntimeException(e);
}
for (int x = 0; x < pdArr.length; x++) {
// logger.debug("PropertyDescriptor - VirtualFileSystemLink - "
// + pdArr[x].getDisplayName());
if (transientListLink.contains(pdArr[x].getName())) {
pdArr[x].setValue("transient", Boolean.TRUE);
}
}
enc.setPersistenceDelegate(VirtualFileSystemLink.class,
new DefaultPersistenceDelegate(new String[] { "username",
"group", "linkPath" }));
}