import java.io.*; public class RotNOutputStream extends OutputStream { Encrypt encrypter; // The encryption class used OutputStream out; // The stream to decrypt public RotNOutputStream(OutputStream out, int rotate ) throws IOException { this.encrypter = new Encrypt(rotate); if ( (this.out = out) == null) throw new IOException ("OutputStream is null"); } public void write(int b) throws IOException { out.write(encrypter.encrypt(b)); } public void write(byte[] b) throws IOException { for (int n = 0; n < b.length; n++) write((int) b[n]); } public void write(byte[] b, int off, int len) throws IOException { for (int n = off; n < len; n++) write((int) b[n]); } public void flush() throws IOException { out.flush(); } public void close() throws IOException { out.close(); } //////////////////////////////////////// // Test function public static void main(String args[]) { StringBuffer buf = new StringBuffer("All I need I already am!"); FileOutputStream fOut = null; RotNOutputStream rOut = null; try { fOut = new FileOutputStream("test.txt"); rOut = new RotNOutputStream(fOut, 10); for (int i = 0; i < buf.length(); i++) rOut.write((int) buf.charAt(i)); rOut.close(); } catch (IOException e) { } } }