@@ -161,8 +161,6 @@ public void log(Logger log, String message) {
161
161
162
162
private static class LoggingOutputStream extends java .io .OutputStream {
163
163
164
- protected static final String LINE_SEPERATOR = System .getProperty ("line.separator" );
165
-
166
164
protected Logger log ;
167
165
protected LoggingLevelEnum loggingLevel ;
168
166
@@ -174,25 +172,7 @@ private static class LoggingOutputStream extends java.io.OutputStream {
174
172
/**
175
173
* The internal buffer where data is stored.
176
174
*/
177
- protected byte [] buffer ;
178
-
179
- /**
180
- * The number of valid bytes in the buffer. This value is always in the
181
- * range <tt>0</tt> through <tt>buf.length</tt>; elements
182
- * <tt>buf[0]</tt> through <tt>buf[count-1]</tt> contain valid byte
183
- * data.
184
- */
185
- protected int count ;
186
-
187
- /**
188
- * Remembers the size of the buffer for speed.
189
- */
190
- private int bufferLength ;
191
-
192
- /**
193
- * The default number of bytes in the buffer. =2048
194
- */
195
- public static final int DEFAULT_BUFFER_LENGTH = 2048 ;
175
+ protected StringBuffer buffer = new StringBuffer ();
196
176
197
177
/**
198
178
* Creates the LoggingOutputStream to flush to the given Category.
@@ -213,9 +193,6 @@ public LoggingOutputStream(Logger log, LoggingLevelEnum loggingLevel) throws Ill
213
193
214
194
this .loggingLevel = loggingLevel ;
215
195
this .log = log ;
216
- bufferLength = DEFAULT_BUFFER_LENGTH ;
217
- buffer = new byte [DEFAULT_BUFFER_LENGTH ];
218
- count = 0 ;
219
196
}
220
197
221
198
/**
@@ -246,25 +223,14 @@ public void write(final int b) throws IOException {
246
223
throw new IOException ("The stream has been closed." );
247
224
}
248
225
249
- // don't log nulls
250
- if (b == 0 ) {
251
- return ;
252
- }
253
-
254
- // would this be writing past the buffer?
255
- if (count == bufferLength ) {
256
- // grow the buffer
257
- final int newBufLength = bufferLength + DEFAULT_BUFFER_LENGTH ;
258
- final byte [] newBuf = new byte [newBufLength ];
259
-
260
- System .arraycopy (buffer , 0 , newBuf , 0 , bufferLength );
261
-
262
- buffer = newBuf ;
263
- bufferLength = newBufLength ;
226
+ byte [] bytes = new byte [1 ];
227
+ bytes [0 ] = (byte ) (b & 0xff );
228
+ String s = new String (bytes );
229
+ if (s .equals ("\n " )) {
230
+ flush ();
231
+ } else {
232
+ buffer .append (s );
264
233
}
265
-
266
- buffer [count ] = (byte ) b ;
267
- count ++;
268
234
}
269
235
270
236
/**
@@ -276,39 +242,15 @@ public void write(final int b) throws IOException {
276
242
*/
277
243
@ Override
278
244
public void flush () {
279
-
280
- if (count == 0 ) {
281
- return ;
245
+ String message = buffer . toString (). trim ();
246
+ if (message . length () > 0 ) {
247
+ loggingLevel . log ( log , message ) ;
282
248
}
283
-
284
- // don't print out blank lines; flushing from PrintStream puts out
285
- // these
286
- if (count == LINE_SEPERATOR .length ()) {
287
- if (((char ) buffer [0 ]) == LINE_SEPERATOR .charAt (0 ) && ((count == 1 ) || // <-
288
- // Unix
289
- // &
290
- // Mac,
291
- // ->
292
- // Windows
293
- ((count == 2 ) && ((char ) buffer [1 ]) == LINE_SEPERATOR .charAt (1 )))) {
294
- reset ();
295
- return ;
296
- }
297
- }
298
-
299
- final byte [] theBytes = new byte [count ];
300
-
301
- System .arraycopy (buffer , 0 , theBytes , 0 , count );
302
-
303
- loggingLevel .log (log , new String (theBytes ));
304
-
305
249
reset ();
306
250
}
307
251
308
252
private void reset () {
309
- // not resetting the buffer -- assuming that if it grew that it
310
- // will likely grow similarly again
311
- count = 0 ;
253
+ buffer = new StringBuffer ();
312
254
}
313
255
}
314
256
}
0 commit comments