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

A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream. More...

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

Inheritance diagram for decaf::io::ByteArrayInputStream:

Public Member Functions

 ByteArrayInputStream ()
 Creates an ByteArrayInputStream with an empty input buffer, the buffer can be initialized with a call to setByteArray.
 ByteArrayInputStream (const std::vector< unsigned char > &buffer)
 Creates the input stream and calls setBuffer with the specified buffer object.
 ByteArrayInputStream (const unsigned char *buffer, int bufferSize, bool own=false)
 Create an instance of the ByteArrayInputStream with the given buffer as the source of input for all read operations.
 ByteArrayInputStream (const unsigned char *buffer, int bufferSize, int offset, int length, bool own=false)
 Create an instance of the ByteArrayInputStream with the given buffer as the source of input for all read operations.
virtual ~ByteArrayInputStream ()
virtual void setByteArray (const std::vector< unsigned char > &buffer)
 Sets the internal buffer.
virtual void setByteArray (const unsigned char *buffer, int bufferSize)
 Sets the data that this reader uses, replaces any existing data and resets to beginning of the buffer.
virtual void setByteArray (const unsigned char *buffer, int bufferSize, int offset, int length)
 Sets the data that this reader uses, replaces any existing data and resets to beginning of the buffer.
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 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 void close ()
 Closes the InputStream freeing any resources that might have been acquired during the lifetime of this stream.
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 ()

Protected Member Functions

virtual int doReadByte ()
virtual int doReadArrayBounded (unsigned char *buffer, int size, int offset, int length)
- Protected Member Functions inherited from decaf::io::InputStream
virtual int doReadArray (unsigned char *buffer, int size)

Detailed Description

A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream.

An internal counter keeps track of the next byte to be supplied by the read method. The ByteArrayInputStream never copies the supplied buffers, only points to them, therefore the caller must ensure that the supplied buffer remain in scope, or is not deleted before this ByteArrayInputStream is freed. If the own argument of one of the constructors that accepts an array pointer is set to true than the ByteArrayInputStream instance will take ownership of the supplied pointer and delete it when that instance is destroyed.

Closing a ByteArrayInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

Since
1.0

Constructor & Destructor Documentation

decaf::io::ByteArrayInputStream::ByteArrayInputStream ( )

Creates an ByteArrayInputStream with an empty input buffer, the buffer can be initialized with a call to setByteArray.

decaf::io::ByteArrayInputStream::ByteArrayInputStream ( const std::vector< unsigned char > &  buffer)

Creates the input stream and calls setBuffer with the specified buffer object.

Parameters
bufferThe buffer to be used.
decaf::io::ByteArrayInputStream::ByteArrayInputStream ( const unsigned char *  buffer,
int  bufferSize,
bool  own = false 
)

Create an instance of the ByteArrayInputStream with the given buffer as the source of input for all read operations.

Parameters
bufferThe initial byte array to use to read from.
bufferSizeThe size of the buffer.
ownIndicates if this object should take ownership of the array, default is false.
Exceptions
NullPointerExceptionif the buffer is Null.
IllegalArguementExceptionif the bufferSize is negative.
decaf::io::ByteArrayInputStream::ByteArrayInputStream ( const unsigned char *  buffer,
int  bufferSize,
int  offset,
int  length,
bool  own = false 
)

Create an instance of the ByteArrayInputStream with the given buffer as the source of input for all read operations.

Parameters
bufferThe initial byte array to use to read from.
bufferSizeThe size of the buffer.
offsetThe offset into the buffer to begin reading from.
lengthThe number of bytes to read past the offset.
ownIndicates if this object should take ownership of the array, default is false.
Exceptions
NullPointerExceptionif the buffer is Null.
IllegalArguementExceptionif the bufferSize is negative.
virtual decaf::io::ByteArrayInputStream::~ByteArrayInputStream ( )
virtual

Member Function Documentation

virtual int decaf::io::ByteArrayInputStream::available ( ) const
virtual

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.

Reimplemented from decaf::io::InputStream.

virtual int decaf::io::ByteArrayInputStream::doReadArrayBounded ( unsigned char *  buffer,
int  size,
int  offset,
int  length 
)
protectedvirtual

Reimplemented from decaf::io::InputStream.

virtual int decaf::io::ByteArrayInputStream::doReadByte ( )
protectedvirtual
virtual void decaf::io::ByteArrayInputStream::mark ( int  readLimit)
virtual

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.

Reimplemented from decaf::io::InputStream.

virtual bool decaf::io::ByteArrayInputStream::markSupported ( ) const
inlinevirtual

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

Reimplemented from decaf::io::InputStream.

virtual void decaf::io::ByteArrayInputStream::reset ( )
virtual

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.

Reimplemented from decaf::io::InputStream.

virtual void decaf::io::ByteArrayInputStream::setByteArray ( const std::vector< unsigned char > &  buffer)
virtual

Sets the internal buffer.

The input stream will wrap around this buffer and will perform all read operations on it. The position will be reinitialized to the beginning of the specified buffer. This class will not own the given buffer - it is the caller's responsibility to free the memory of the given buffer as appropriate.

Parameters
bufferThe buffer to be used.
virtual void decaf::io::ByteArrayInputStream::setByteArray ( const unsigned char *  buffer,
int  bufferSize 
)
virtual

Sets the data that this reader uses, replaces any existing data and resets to beginning of the buffer.

Parameters
bufferThe initial byte array to use to read from.
bufferSizeThe size of the buffer.
Exceptions
NullPointerExceptionif the buffer is Null.
IllegalArguementExceptionif the bufferSize is negative.
virtual void decaf::io::ByteArrayInputStream::setByteArray ( const unsigned char *  buffer,
int  bufferSize,
int  offset,
int  length 
)
virtual

Sets the data that this reader uses, replaces any existing data and resets to beginning of the buffer.

Parameters
bufferThe initial byte array to use to read from.
bufferSizeThe size of the buffer.
offsetThe offset into the buffer to begin reading from.
lengthThe number of bytes to read past the offset.
Exceptions
NullPointerExceptionif the buffer is Null.
IllegalArguementExceptionif the bufferSize is negative.
virtual long long decaf::io::ByteArrayInputStream::skip ( long long  num)
virtual

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.

Reimplemented from decaf::io::InputStream.


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