Skip to content

Instantly share code, notes, and snippets.

@btolfa
Forked from anonymous/gist:2357776
Created April 11, 2012 08:06
Show Gist options
  • Save btolfa/2357781 to your computer and use it in GitHub Desktop.
Save btolfa/2357781 to your computer and use it in GitHub Desktop.
package com.samples;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
public class Writer {
public static void main(String[] args) throws IOException {
FileReader fiR = new FileReader(
"D:/My java workspace/sampleproject/tmp/AlmPos- ID.txt");
BufferedReader buR = new BufferedReader(fiR);
buR.readLine();buR.readLine();
// Объект-сериализатор
XStream xs = new XStream(new DomDriver());
xs.autodetectAnnotations(true);
xs.aliasType("Element", Param.class);
FileOutputStream fs = new FileOutputStream(
"D:/My java workspace/sampleproject/tmp/AlmPos- ID.xml");
ArrayList <Param> listElem = new ArrayList<Param>();
listElem.add(new Param("tmp/AlmPos.xls", "0", 0, 0));
String line;
for (int j = 0; (line = buR.readLine()) != null; j++) {
listElem.add((new Param("NameObj", line, Integer.parseInt(line = buR
.readLine()), Integer.parseInt(line = buR.readLine()))));
}
ObjectPars op = new ObjectPars(listElem);
// начало куска
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
java.io.Writer writer = new OutputStreamWriter(outputStream, "UTF-8");
String xml = outputStream.toString("UTF-8");
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
xs.toXML(op, writer);
// конец
xs.toXML(op, fs); // Write to a file in the file system
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment