Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 61965 invoked from network); 7 Jul 2010 21:44:45 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 7 Jul 2010 21:44:45 -0000 Received: (qmail 63781 invoked by uid 500); 7 Jul 2010 21:44:45 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 63699 invoked by uid 500); 7 Jul 2010 21:44:44 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 63692 invoked by uid 99); 7 Jul 2010 21:44:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jul 2010 21:44:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jul 2010 21:44:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 24E3A23888D1; Wed, 7 Jul 2010 21:43:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r961512 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp Date: Wed, 07 Jul 2010 21:43:18 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100707214318.24E3A23888D1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Wed Jul 7 21:43:17 2010 New Revision: 961512 URL: http://svn.apache.org/viewvc?rev=961512&view=rev Log: Finish the readLine method since the PushbackInputStream is implemented now. Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp?rev=961512&r1=961511&r2=961512&view=diff ============================================================================== --- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp (original) +++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInputStream.cpp Wed Jul 7 21:43:17 2010 @@ -17,6 +17,8 @@ #include +#include + #ifdef HAVE_STRING_H #include #endif @@ -343,41 +345,51 @@ void DataInputStream::readFully( unsigne std::string DataInputStream::readLine() { try{ - throw IOException( __FILE__, __LINE__, "Not Yet Implemented." ); - // TODO - Once PushBackInputStream is done. -// std::string line; -// bool foundTerminator = false; -// -// while( true ) { -// -// int nextByte = inputStream->read(); -// switch( nextByte ) { -// case -1: -// if( line.length() == 0 && !foundTerminator ) { -// return ""; -// } -// return line; -// case (unsigned char)'\r': -// if( foundTerminator ) { -// ( (PushbackInputStream)in ).unread( nextByte ); -// return line.toString(); -// } -// foundTerminator = true; -// /* Have to be able to peek ahead one byte */ -// if(!(in.getClass() == PushbackInputStream.class)) { -// in = new PushbackInputStream( in ); -// } -// break; -// case (byte)'\n': -// return line.toString(); -// default: -// if( foundTerminator ) { -// ( (PushbackInputStream)in ).unread( nextByte ); -// return line.toString(); -// } -// line.append( (char)nextByte ); -// } -// } + std::string line; + bool foundTerminator = false; + + while( true ) { + + int nextByte = inputStream->read(); + + if( nextByte == -1 ) { + + if( line.length() == 0 && !foundTerminator ) { + return ""; + } + return line; + + } else if( nextByte == (unsigned char)'\r' ) { + + PushbackInputStream* pbStream = dynamic_cast( inputStream ); + + if( foundTerminator ) { + ( (PushbackInputStream*)inputStream )->unread( (unsigned char)nextByte ); + return line; + } + + foundTerminator = true; + + // Have to be able to peek ahead one byte to see if its an newline. + if( pbStream == NULL ) { + inputStream = new PushbackInputStream( inputStream, own ); + own = true; + } + + } else if( nextByte == (unsigned char)'\n' ) { + + return line; + + } else { + + if( foundTerminator ) { + ( (PushbackInputStream*)inputStream )->unread( (unsigned char)nextByte ); + return line; + } + + line += (char)nextByte; + } + } } DECAF_CATCH_RETHROW( IOException ) DECAF_CATCHALL_THROW( IOException )