blob: a4476affcc59a7029f372de7f9e0d5a3c3681ee0 (
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 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.handler;
import com.yahoo.jdisc.Request;
import java.nio.ByteBuffer;
/**
* <p>This class provides a convenient implementation of {@link ContentChannel} that does not support being written to.
* If {@link #write(ByteBuffer, CompletionHandler)} is called, it throws an UnsupportedOperationException. If {@link
* #close(CompletionHandler)} is called, it calls the given {@link CompletionHandler}.</p>
*
* <p>A {@link RequestHandler}s that does not expect content can simply return the {@link #INSTANCE} of this class for
* every invocation of its {@link RequestHandler#handleRequest(Request, ResponseHandler)}.</p>
*
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
*/
public final class NullContent implements ContentChannel {
public static final NullContent INSTANCE = new NullContent();
private NullContent() {
// hide
}
@Override
public void write(ByteBuffer buf, CompletionHandler handler) {
if (buf.hasRemaining()) {
throw new UnsupportedOperationException();
}
if (handler != null) {
handler.completed();
}
}
@Override
public void close(CompletionHandler handler) {
if (handler != null) {
handler.completed();
}
}
}
|