aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/text/ForwardWriter.java
blob: 4b15d4f3699936938ca4f8b64db68f2d72895a41 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.text;

import java.io.IOException;

/**
 * Wraps another writer and converts IOException to RuntimeExceptions.
 *
 * @author baldersheim
 */
public class ForwardWriter extends GenericWriter {

    private final GenericWriter out;

    public ForwardWriter(GenericWriter writer) {
        super();
        this.out = writer;
    }

    @Override
    public void write(char[] c, int offset, int bytes) {
        try {
            out.write(c, offset, bytes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    public GenericWriter write(AbstractUtf8Array v) {
        try {
            out.write(v);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return this;
    }
    @Override
    public void write(String v) {
        try {
            out.write(v);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    public GenericWriter write(CharSequence c) {
        try {
            out.write(c);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return this;
    }


    @Override
    public GenericWriter write(double d) {
        try {
            out.write(d);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return this;
    }

    @Override
    public GenericWriter write(float f) {
        try {
            out.write(f);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return this;
    }

    @Override
    public GenericWriter write(long v) {
        try {
            out.write(v);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return this;
    }
    @Override
    public void write(int v) {
        try {
            out.write(v);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    @Override
    public GenericWriter write(short v) {
        try {
            out.write(v);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return this;
    }
    @Override
    public GenericWriter write(char c) {
        try {
            out.write(c);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return this;
    }
    @Override
    public GenericWriter write(byte b) {
        try {
            out.write(b);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return this;
    }


    @Override
    public GenericWriter write(boolean v) {
        try {
            out.write(v);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return this;
    }

    @Override
    public void flush() {
        try {
            out.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void close() {
        try {
            out.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Gives access to the wrapped writer.
     * @return wrapped writer.
     */
    public GenericWriter getWriter() { return out; }

}