29.07.2013 Views

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

Master of Science thesis Fighting Spam

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

else<br />

{<br />

// When JDK1.4 is more accepted, use an assertion here.<br />

throw new java.io.IOException( "Error in Base64 code reading stream." );<br />

} // end else<br />

} // end read<br />

/**<br />

* Calls {@link #read()} repeatedly until the end <strong>of</strong> stream<br />

* is reached or len bytes are read.<br />

* Returns number <strong>of</strong> bytes read into array or -1 if<br />

* end <strong>of</strong> stream is encountered.<br />

*<br />

* @param dest array to hold values<br />

* @param <strong>of</strong>f <strong>of</strong>fset for array<br />

* @param len max number <strong>of</strong> bytes to read into array<br />

* @return bytes read into array or -1 if end <strong>of</strong> stream is encountered.<br />

* @since 1.3<br />

*/<br />

public int read( byte[] dest, int <strong>of</strong>f, int len ) throws java.io.IOException<br />

{<br />

int i;<br />

int b;<br />

for( i = 0; i < len; i++ )<br />

{<br />

b = read();<br />

//if( b < 0 && i == 0 )<br />

// return -1;<br />

if( b >= 0 )<br />

dest[<strong>of</strong>f + i] = (byte)b;<br />

else if( i == 0 )<br />

return -1;<br />

else<br />

break; // Out <strong>of</strong> 'for' loop<br />

} // end for: each byte read<br />

return i;<br />

} // end read<br />

} // end inner class InputStream<br />

/* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */<br />

/**<br />

* A {@link Base64.OutputStream} will write data to another<br />

* java.io.OutputStream, given in the constructor,<br />

* and encode/decode to/from Base64 notation on the fly.<br />

*<br />

* @see Base64<br />

* @since 1.3<br />

*/<br />

public static class OutputStream extends java.io.FilterOutputStream<br />

{<br />

private boolean encode;<br />

private int position;<br />

private byte[] buffer;<br />

private int bufferLength;<br />

private int lineLength;<br />

private boolean breakLines;<br />

private byte[] b4; // Scratch used in a few places<br />

private boolean suspendEncoding;<br />

380

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!