aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/federation/http/TimedHttpEntity.java
blob: 03ffe2b8a9c7072bd2a0b8298c8dfc3010f10cad (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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.federation.http;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.http.Header;
import org.apache.http.HttpEntity;

/**
 * Wrapper for adding timeout to an HttpEntity instance.
 *
 * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a>
 * @deprecated
 */
// TODO: Remove on Vespa 7
@Deprecated // OK
public class TimedHttpEntity implements HttpEntity {
    /**
     * The wrapped entity. Never null.
     */
    private final HttpEntity entity;
    private final long startTime;
    private final long timeout;

    public TimedHttpEntity(HttpEntity entity, long startTime, long timeout) {
        if (entity == null) {
            throw new IllegalArgumentException("TimedHttpEntity cannot be instantiated with null HttpEntity.");
        }
        this.entity = entity;
        this.startTime = startTime;
        this.timeout = timeout;
    }


    @Override
    public InputStream getContent() throws IOException, IllegalStateException {
        InputStream content = entity.getContent();
        if (content == null) {
            return null;
        } else {
            return new TimedStream(content, startTime, timeout);
        }
    }


    // START OF PURE FORWARDING METHODS
    @Override
    public void consumeContent() throws IOException {
        entity.consumeContent();
    }


    @Override
    public Header getContentEncoding() {
        return entity.getContentEncoding();
    }

    @Override
    public long getContentLength() {
        return entity.getContentLength();
    }

    @Override
    public Header getContentType() {
        return entity.getContentType();
    }

    @Override
    public boolean isChunked() {
        return entity.isChunked();
    }

    @Override
    public boolean isRepeatable() {
        return entity.isRepeatable();
    }

    @Override
    public boolean isStreaming() {
        return entity.isStreaming();
    }

    @Override
    public void writeTo(OutputStream outstream) throws IOException {
        entity.writeTo(outstream);
    }
    // END OF PURE FORWARDING METHODS

}