import java.io.*; public class RotNInputStream extends InputStream { Decrypt decrypter; // The decryption class used InputStream in; // The stream to encrypt public RotNInputStream(InputStream in, int rotate ) throws IOException { this.decrypter = new Decrypt(rotate); if ( (this.in = in) == null) throw new IOException ("InputStream is null"); } public int available() throws IOException { return in.available(); } public int read() throws IOException { return decrypter.decrypt(in.read()); } public int read(byte b[], int off, int len) throws IOException { int readlength = in.read(b, off, len); if (readlength == 0 || readlength == -1 ) return readlength; for (int i = 0; i < readlength; i++) b[off + i] = (byte) decrypter.decrypt((int) b[off + i]); return readlength; } public int read(byte b[]) throws IOException { return read(b, 0, b.length); } public void close() throws IOException { in.close(); } public void mark(int readlimit) { in.mark(readlimit); } public void reset() throws IOException { in.reset(); } public boolean markSupported() { return in.markSupported(); } //////////////////////////////////////// // Test function public static void main(String args[]) { FileInputStream fIn = null; RotNInputStream rIn = null; try { fIn = new FileInputStream("test.txt"); rIn = new RotNInputStream(fIn, 10); while ( rIn.available() > 0 ) System.out.print("" + (char) rIn.read()); System.out.println(""); rIn.close(); } catch (IOException e) { } } }