activemq-cpp-3.6.0
decaf::io::DataInputStream Class Reference

A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way. More...

#include <src/main/decaf/io/DataInputStream.h>

Inheritance diagram for decaf::io::DataInputStream:

Public Member Functions

 DataInputStream (InputStream *inputStream, bool own=false)
 Creates a DataInputStream that uses the specified underlying InputStream.
virtual ~DataInputStream ()
virtual bool readBoolean ()
 Reads in one byte and returns true if that byte is nonzero, false if that byte is zero.
virtual char readByte ()
 Reads and returns one input byte.
virtual unsigned char readUnsignedByte ()
 Reads one input byte, zero-extends it to type int, and returns the result, which is therefore in the range 0 through 255.
virtual char readChar ()
 Reads an input char and returns the char value.
virtual double readDouble ()
 Reads eight input bytes and returns a double value.
virtual float readFloat ()
 Reads four input bytes and returns a float value.
virtual int readInt ()
 Reads four input bytes and returns an int value.
virtual long long readLong ()
 Reads eight input bytes and returns a long value.
virtual short readShort ()
 Reads two input bytes and returns a short value.
virtual unsigned short readUnsignedShort ()
 Reads two input bytes and returns an int value in the range 0 through 65535.
virtual std::string readString ()
 Reads an NULL terminated ASCII string to the stream and returns the string to the caller.
virtual std::string readLine ()
 Reads the next line of text from the input stream.
virtual std::string readUTF ()
 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.
virtual void readFully (unsigned char *buffer, int size)
 Reads some bytes from an input stream and stores them into the buffer array buffer.
virtual void readFully (unsigned char *buffer, int size, int offset, int length)
 Reads length bytes from an input stream.
virtual long long skipBytes (long long num)
 Makes an attempt to skip over n bytes of data from the input stream, discarding the skipped bytes.
- Public Member Functions inherited from decaf::io::FilterInputStream
 FilterInputStream (InputStream *inputStream, bool own=false)
 Constructor to create a wrapped InputStream.
virtual ~FilterInputStream ()
virtual int available () const
 Indicates the number of bytes available.The default implementation of this methods returns 0. Classes that override this method may return the total number of bytes that are currently available for reading and others may simply return a value of one indicating that there is some data avaiable. The caller should view the result of this method as an absolute.The default implementation of this method returns zero.
Returns
the number of bytes available on this input stream.
Exceptions
IOExceptionif an I/O error occurs.

virtual void close ()
 Closes the InputStream freeing any resources that might have been acquired during the lifetime of this stream.The default implementation of this method does nothing.
Exceptions
IOExceptionif an I/O error occurs while closing the InputStream.

virtual long long skip (long long num)
 Skips over and discards n bytes of data from this input stream.The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned.The skip method of InputStream creates a byte array and then repeatedly reads into it until num bytes have been read or the end of the stream has been reached. Subclasses are encouraged to provide a more efficient implementation of this method.
Parameters
numThe number of bytes to skip.
Returns
total bytes skipped
Exceptions
IOExceptionif an I/O error occurs.
UnsupportedOperationExceptionif the concrete stream class does not support skipping bytes.

virtual void mark (int readLimit)
 Marks the current position in the stream A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.If a stream instance reports that marks are supported then the stream will ensure that the same bytes can be read again after the reset method is called so long the readLimit is not reached.Calling mark on a closed stream instance should have no effect.The default implementation of this method does nothing.
Parameters
readLimitThe max bytes read before marked position is invalid.

virtual void reset ()
 Repositions this stream to the position at the time the mark method was last called on this input stream.If the method markSupported returns true, then:

  • If the method mark has not been called since the stream was created, or the number of bytes read from the stream since mark was last called is larger than the argument to mark at that last call, then an IOException might be thrown.
  • If such an IOException is not thrown, then the stream is reset to a state such that all the bytes read since the most recent call to mark (or since the start of the file, if mark has not been called) will be resupplied to subsequent callers of the read method, followed by any bytes that otherwise would have been the next input data as of the time of the call to reset.
If the method markSupported returns false, then:

  • The call to reset may throw an IOException.
  • If an IOException is not thrown, then the stream is reset to a fixed state that depends on the particular type of the input stream and how it was created. The bytes that will be supplied to subsequent callers of the read method depend on the particular type of the input stream.
The default implementation of this method throws an IOException.
Exceptions
IOExceptionif an I/O error occurs.

virtual bool markSupported () const
 Determines if this input stream supports the mark and reset methods.Whether or not mark and reset are supported is an invariant property of a particular input stream instance.The default implementation of this method returns false.
Returns
true if this stream instance supports marks

- Public Member Functions inherited from decaf::io::InputStream
 InputStream ()
virtual ~InputStream ()
virtual int read ()
 Reads a single byte from the buffer.
virtual int read (unsigned char *buffer, int size)
 Reads up to size bytes of data from the input stream into an array of bytes.
virtual int read (unsigned char *buffer, int size, int offset, int length)
 Reads up to length bytes of data from the input stream into an array of bytes.
virtual std::string toString () const
 Output a String representation of this object.
virtual void lock ()
 Locks the object.
virtual bool tryLock ()
 Attempts to Lock the object, if the lock is already held by another thread than this method returns false.
virtual void unlock ()
 Unlocks the object.
virtual void wait ()
 Waits on a signal from this object, which is generated by a call to Notify.
virtual void wait (long long millisecs)
 Waits on a signal from this object, which is generated by a call to Notify.
virtual void wait (long long millisecs, int nanos)
 Waits on a signal from this object, which is generated by a call to Notify.
virtual void notify ()
 Signals a waiter on this object that it can now wake up and continue.
virtual void notifyAll ()
 Signals the waiters on this object that it can now wake up and continue.
- Public Member Functions inherited from decaf::io::Closeable
virtual ~Closeable ()
- Public Member Functions inherited from decaf::util::concurrent::Synchronizable
virtual ~Synchronizable ()

Additional Inherited Members

- Protected Member Functions inherited from decaf::io::FilterInputStream
virtual int doReadByte ()
virtual int doReadArray (unsigned char *buffer, int size)
virtual int doReadArrayBounded (unsigned char *buffer, int size, int offset, int length)
virtual bool isClosed () const
- Protected Attributes inherited from decaf::io::FilterInputStream
InputStreaminputStream
bool own
volatile bool closed

Detailed Description

A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way.

An application uses a data output stream to write data that can later be read by a data input stream.

Due to the lack of garbage collection in C++ a design decision was made to add a boolean parameter to the constructor indicating if the wrapped InputStream is owned by this object. That way creation of the underlying stream can occur in a Java like way. Ex:

DataInputStream os = new DataInputStream( new InputStream(), true )

Since
1.0

Constructor & Destructor Documentation

decaf::io::DataInputStream::DataInputStream ( InputStream inputStream,
bool  own = false 
)

Creates a DataInputStream that uses the specified underlying InputStream.

Parameters
inputStreamthe InputStream instance to wrap.
ownindicates if this class owns the wrapped string defaults to false.
virtual decaf::io::DataInputStream::~DataInputStream ( )
virtual

Member Function Documentation

virtual bool decaf::io::DataInputStream::readBoolean ( )
virtual

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).
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual char decaf::io::DataInputStream::readByte ( )
virtual

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.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual char decaf::io::DataInputStream::readChar ( )
virtual

Reads an input char and returns the char value.

A ascii char is made up of one bytes. This returns the same result as readByte

Returns
the 8 bit char read.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual double decaf::io::DataInputStream::readDouble ( )
virtual

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.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual float decaf::io::DataInputStream::readFloat ( )
virtual

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.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual void decaf::io::DataInputStream::readFully ( unsigned char *  buffer,
int  size 
)
virtual

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.

This method blocks until one of the following conditions occurs:

  • buffer's 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.

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.

Parameters
bufferThe byte array to insert read data into.
sizeThe size in bytes of the given byte buffer.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
IndexOutOfBoundsExceptionif the size value is negative.
virtual void decaf::io::DataInputStream::readFully ( unsigned char *  buffer,
int  size,
int  offset,
int  length 
)
virtual

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.

Parameters
bufferThe byte array to insert read data into.
sizeThe size in bytes of the given byte buffer.
offsetThe location in buffer to start writing.
lengthThe number of bytes to read from the buffer.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
NullPointerExceptionif the buffer is NULL.
IndexOutOfBoundsExceptionif the offset + length > size.
virtual int decaf::io::DataInputStream::readInt ( )
virtual

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.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual std::string decaf::io::DataInputStream::readLine ( )
virtual

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 '
' is encountered, it is discarded and reading ceases. If the character '' is encountered, it is discarded and, if the following byte converts to the character '
', then that is discarded also; reading then ceases. If end of file is encountered before either of the characters '
' and '' is encountered, reading ceases. Once reading has ceased, a String is returned that contains all the characters read and not discarded, taken in order.

Returns
the next line of text read from the input stream or empty string if at EOF.
Exceptions
IOExceptionif an I/O Error occurs.
virtual long long decaf::io::DataInputStream::readLong ( )
virtual

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.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual short decaf::io::DataInputStream::readShort ( )
virtual

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.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual std::string decaf::io::DataInputStream::readString ( )
virtual

Reads an NULL terminated ASCII string to the stream and returns the string to the caller.

Returns
string object containing the string read.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual unsigned char decaf::io::DataInputStream::readUnsignedByte ( )
virtual

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.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual unsigned short decaf::io::DataInputStream::readUnsignedShort ( )
virtual

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.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
virtual std::string decaf::io::DataInputStream::readUTF ( )
virtual

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.
Exceptions
IOExceptionif an I/O Error occurs.
EOFExceptionif the end of input is reached.
UTFDataFormatExceptionif the bytes are not valid modified UTF-8 values.
virtual long long decaf::io::DataInputStream::skipBytes ( long long  num)
virtual

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.

Parameters
numThe number of bytes to skip over.
Returns
the total number of bytes skipped.
Exceptions
IOExceptionif an I/O Error occurs.

The documentation for this class was generated from the following file: