1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.util.io;
11
12 import java.io.IOException;
13 import java.io.Writer;
14 import java.security.AccessController;
15 import java.security.PrivilegedAction;
16
17 import org.eclipse.jgit.util.SystemReader;
18
19
20
21
22
23
24 public class ThrowingPrintWriter extends Writer {
25
26 private final Writer out;
27
28 private final String LF;
29
30
31
32
33
34
35
36 public ThrowingPrintWriter(Writer out) {
37 this.out = out;
38 LF = AccessController
39 .doPrivileged((PrivilegedAction<String>) () -> SystemReader
40 .getInstance().getProperty("line.separator")
41 );
42 }
43
44
45 @Override
46 public void write(char[] cbuf, int off, int len) throws IOException {
47 out.write(cbuf, off, len);
48 }
49
50
51 @Override
52 public void flush() throws IOException {
53 out.flush();
54 }
55
56
57 @Override
58 public void close() throws IOException {
59 out.close();
60 }
61
62
63
64
65
66
67
68 public void println(String s) throws IOException {
69 print(s + LF);
70 }
71
72
73
74
75
76
77 public void println() throws IOException {
78 print(LF);
79 }
80
81
82
83
84
85
86
87 public void print(char value) throws IOException {
88 print(String.valueOf(value));
89 }
90
91
92
93
94
95
96
97
98 public void print(int value) throws IOException {
99 print(String.valueOf(value));
100 }
101
102
103
104
105
106
107
108 public void print(long value) throws IOException {
109 print(String.valueOf(value));
110 }
111
112
113
114
115
116
117
118 public void print(short value) throws IOException {
119 print(String.valueOf(value));
120 }
121
122
123
124
125
126
127
128
129
130
131
132 public void format(String fmt, Object... args) throws IOException {
133 print(String.format(fmt, args));
134 }
135
136
137
138
139
140
141
142
143 public void print(Object any) throws IOException {
144 out.write(String.valueOf(any));
145 }
146 }