com.github.rrsunhome.excelsql.viewer.AbstractStreamViewer Maven / Gradle / Ivy
package com.github.rrsunhome.excelsql.viewer;
import java.io.*;
import java.util.Collections;
import java.util.List;
/**
* @author : wangqijia
* create at: 2021/10/31 下午11:18
*/
public abstract class AbstractStreamViewer implements Viewer, Closeable {
protected Writer writer;
protected AbstractStreamViewer(OutputStream outputStream) {
this.writer = new BufferedWriter(new OutputStreamWriter(outputStream));
}
protected AbstractStreamViewer(Writer writer) {
this.writer = writer;
}
@Override
public void outPut(String content) {
batchOutPut(Collections.singletonList(content));
}
@Override
public void batchOutPut(List contentList) {
try {
for (String content : contentList) {
writer.write(content + "\n");
}
writer.flush();
} catch (IOException e) {
throw new ViewOutputException("output view exception", e);
}
}
@Override
public void close() throws IOException {
}
}