Difference between revisions of "READERNAME StreamReaderFormatter.java"
From RifidiWiki
(New page: This class handles how bytes should be read in from TCP Socket Most of the time, a reader will not need to implement this class and can instead use either the GenericByteStreamReader or t...) |
|||
Line 1: | Line 1: | ||
+ | [[category:developerDoc]][[category:emulatorDoc]] | ||
This class handles how bytes should be read in from TCP Socket Most of the time, a reader will not need to implement this class and can instead use either the GenericByteStreamReader or the GenericCharStreamReader. If it does need this method, this class will need to implement the AbstractStreamReader interface | This class handles how bytes should be read in from TCP Socket Most of the time, a reader will not need to implement this class and can instead use either the GenericByteStreamReader or the GenericCharStreamReader. If it does need this method, this class will need to implement the AbstractStreamReader interface | ||
Revision as of 00:34, 12 February 2008
This class handles how bytes should be read in from TCP Socket Most of the time, a reader will not need to implement this class and can instead use either the GenericByteStreamReader or the GenericCharStreamReader. If it does need this method, this class will need to implement the AbstractStreamReader interface
read
This method should read in bytes from the TCP socket
public abstract byte[] read() throws IOException;
Arguments
Return Value
bytes that were read
Reference Implementation
This is the implementation of the read method in the GenericByteStreamReader.
public byte[] read() throws IOException { ArrayList<Byte> bytes = new ArrayList<Byte>(); int b = in.read(); while (in.available() != 0) { bytes.add((byte) b); b = in.read(); } bytes.add((byte)b); /* If there is nothing on the buffer, return null */ if (bytes.isEmpty() || bytes.get(0)==-1) { logger.debug("returning bytes is null"); return null; } /* Else return the bytes */ else { byte[] retVal = new byte[bytes.size()]; logger.debug("returning bytes"); for (int i = 0; i < bytes.size(); i++) { retVal[i] = bytes.get(i); } return retVal; } }