本文整理汇总了Java中nu.xom.Serializer类的典型用法代码示例。如果您正苦于以下问题:Java Serializer类的具体用法?Java Serializer怎么用?Java Serializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Serializer类属于nu.xom包,在下文中一共展示了Serializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prettyXml
import nu.xom.Serializer; //导入依赖的package包/类
public static String prettyXml(String xml, String firstLine){
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Serializer serializer = new Serializer(out);
serializer.setIndent(2);
if(firstLine != null){
serializer.write(new Builder().build(firstLine + xml, ""));
} else {
serializer.write(new Builder().build(xml, ""));
}
String ret = out.toString("UTF-8");
if(firstLine != null){
return ret.substring(firstLine.length() , ret.length()).trim();
} else {
return ret;
}
} catch (Exception e) {
// ExceptionHandler.handle(e);
return xml;
}
}
示例2: outputDocument
import nu.xom.Serializer; //导入依赖的package包/类
@Override
public void outputDocument(Document pNode, OutputStream pOutputStream, boolean pPrettyPrint) {
//Use the standard XOM Serializer to serialize document nodes because we don't need any special features
try {
Serializer lSerializer = new Serializer(pOutputStream);
if(pPrettyPrint) {
lSerializer.setIndent(2);
}
lSerializer.setLineSeparator("\n");
lSerializer.write(pNode);
}
catch (IOException e) {
throw new ExInternal("Failed to serialize XML document", e);
}
}
示例3: writeDocument
import nu.xom.Serializer; //导入依赖的package包/类
public static void writeDocument(
@Nonnull Document document, @Nonnull OutputStream outputStream, @Nonnull Charset encoding)
throws IOException {
Preconditions.checkNotNull(document, "xmlDoc");
Preconditions.checkNotNull(outputStream, "outputStream");
Preconditions.checkNotNull(encoding, "encoding");
Serializer ser = new Serializer(outputStream, encoding.name());
ser.setIndent(2);
ser.setMaxLength(0);
ser.setLineSeparator("\n");
// XXX all elements inherit root elements base uri unless explicitly set (even if an
// ancestor overrides that base.) Not sure this is correct.
ser.setPreserveBaseURI(true);
ser.write(document);
ser.flush();
}
示例4: main
import nu.xom.Serializer; //导入依赖的package包/类
public static void main( String[] args )
{
TestVZomeFiles tester = new TestVZomeFiles( args[0], args[1] );
Element results = tester .collectResults();
FileOutputStream out;
try {
out = new FileOutputStream( args[2] );
Serializer serializer = new Serializer( out );
serializer .setLineSeparator( System .getProperty( "line.separator" ) );
// don't spoil the whitespace!
// serializer .setIndent( 2 );
// serializer .setMaxLength( 120 );
serializer .write( new Document( results ) );
out .close();
} catch ( IOException e ) {
e.printStackTrace();
}
System.exit( tester .exitCode );
}
示例5: saveFile
import nu.xom.Serializer; //导入依赖的package包/类
/**
* Saves the valid resource to a file.
*
* @param filename the filename
* @throws IOException
*/
private void saveFile(String filename, Resource resource) throws IOException {
FileOutputStream os = null;
try {
Document doc = new Document(resource.getXOMElementCopy());
doc.insertChild(new Comment(" Generated by Escort in DDMSence v" + PropertyReader.getProperty("version")
+ " "), 0);
File outputFile = new File(PropertyReader.getProperty("sample.data"), filename);
os = new FileOutputStream(outputFile);
Serializer serializer = new Serializer(os);
serializer.setIndent(3);
serializer.write(doc);
println("File saved at \"" + outputFile.getAbsolutePath() + "\".");
}
finally {
if (os != null)
os.close();
}
}
示例6: toZipData
import nu.xom.Serializer; //导入依赖的package包/类
/**
* @return this container as compressed data
* @throws IOException in case of any failure
*/
public byte[] toZipData() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (ZipOutputStream zipOutputStream = new ZipOutputStream(bos)) {
ZipEntry docEntry = new ZipEntry(documentName);
zipOutputStream.putNextEntry(docEntry);
Serializer serializer = new Serializer(zipOutputStream);
serializer.setIndent(4);
serializer.write(document);
zipOutputStream.closeEntry();
for (Map.Entry<String, byte[]> entry : externalResources.entrySet()) {
ZipEntry extResourceEntry = new ZipEntry(entry.getKey());
zipOutputStream.putNextEntry(extResourceEntry);
zipOutputStream.write(entry.getValue());
zipOutputStream.closeEntry();
}
}
return bos.toByteArray();
}
示例7: xmlToString
import nu.xom.Serializer; //导入依赖的package包/类
private String xmlToString(Document xml) throws IOException {
String lineSeparator = System.getProperty("line.separator");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Serializer serializer = new Serializer(outputStream, "UTF-8");
serializer.setIndent(4);
serializer.setLineSeparator(lineSeparator);
serializer.write(xml);
String xmlString = new String(outputStream.toByteArray(), "UTF-8");
return xmlString.substring(xmlString.indexOf(lineSeparator) + lineSeparator.length());
}
示例8: prettyXml
import nu.xom.Serializer; //导入依赖的package包/类
public static String prettyXml(Document doc) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Serializer serializer = new Serializer(out);
serializer.setIndent(2);
serializer.write(doc);
return out.toString("UTF-8");
}
示例9: printXML
import nu.xom.Serializer; //导入依赖的package包/类
private static void printXML(Element root) throws IOException {
Document doc = new Document(root);
Serializer serializer= new Serializer(System.out);
serializer.setIndent(4);
serializer.setMaxLength(60);
serializer.write(doc);
serializer.flush();
}
示例10: writeChanges
import nu.xom.Serializer; //导入依赖的package包/类
private void writeChanges(Document pom) {
Serializer serializer = createSerialiser();
try {
serializer.write(pom);
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
示例11: writeNamespacesUnchanged
import nu.xom.Serializer; //导入依赖的package包/类
@Test
public void writeNamespacesUnchanged()
throws ValidityException, ParsingException, IOException {
Document pom = new Builder().build(new File(new File("src/it/reflector"), "pom.xml"));
Serializer s = new StickySerializer(new FileOutputStream(new File("target/tmp.xml")), "UTF-8");
s.write(pom);
}
示例12: putDocument
import nu.xom.Serializer; //导入依赖的package包/类
/**
* @param path the path of the document within the ZIP filesystem.
* @param document the document that should be added or that should replace an older
* version with the same path
* @throws IOException in case of any failure
*/
public void putDocument(String path, Document document) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Serializer serializer = new Serializer(bos);
serializer.write(document);
putDocument(path, bos.toByteArray());
}
示例13: convertToString
import nu.xom.Serializer; //导入依赖的package包/类
/**
* @param sourceData the input document
* @param conversionPath a path to convert from input format to output format.
* @param properties the conversion properties
* @return the conversion result as a String
* @throws IOException in case of any failure
*/
public String convertToString(
byte[] sourceData,
ConversionPath conversionPath,
Properties properties) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Serializer serializer = new Serializer(buffer);
serializer.setIndent(2);
serializer.write(convertToDocument(sourceData, conversionPath, properties));
return buffer.toString("UTF-8"); //$NON-NLS-1$
}
示例14: test03
import nu.xom.Serializer; //导入依赖的package包/类
/**
* 格式化
*/
@Test
public void test03() {
BigInteger low = BigInteger.ONE;
BigInteger high = BigInteger.ONE;
Element root = new Element("Fibonacci_Numbers");
for (int i = 1; i <= 10; i++) {
Element fibonacci = new Element("fibonacci");
fibonacci.appendChild(low.toString());
root.appendChild(fibonacci);
BigInteger temp = high;
high = high.add(low);
low = temp;
}
Document doc = new Document(root);
try {
Serializer serializer = new Serializer(System.out, "ISO-8859-1");
serializer.setIndent(4);
serializer.setMaxLength(64);
serializer.write(doc);
}
catch (IOException ex) {
System.err.println(ex);
}
}
示例15: test04
import nu.xom.Serializer; //导入依赖的package包/类
/**
* 屬性
*/
@Test
public void test04() {
BigInteger low = BigInteger.ONE;
BigInteger high = BigInteger.ONE;
Element root = new Element("Fibonacci_Numbers");
for (int i = 1; i <= 10; i++) {
Element fibonacci = new Element("fibonacci");
fibonacci.appendChild(low.toString());
Attribute index = new Attribute("index", String.valueOf(i));
fibonacci.addAttribute(index);
root.appendChild(fibonacci);
BigInteger temp = high;
high = high.add(low);
low = temp;
}
Document doc = new Document(root);
try {
Serializer serializer = new Serializer(System.out, "ISO-8859-1");
serializer.setIndent(4);
serializer.setMaxLength(64);
serializer.write(doc);
} catch (IOException ex) {
System.err.println(ex);
}
}