sdsu.io
Class XorInputStream
java.lang.Object
|
+--java.io.InputStream
|
+--java.io.FilterInputStream
|
+--sdsu.io.XorInputStream
- public class XorInputStream
- extends java.io.FilterInputStream
XorInputStream is an inputstream that Xor all input bytes
with the byte mask given in the constructor. Use to decode
output of a XorOutputStream by giving it the XorInputStream
the same byte mask as XorOutputStream. XorInputStream and
XorOutputStream can be used for a very weak form of encryption.
- Version:
- 1.0 14 Feb 1998
- Author:
- Roger Whitney
(whitney@cs.sdsu.edu)
Constructor Summary |
XorInputStream(java.io.InputStream in,
byte mask)
Create an XorInputStream on the given input stream. |
Method Summary |
int |
read()
Reads the next byte of data and Xors it with the mask
given in the constructor. |
int |
read(byte[] inputBuffer,
int offset,
int length)
Reads up to length bytes of data and Xor each byte. |
Methods inherited from class java.io.FilterInputStream |
available,
close,
mark,
markSupported,
read,
reset,
skip |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
XorInputStream
public XorInputStream(java.io.InputStream in,
byte mask)
- Create an XorInputStream on the given input stream.
- Parameters:
mask
- the bit pattern with which all input bytes
will be Xored
read
public int read()
throws java.io.IOException
- Reads the next byte of data and Xors it with the mask
given in the constructor. If no byte is available
because the end of the stream has been reached, the value
-1
is returned. This method blocks until input data
is available, the end of the stream is detected, or an exception
is thrown.
- Returns:
- the next byte of data, or
-1
if the end of the
stream is reached. - Throws:
- java.io.IOException - if an I/O error occurs.
- Overrides:
- read in class java.io.FilterInputStream
read
public int read(byte[] inputBuffer,
int offset,
int length)
throws java.io.IOException
- Reads up to
length
bytes of data and Xor each byte.
This method blocks until some input is
available.
- Parameters:
inputBuffer
- the buffer into which the data is read.offset
- the start offset of the data.length
- the maximum number of bytes read.- Returns:
- the total number of bytes read into the buffer, or
-1
if there is no more data because the end of
the stream has been reached. - Throws:
- java.io.IOException - if an I/O error occurs.
- Overrides:
- read in class java.io.FilterInputStream