Skip to content

Commit 562e50f

Browse files
committed
Update CSVEncoder.
1 parent 8ce0518 commit 562e50f

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

kilo-client/src/main/java/org/httprpc/kilo/io/CSVEncoder.java

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,54 @@ public void write(Iterable<?> row, Writer writer) throws IOException {
6464
encode(row, writer);
6565
}
6666

67+
/**
68+
* Encodes multiple rows.
69+
*
70+
* @param rows
71+
* The rows to encode.
72+
*
73+
* @param outputStream
74+
* The output stream to write to.
75+
*
76+
* @throws IOException
77+
* If an exception occurs.
78+
*/
79+
public void writeAll(Iterable<? extends Iterable<?>> rows, OutputStream outputStream) throws IOException {
80+
if (rows == null || outputStream == null) {
81+
throw new IllegalArgumentException();
82+
}
83+
84+
writeAll(rows, new OutputStreamWriter(outputStream, getCharset()));
85+
}
86+
87+
/**
88+
* Encodes multiple rows.
89+
*
90+
* @param rows
91+
* The rows to encode.
92+
*
93+
* @param writer
94+
* The character stream to write to.
95+
*
96+
* @throws IOException
97+
* If an exception occurs.
98+
*/
99+
public void writeAll(Iterable<? extends Iterable<?>> rows, Writer writer) throws IOException {
100+
if (rows == null || writer == null) {
101+
throw new IllegalArgumentException();
102+
}
103+
104+
writer = new BufferedWriter(writer);
105+
106+
try {
107+
for (var row : rows) {
108+
encode(row, writer);
109+
}
110+
} finally {
111+
writer.flush();
112+
}
113+
}
114+
67115
private void encode(Iterable<?> row, Writer writer) throws IOException {
68116
var i = 0;
69117

@@ -126,52 +174,4 @@ private void encode(Number number, Writer writer) throws IOException {
126174
private void encode(Boolean flag, Writer writer) throws IOException {
127175
writer.write(flag.toString());
128176
}
129-
130-
/**
131-
* Encodes multiple rows.
132-
*
133-
* @param rows
134-
* The rows to encode.
135-
*
136-
* @param outputStream
137-
* The output stream to write to.
138-
*
139-
* @throws IOException
140-
* If an exception occurs.
141-
*/
142-
public void writeAll(Iterable<? extends Iterable<?>> rows, OutputStream outputStream) throws IOException {
143-
if (rows == null || outputStream == null) {
144-
throw new IllegalArgumentException();
145-
}
146-
147-
writeAll(rows, new OutputStreamWriter(outputStream, getCharset()));
148-
}
149-
150-
/**
151-
* Encodes multiple rows.
152-
*
153-
* @param rows
154-
* The rows to encode.
155-
*
156-
* @param writer
157-
* The character stream to write to.
158-
*
159-
* @throws IOException
160-
* If an exception occurs.
161-
*/
162-
public void writeAll(Iterable<? extends Iterable<?>> rows, Writer writer) throws IOException {
163-
if (rows == null || writer == null) {
164-
throw new IllegalArgumentException();
165-
}
166-
167-
writer = new BufferedWriter(writer);
168-
169-
try {
170-
for (var row : rows) {
171-
encode(row, writer);
172-
}
173-
} finally {
174-
writer.flush();
175-
}
176-
}
177177
}

0 commit comments

Comments
 (0)