Matthew,
The problem in in your ByteStreamSetup class. You wrap byteIn around byteOut during construction of the object. This causes byteIn to wrap the btye array held by byteOut at *construction* time -- when the array is null of course. I moved the byteIn construction (byteIn = new ByteArrayInputStream(byteOut.toByteArray());) to getInStream() and it works fine. You might consider using PipedWriter/Reader pair rather than all that byte array confusion if you really are passing strings around. Kevin ps. if you are hiring, I'm looking for work [EMAIL PROTECTED] wrote: > > Can anyone find the problem here? > > I have a writer appender that writes to a bytearrayoutputstream. > I have a bytearrayinputstream wrapped in a bufferedreader that reads the > logged message from the stream once it has been logged. > However, my stream is empty, or at least the string conversion returns > null. > > My code is : > > BufferedWriter outputStream = setup.getOutStream(); > > cat = (AuditCategory) AuditCategory.getInstance(classFQN); > > PatternLayout logLayout = new PatternLayout(); > > ConsoleAppender consoleApp = new ConsoleAppender(logLayout); > WriterAppender writerApp = new WriterAppender(logLayout, outputStream); > > consoleApp.setThreshold(AuditLogPriority.DEBUG) > writerApp.setThreshold(AuditLogPriority.AUDIT); > > cat.addAppender(consoleApp); > cat.addAppender(writerApp); > > To setup the category with the correct appenders. > > Then: > > public void audit(java.lang.Object message) { > System.out.println("message in audit method = " + message.toString()); > cat.audit(message); > sendJmsMessage(); > } > > private void sendJmsMessage() { > > ByteArrayInputStream byteIn = setup.getInStream(); > > BufferedReader myInput = new BufferedReader ( new InputStreamReader(byteIn) ); > > try {System.out.println(myInput.readLine());} // !!!!!!!!This returns null >here!!!!!!!!! > catch (Exception e){} > > String message = new String(); > > try { > // read the now characters and convert to string > message = myInput.readLine(); > } > catch (IOException e) { > System.out.println ("Exception: " + e); > } > System.out.println (":::::::::::::::message == " + message); > > JMSProducer sendJms = new JMSProducer(message); > } > > With the arrayoutputstream stuff being done in aseperate class: > > public ByteStreamSetup() { > > // initialise the output stream > byteOut = new ByteArrayOutputStream(); > // wrap the OP stream in the writer > myOutput = new BufferedWriter( new OutputStreamWriter(byteOut) ); > > // get the buffer contents and read it into our stream reader, wrapped in a > // buffered reader which converts a stream of bytes to charatcers in one. > byteIn = new ByteArrayInputStream(byteOut.toByteArray()); > > //myInput = new BufferedReader ( new InputStreamReader(byteIn) ); > } > > public BufferedWriter getOutStream() { > return myOutput; > } > > public ByteArrayInputStream getInStream() { > //return myInput; > return byteIn; > } > > Is this a WriterAppender problem??? > I can't work out where my message is getting lost?? > > Any ideas?? > > cheers > matt > > ************************************************************************** > Privileged, confidential and/or copyright information may be contained in > this e-mail. This e-mail is for the use only of the intended addressee. If > you are not the intended addressee, or the person responsible for > delivering it to the intended addressee, you may not copy, forward, > disclose or otherwise use it or any part of it in any way whatsoever. To do > so is prohibited and may be unlawful. > If you receive this e-mail by mistake please advise the sender immediately > by using the reply facility in your e-mail software. > > Bull Information Systems Limited may monitor the content of e-mails sent > and received via its network for the purposes of ensuring compliance with > its policies and procedures. > > This message is subject to and does not create or vary any contractual > relationship between Bull Information Systems Limited and you. > > Bull Information Systems Limited. Registered Office: Computer House, Great > West Road, Brentford, Middlesex TW8 9DH. Registered in England. > Registration Number: 2017873 > > Thank you. > ************************************************************************** > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>