org.axonframework.common.io
Class BinaryEntryInputStream

java.lang.Object
  extended by org.axonframework.common.io.BinaryEntryInputStream

public class BinaryEntryInputStream
extends Object

Wrapper around an input stream that can be used to read simple values, written using the BinaryEntryOutputStream. This input stream reads whitespace-separated entries from an input stream. That means that the entries (except for binary entries) may not contain whitespace themselves.

The BinaryEntryInputStream does not read ahead. It will read up to and inclusive the next whitespace each time is read. When byte arrays are read, it will first read an entry containing its size, and then the exact number of bytes as indicated in the size entry. Any whitespace character followed by the byte array is not read.

This class is meant for internal use, and should be used with care.

Since:
1.0
Author:
Allard Buijze

Constructor Summary
BinaryEntryInputStream(InputStream inputStream)
          Initialize a BinaryEntryInputStream reading its data from the given inputStream.
 
Method Summary
 byte[] readBytes()
          Reads the next entry as a byte array.
 long readNumber()
          Reads the next entry as a number (long).
 String readString()
          Reads the next entry as a String value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryEntryInputStream

public BinaryEntryInputStream(InputStream inputStream)
Initialize a BinaryEntryInputStream reading its data from the given inputStream.

Parameters:
inputStream - The input stream providing the data
Method Detail

readNumber

public long readNumber()
                throws IOException
Reads the next entry as a number (long).

Returns:
the numeric value of the next entry
Throws:
IOException - if an error occurs reading from the backing stream
NumberFormatException - if the entry read does not represent a Long

readString

public String readString()
                  throws IOException
Reads the next entry as a String value.

Returns:
The String value of the next entry
Throws:
IOException - if an error occurs reading from the backing stream

readBytes

public byte[] readBytes()
                 throws IOException
Reads the next entry as a byte array.

Returns:
A byte[] of size numberOfBytes containing the entry read, or null of the input stream did not contain all the bytes for this entry.
Throws:
IOException - if an error occurs reading from the backing stream


Copyright © 2010-2012. All Rights Reserved.