Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25276
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx09.iad.POSTED!not-for-mail |
|---|---|
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 |
| MIME-Version | 1.0 |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Reading from stdout |
| References | <l0sruc$clf$1@dont-email.me> |
| In-Reply-To | <l0sruc$clf$1@dont-email.me> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Lines | 30 |
| Message-ID | <DfnYt.29309$cs5.9201@fx09.iad> (permalink) |
| X-Complaints-To | abuse@newsrazor.net |
| NNTP-Posting-Date | Thu, 12 Sep 2013 17:56:51 UTC |
| Date | Thu, 12 Sep 2013 10:56:49 -0700 |
| X-Received-Bytes | 1765 |
| Xref | csiph.com comp.lang.java.programmer:25276 |
Show key headers only | View raw
On 9/12/13 9:59 AM, White Spirit wrote: > I'm writing a unit test for a logger class that writes to stdout. The > logger class uses an OutputStreamWriter to wrap FileDescriptor.out: > > mOut = new OutputStreamWriter(new > FileOutputStream(FileDescriptor.out), "UTF-8"); > > My unit test instantiates the logger class as a local object. When I > try to read from FileDescriptor.out in my unit test class, however, > nothing is received: > > BufferedReader reader = new BufferedReader( new InputStreamReader( new > FileInputStream( FileDescriptor.out ) ) ); > // do some logging > // ... > String n = reader.readLine(); > > Is there any way of reading what the logger is outputting? If you allow the Logger to accept an OutputStream, then you can pass in a new ByteArrayOutputStream(). final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Logger logger = new Logger(baos); doSomeLogging(logger); String result = baos.toString(); // uses default encoding. assertEqual(expectedResult, result);
Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread
Re: Reading from stdout Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-09-12 10:56 -0700
csiph-web