13
13
14
14
import org .apache .commons .lang3 .StringUtils ;
15
15
import java .io .File ;
16
- import java .io .FileWriter ;
16
+ import java .io .FileOutputStream ;
17
17
import java .io .IOException ;
18
+ import java .io .OutputStreamWriter ;
18
19
import java .text .SimpleDateFormat ;
19
20
import java .util .Calendar ;
20
21
import java .util .List ;
@@ -52,7 +53,8 @@ public class CSVWriter {
52
53
*/
53
54
public static File writeFile (final AbstractDataProvider provider , final String fileName ) throws IOException {
54
55
File file = new File (fileName );
55
- FileWriter writer = new FileWriter (file );
56
+ FileOutputStream fos = new FileOutputStream (file );
57
+ OutputStreamWriter writer = new OutputStreamWriter (fos , "ISO-8859-1" );
56
58
57
59
// retrieve DataSet
58
60
DataSet data = provider .getDataSet ();
@@ -79,7 +81,7 @@ public static File writeFile(final AbstractDataProvider provider, final String f
79
81
* @param headings List of column headings to write.
80
82
* @throws IOException
81
83
*/
82
- private static void writeColumnHeadings (FileWriter writer , List <String > headings ) throws IOException {
84
+ private static void writeColumnHeadings (OutputStreamWriter writer , List <String > headings ) throws IOException {
83
85
// write column headings
84
86
Object [] objects = headings .toArray ();
85
87
CSVWriter .writeRow (writer , objects );
@@ -94,25 +96,20 @@ private static void writeColumnHeadings(FileWriter writer, List<String> headings
94
96
* @param provider A data provider.
95
97
* @throws IOException
96
98
*/
97
- private static void writeProviderInformation (FileWriter writer , final AbstractDataProvider provider )
99
+ private static void writeProviderInformation (OutputStreamWriter writer , final AbstractDataProvider provider )
98
100
throws IOException {
99
101
SimpleDateFormat dateFormat = new SimpleDateFormat (DateWidget .VALID_DATE_FORMAT );
100
102
101
103
// provider title
102
- writer .write (provider .getName ());
103
- writer .write (StringUtils .LF );
104
- writer .write (dateFormat .format (Calendar .getInstance ().getTime ()));
105
- writer .write (StringUtils .LF );
106
- writer .write (StringUtils .LF );
104
+ writer .write (provider .getName () + StringUtils .LF );
105
+ writer .write (dateFormat .format (Calendar .getInstance ().getTime ()) + StringUtils .LF + StringUtils .LF );
107
106
108
107
// write parameters
109
108
Map <String , Object > getters = ProviderHelper .getGetterMap (provider , true );
110
109
for (Object name : getters .keySet ().toArray ()) {
111
- writer .write (name + " = " + getters .get (name )); //$NON-NLS-1$
112
- writer .write (StringUtils .LF );
110
+ writer .write (name + " = " + getters .get (name ) + StringUtils .LF ); //$NON-NLS-1$
113
111
}
114
- writer .write (StringUtils .LF );
115
- writer .write (StringUtils .LF );
112
+ writer .write (StringUtils .LF + StringUtils .LF );
116
113
}
117
114
118
115
/**
@@ -122,7 +119,7 @@ private static void writeProviderInformation(FileWriter writer, final AbstractDa
122
119
* @param objects An array of objects containing the data to write.
123
120
* @throws IOException
124
121
*/
125
- private static void writeRow (FileWriter writer , Object [] objects ) throws IOException {
122
+ private static void writeRow (OutputStreamWriter writer , Object [] objects ) throws IOException {
126
123
StringBuffer buf = new StringBuffer ();
127
124
for (Object obj : objects ) {
128
125
buf .append (obj != null ? obj .toString () : StringUtils .EMPTY );
0 commit comments