FileDocCategorySizeDatePackage
XorInputStream.javaAPI DocExample2685Wed Apr 19 11:20:16 BST 2000examples.rmisocfac

XorInputStream

public class XorInputStream extends FilterInputStream

Fields Summary
private byte
pattern
Constructors Summary
public XorInputStream(InputStream in, byte pattern)

  
    /*
     * Constructor for class XorInputStream
     */
         
        super(in);
	if (pattern != 0)
            this.pattern = pattern;
    
Methods Summary
public intread()

        int b = in.read();
        //If not end of file or an error, truncate b to one byte
	if (b != -1)
	  b = (b ^ pattern) & 0xFF;
                     
	return b;
    
public intread(byte[] b, int off, int len)

        int numBytes = in.read(b, off, len);

	if (numBytes <= 0)
	    return numBytes;

        int i = 0;
        for(; i < numBytes; i++) {
	    b[off + i] = (byte)((b[off + i] ^ pattern) & 0xFF);
        }
	return i;