当前位置: 首页>>代码示例>>Java>>正文


Java Serializer.write方法代码示例

本文整理汇总了Java中nu.xom.Serializer.write方法的典型用法代码示例。如果您正苦于以下问题:Java Serializer.write方法的具体用法?Java Serializer.write怎么用?Java Serializer.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nu.xom.Serializer的用法示例。


在下文中一共展示了Serializer.write方法的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;
      }
   }
 
开发者ID:nextinterfaces,项目名称:http4e,代码行数:23,代码来源:JunkUtils.java

示例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);
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:18,代码来源:ActuateReadOnly.java

示例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();
}
 
开发者ID:hamishmorgan,项目名称:XomB,代码行数:20,代码来源:XomUtil.java

示例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 );
    }
 
开发者ID:vZome,项目名称:vzome-core,代码行数:21,代码来源:TestVZomeFiles.java

示例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();
	}
}
 
开发者ID:imintel,项目名称:ddmsence,代码行数:25,代码来源:Escort.java

示例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();
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:27,代码来源:ZipResult.java

示例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());
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:11,代码来源:XmlBuilderTest.java

示例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");
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:8,代码来源:XmlUtils.java

示例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();
}
 
开发者ID:spiffykahuna,项目名称:TIJ4-code_idea,代码行数:10,代码来源:Exercise32.java

示例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);
  }
}
 
开发者ID:stickycode,项目名称:bounds-maven-plugin,代码行数:10,代码来源:StickyBoundsMojo.java

示例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);
}
 
开发者ID:stickycode,项目名称:bounds-maven-plugin,代码行数:8,代码来源:StickyBoundsMojoIntegrationTest.java

示例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());
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:14,代码来源:ZipFs.java

示例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$
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:19,代码来源:OxGarageConversionClient.java

示例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); 
    }   
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:31,代码来源:XomCreateXML.java

示例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);
	}
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:31,代码来源:XomCreateXML.java


注:本文中的nu.xom.Serializer.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。