111
rk
2025-09-28 42c0d9901e9adbfbeea4a5abb1d901196ea0ffcb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.doumee.core.servlet;
 
import lombok.Data;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.WriteListener;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
 
/**
 * 包含副本的输出流
 * @author  dm
 * @since 2025/03/31 16:44
 */
 @Data
public class ServletDuplicateOutputStream extends ServletOutputStream {
 
    private ServletOutputStream stream;
 
    private ByteArrayOutputStream duplicate;
 
    public ServletDuplicateOutputStream(ServletOutputStream servletOutputStream)  {
        this.stream = servletOutputStream;
        this.duplicate = new ByteArrayOutputStream();
    }
 
    @Override
    public boolean isReady() {
        return stream.isReady();
    }
 
    @Override
    public void setWriteListener(WriteListener writeListener) {
        stream.setWriteListener(writeListener);
    }
 
    @Override
    public void write(byte[] b) throws IOException {
        stream.write(b);
        duplicate.write(b);
    }
 
    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        stream.write(b, off, len);
        duplicate.write(b, off, len);
    }
 
    @Override
    public void flush() throws IOException {
        stream.flush();
        duplicate.flush();
    }
 
    @Override
    public void close() throws IOException {
        stream.close();
        duplicate.close();
    }
 
    @Override
    public void write(int b) throws IOException {
        stream.write(b);
        duplicate.write(b);
    }
 
    public String getContent() {
        return duplicate.toString();
    }
}