| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package cn.exlive.monitor.utils;
- import org.apache.commons.lang3.SystemUtils;
- import java.io.Closeable;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.nio.charset.Charset;
- import java.nio.charset.StandardCharsets;
- /**
- * 收集日志
- *
- * <pre>
- *
- * Created by zhaopx.
- * Date: 2025/6/9
- * Time: 14:06
- * Vendor: exlive.cn
- *
- * </pre>
- *
- * @author zhaopx
- */
- public class ShellLogOutputStream extends OutputStream implements Closeable {
- final StringBuffer lines = new StringBuffer();
- /**
- * 系统编码
- */
- Charset charset = SystemUtils.IS_OS_LINUX ? StandardCharsets.UTF_8 : Charset.forName("GBK");
- @Override
- public void write(int b) throws IOException {
- }
- /**
- * write one line
- * @param line one line
- * @return
- * @throws IOException
- */
- public void write(String line) throws IOException {
- lines.append(line);
- }
- @Override
- public void write(byte[] b, int off, int len) throws IOException {
- String line = new String(b, off, len, charset);
- write(line);
- }
- @Override
- public void flush() throws IOException {
- }
- @Override
- public void close() throws IOException {
- }
- @Override
- public String toString() {
- return lines.toString();
- }
- public Charset getCharset() {
- return charset;
- }
- public void setCharset(Charset charset) {
- this.charset = charset;
- }
- }
|