aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/processing/rendering/TestContentChannel.java
blob: cc93f35d572c4f3abb1ff9dc859512f956c726cc (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.processing.rendering;

import com.yahoo.jdisc.handler.CompletionHandler;
import com.yahoo.jdisc.handler.ContentChannel;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

/**
* @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
* @since 5.1.9
*/
class TestContentChannel implements ContentChannel {
    private final List<ByteBuffer> buffers = new ArrayList<>();
    private boolean closed = false;

    @Override
    public void write(ByteBuffer buf, CompletionHandler handler) {
        buffers.add(buf);
        if (handler != null) {
            handler.completed();
        }
    }

    @Override
    public void close(CompletionHandler handler) {
        closed = true;
        if (handler != null) {
            handler.completed();
        }
    }

    public List<ByteBuffer> getBuffers() {
        return buffers;
    }

    public boolean isClosed() {
        return closed;
    }
}