Difference between revisions of "READERNAME StreamReaderFormatter.java"

From RifidiWiki

Jump to: navigation, search
m (Reverted edits by Amesycyxa (Talk); changed back to last version by Kyle)
 
Line 1: Line 1:
----
 
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://unugeboq.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
 
----
 
=[http://unugeboq.co.cc CLICK HERE]=
 
----
 
</div>
 
 
[[category:developerDoc]][[category:emulatorDoc]]
 
[[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
Line 14: Line 6:
 
This method should read in bytes from the TCP socket
 
This method should read in bytes from the TCP socket
  
&lt;pre&gt;public abstract byte[] read() throws IOException;&lt;/pre&gt;
+
<pre>public abstract byte[] read() throws IOException;</pre>
  
 
==Arguments==
 
==Arguments==
Line 23: Line 15:
 
==Reference Implementation==
 
==Reference Implementation==
 
This is the implementation of the read method in the GenericByteStreamReader.
 
This is the implementation of the read method in the GenericByteStreamReader.
&lt;pre&gt;
+
<pre>
 
public byte[] read() throws IOException {
 
public byte[] read() throws IOException {
ArrayList&lt;Byte&gt; bytes = new ArrayList&lt;Byte&gt;();
+
ArrayList<Byte> bytes = new ArrayList<Byte>();
 
int b = in.read();
 
int b = in.read();
 
while (in.available() != 0) {
 
while (in.available() != 0) {
Line 34: Line 26:
 
/* If there is nothing on the buffer, return null */
 
/* If there is nothing on the buffer, return null */
 
if (bytes.isEmpty() || bytes.get(0)==-1) {
 
if (bytes.isEmpty() || bytes.get(0)==-1) {
logger.debug(&quot;returning bytes is null&quot;);
+
logger.debug("returning bytes is null");
 
return null;
 
return null;
 
}
 
}
Line 41: Line 33:
 
byte[] retVal = new byte[bytes.size()];
 
byte[] retVal = new byte[bytes.size()];
  
logger.debug(&quot;returning bytes&quot;);
+
logger.debug("returning bytes");
for (int i = 0; i &lt; bytes.size(); i++) {
+
for (int i = 0; i < bytes.size(); i++) {
 
retVal[i] = bytes.get(i);
 
retVal[i] = bytes.get(i);
 
}
 
}
Line 49: Line 41:
  
 
}
 
}
&lt;/pre&gt;
+
</pre>

Latest revision as of 19:41, 26 November 2010

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;
		}

	}
Personal tools