You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/02/19 01:39:35 UTC
svn commit: r911658 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io: DataInput.h
DataOutput.h
Author: tabish
Date: Fri Feb 19 00:39:34 2010
New Revision: 911658
URL: http://svn.apache.org/viewvc?rev=911658&view=rev
Log:
Adding in the DataInput and DataOutput interfaces for Decaf
Added:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInput.h (with props)
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutput.h (with props)
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInput.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInput.h?rev=911658&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInput.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInput.h Fri Feb 19 00:39:34 2010
@@ -0,0 +1,341 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_IO_DATAINPUT_H_
+#define _DECAF_IO_DATAINPUT_H_
+
+#include <decaf/util/Config.h>
+
+#include <vector>
+#include <string>
+
+#include <decaf/io/IOException.h>
+#include <decaf/io/EOFException.h>
+#include <decaf/io/UTFDataFormatException.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+namespace decaf {
+namespace io {
+
+ /**
+ * The DataInput interface provides for reading bytes from a binary stream and reconstructing
+ * from them data in any of the C++ primitive types. There is also a facility for reconstructing
+ * Strings from data in the Java standard modified UTF-8 format.
+ *
+ * It is generally true of all the reading routines in this interface that if end of file is
+ * reached before the desired number of bytes has been read, an EOFException is thrown. If any
+ * byte cannot be read for any reason other than end of file, an IOException other than EOFException
+ * is thrown. for example, an IOException may be thrown if the underlying input stream has been
+ * closed.
+ *
+ * @see DataOutput
+ * @see DataInputStream
+ *
+ * @since 1.0
+ */
+ class DECAF_API DataInput {
+ public:
+
+ virtual ~DataInput() {}
+
+ /**
+ * Reads in one byte and returns true if that byte is nonzero, false if that
+ * byte is zero.
+ *
+ * @returns the boolean value of the read in byte (0=false, 1=true).
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual bool readBoolean()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads and returns one input byte. The byte is treated as a
+ * signed value in the range -128 through 127, inclusive.
+ *
+ * @returns the 8-bit value read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual char readByte()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads one input byte, zero-extends it to type int, and returns
+ * the result, which is therefore in the range 0 through 255.
+ *
+ * @returns the 8 bit unsigned value read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual unsigned char readUnsignedByte()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads an input char and returns the char value. A ascii char
+ * is made up of one bytes. This returns the same result as
+ * <code>readByte</code>
+ *
+ * @returns the 8 bit char read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual char readChar()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads eight input bytes and returns a double value. It does this
+ * by first constructing a long long value in exactly the manner of
+ * the readlong method, then converting this long value to a double
+ * in exactly the manner of the method Double::longBitsToDouble.
+ *
+ * @returns the double value read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual double readDouble()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads four input bytes and returns a float value. It does this
+ * by first constructing an int value in exactly the manner of the
+ * readInt method, then converting this int value to a float in
+ * exactly the manner of the method Float::intBitsToFloat.
+ *
+ * @returns the float value read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual float readFloat()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads four input bytes and returns an int value. Let a be the
+ * first byte read, b be the second byte, c be the third byte, and
+ * d be the fourth byte. The value returned is:
+ *
+ * (((a & 0xff) << 24) | ((b & 0xff) << 16) |
+ * ((c & 0xff) << 8) | (d & 0xff))
+ *
+ * @returns the int value read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual int readInt()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads eight input bytes and returns a long value. Let a be the
+ * first byte read, b be the second byte, c be the third byte, d
+ * be the fourth byte, e be the fifth byte, f be the sixth byte,
+ * g be the seventh byte, and h be the eighth byte. The value
+ * returned is:
+ *
+ * (((long)(a & 0xff) << 56) |
+ * ((long)(b & 0xff) << 48) |
+ * ((long)(c & 0xff) << 40) |
+ * ((long)(d & 0xff) << 32) |
+ * ((long)(e & 0xff) << 24) |
+ * ((long)(f & 0xff) << 16) |
+ * ((long)(g & 0xff) << 8) |
+ * ((long)(h & 0xff)))
+ *
+ * @returns the 64 bit long long read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual long long readLong()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads two input bytes and returns a short value. Let a be the
+ * first byte read and b be the second byte. The value returned is:
+ *
+ * (short)((a << 8) | (b & 0xff))
+ *
+ * @returns the 16 bit short value read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual short readShort()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads two input bytes and returns an int value in the range 0
+ * through 65535. Let a be the first byte read and b be the
+ * second byte. The value returned is:
+ *
+ * (((a & 0xff) << 8) | (b & 0xff))
+ *
+ * @returns the 16 bit unsigned short read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual unsigned short readUnsignedShort()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads an NULL terminated ASCII string to the stream and returns the
+ * string to the caller.
+ *
+ * @returns string object containing the string read.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual std::string readString()
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads the next line of text from the input stream. It reads successive bytes, converting
+ * each byte to an ASCII char separately, until it encounters a line terminator or end of
+ * file; the characters read are then returned as a standard String. Note that because this
+ * method processes bytes, it does not support input of the full Unicode character set.
+ *
+ * If end of file is encountered before even one byte can be read, then an empty string is
+ * returned. Otherwise, each byte that is read is converted to type char. If the character
+ * '\n' is encountered, it is discarded and reading ceases. If the character '\r' is
+ * encountered, it is discarded and, if the following byte converts to the character '\n',
+ * then that is discarded also; reading then ceases. If end of file is encountered before
+ * either of the characters '\n' and '\r' is encountered, reading ceases. Once reading has
+ * ceased, a String is returned that contains all the characters read and not discarded,
+ * taken in order.
+ *
+ * @return the next line of text read from the input stream or empty string if at EOF.
+ *
+ * @throws IOException if an I/O Error occurs.
+ */
+ virtual std::string readLine()
+ throw( decaf::io::IOException ) = 0;
+
+ /**
+ * Reads a modified UTF-8 encoded string in ASCII format and returns it,
+ * this is only useful if you know for sure that the string that is to be read
+ * was a string that contained all ASCII values (0-255), if so this method will
+ * throw a UTFFormatException. This method reads String value written from a
+ * Java DataOutputStream and assumes that the length prefix the precedes the
+ * encoded UTF-8 bytes is an unsigned short, which implies that the String will
+ * be no longer than 65535 characters.
+ *
+ * @returns The decoded string read from stream.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ * @throws UTFDataFormatException if the bytes are not valid modified UTF-8 values.
+ */
+ virtual std::string readUTF()
+ throw( decaf::io::IOException,
+ decaf::io::EOFException,
+ decaf::io::UTFDataFormatException ) = 0;
+
+ /**
+ * Reads some bytes from an input stream and stores them into the
+ * buffer array buffer. The number of bytes read is equal to the length
+ * of buffer.<p>
+ * This method blocks until one of the following conditions occurs:
+ * * buffer.size() bytes of input data are available, in which case
+ * a normal return is made.
+ * * End of file is detected, in which case an EOFException is
+ * thrown.
+ * * An I/O error occurs, in which case an IOException other than
+ * EOFException is thrown.
+ * <p>
+ * If buffer.size() is zero, then no bytes are read. Otherwise, the
+ * first byte read is stored into element b[0], the next one into
+ * buffer[1], and so on. If an exception is thrown from this method,
+ * then it may be that some but not all bytes of buffer have been
+ * updated with data from the input stream.
+ *
+ * @param buffer - vector of char that is read to its size().
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ */
+ virtual void readFully( std::vector<unsigned char>& buffer )
+ throw( decaf::io::IOException, decaf::io::EOFException ) = 0;
+
+ /**
+ * Reads length bytes from an input stream.
+ *
+ * This method blocks until one of the following conditions occurs:
+ * * length bytes of input data are available, in which case a
+ * normal return is made.
+ * * End of file is detected, in which case an EOFException is
+ * thrown.
+ * * An I/O error occurs, in which case an IOException other
+ * than EOFException is thrown.
+ *
+ * If buffer is NULL, a NullPointerException is thrown. If offset+length
+ * is greater than the length of the array buffer, then an IndexOutOfBoundsException
+ * is thrown. If length is zero, then no bytes are read. Otherwise, the first
+ * byte read is stored into element buffer[off], the next one into buffer[offset+1],
+ * and so on. The number of bytes read is, at most, equal to length.
+ *
+ * @param buffer
+ * The byte array to insert read data into.
+ * @param size
+ * The size in bytes of the given byte buffer.
+ * @param offset
+ * The location in buffer to start writing.
+ * @param length
+ * The number of bytes to read from the buffer.
+ *
+ * @throws IOException if an I/O Error occurs.
+ * @throws EOFException if the end of input is reached.
+ * @throws NullPointerException if the buffer is NULL.
+ * @throws IndexOutOfBoundsException if the offset + length > size.
+ */
+ virtual void readFully( unsigned char* buffer, std::size_t size,
+ std::size_t offset, std::size_t length )
+ throw ( decaf::io::IOException,
+ decaf::io::EOFException,
+ decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IndexOutOfBoundsException ) = 0;
+
+ /**
+ * Makes an attempt to skip over n bytes of data from the input stream,
+ * discarding the skipped bytes. However, it may skip over some smaller
+ * number of bytes, possibly zero. This may result from any of a number
+ * of conditions; reaching end of file before n bytes have been skipped
+ * is only one possibility. This method never throws an EOFException.
+ * The actual number of bytes skipped is returned.
+ *
+ * @param num
+ * The number of bytes to skip over.
+ *
+ * @return the total number of bytes skipped.
+ *
+ * @throws IOException if an I/O Error occurs.
+ */
+ virtual std::size_t skipBytes( std::size_t num ) throw( io::IOException ) = 0;
+
+ };
+
+}}
+
+#endif /* _DECAF_IO_DATAINPUT_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataInput.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutput.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutput.h?rev=911658&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutput.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutput.h Fri Feb 19 00:39:34 2010
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_IO_DATAOUTPUT_H_
+#define _DECAF_IO_DATAOUTPUT_H_
+
+#include <decaf/util/Config.h>
+
+#include <vector>
+#include <string>
+
+#include <decaf/io/IOException.h>
+#include <decaf/io/EOFException.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+
+namespace decaf {
+namespace io {
+
+ /**
+ * The DataOutput interface provides for converting data from any of the C++ primitive types
+ * to a series of bytes and writing these bytes to a binary stream. There is also a facility
+ * for converting Strings into the Java standard modified UTF-8 format and writing the
+ * resulting series of bytes.
+ *
+ * If a method in this interface encounters an error while writing it will throw an IOException.
+ *
+ * @see DataInput
+ * @see DataOutputStream
+ *
+ * @since 1.0
+ */
+ class DECAF_API DataOutput {
+ public:
+
+ virtual ~DataOutput() {}
+
+ /**
+ * Writes a boolean to the underlying output stream as a 1-byte value. The
+ * value true is written out as the value (byte)1; the value false
+ * is written out as the value (byte)0. If no exception is thrown,
+ * the counter written is incremented by 1.
+ *
+ * @param value
+ * The boolean to write as a byte (1=true, 0=false).
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeBoolean( bool value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Writes out a byte to the underlying output stream as a 1-byte
+ * value. If no exception is thrown, the counter written is
+ * incremented by 1.
+ *
+ * @param value
+ * The unsigned char value to write.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeByte( unsigned char value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Writes a short to the underlying output stream as two bytes, high
+ * byte first. If no exception is thrown, the counter written is
+ * incremented by 2.
+ *
+ * @param value
+ * The signed short value to write.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeShort( short value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Writes a unsigned short to the bytes message stream as a 2 byte value
+ *
+ * @param value
+ * The unsigned short to write to the stream.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeUnsignedShort( unsigned short value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Writes out a char to the underlying output stream as a one byte
+ * value If no exception is thrown, the counter written is
+ * incremented by 1.
+ *
+ * @param value
+ * The signed char value to write.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeChar( char value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Writes an int to the underlying output stream as four bytes, high
+ * byte first. If no exception is thrown, the counter written is
+ * incremented by 4.
+ *
+ * @param value
+ * The signed integer value to write.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeInt( int value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Writes an 64 bit long to the underlying output stream as eight
+ * bytes, high byte first. If no exception is thrown, the counter
+ * written is incremented by 8.
+ *
+ * @param value
+ * The signed 64bit long value to write.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeLong( long long value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Converts the float argument to an int using the floatToIntBits
+ * method in class Float, and then writes that int value to the
+ * underlying output stream as a 4-byte quantity, high byte first.
+ * If no exception is thrown, the counter written is incremented
+ * by 4.
+ *
+ * @param value
+ * The 32bit floating point value to write.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeFloat( float value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Converts the double argument to a long using the doubleToLongBits
+ * method in class Double, and then writes that long value to the
+ * underlying output stream as an 8-byte quantity, high byte first.
+ * If no exception is thrown, the counter written is incremented
+ * by 8.
+ *
+ * @param value
+ * The 64bit double value to write.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeDouble( double value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Writes out the string to the underlying output stream as a
+ * sequence of bytes. Each character in the string is written out,
+ * in sequence, by discarding its high eight bits. If no exception
+ * is thrown, the counter written is incremented by the length of
+ * value. The value written does not include a trailing null as that
+ * is not part of the sequence of bytes, if the null is needed, then use
+ * the writeChars method.
+ *
+ * @param value
+ * The vector of bytes to write.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeBytes( const std::string& value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Writes a string to the underlying output stream as a sequence of
+ * characters. Each character is written to the data output stream
+ * as if by the writeChar method. If no exception is thrown, the
+ * counter written is incremented by the length of value. The trailing
+ * NULL character is written by this method.
+ *
+ * @param value
+ * The string value to write as raw bytes.
+ *
+ * @throws IOException if an I/O error is encountered.
+ */
+ virtual void writeChars( const std::string& value )
+ throw ( decaf::io::IOException ) = 0;
+
+ /**
+ * Writes out the string to the underlying output stream as a modeified UTF-8
+ * encoded sequence of bytes. The first two bytes written are indicate its
+ * encoded length followed by the rest of the string's characters encoded as
+ * modified UTF-8. The length represent the encoded length of the data not the
+ * actual length of the string.
+ *
+ * @param value
+ * The string value value to write as modified UTF-8.
+ *
+ * @throws IOException if an I/O error is encountered.
+ * @throws UTFDataFormatException if the encoded size if greater than 65535
+ */
+ virtual void writeUTF( const std::string& value )
+ throw ( decaf::io::IOException,
+ decaf::io::UTFDataFormatException ) = 0;
+
+ };
+
+}}
+
+#endif /* _DECAF_IO_DATAOUTPUT_H_ */
Propchange: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/io/DataOutput.h
------------------------------------------------------------------------------
svn:eol-style = native