Listing 1.
FileOutputStream fileOut = new FileOutputStream("super_secret.txt");
PrintStream printStream = new PrintStream(fileOut
);
printStream.println("Code: The blue pig has
no legs. Reply: Corn grows in stone");
printStream.close();
Listing 2
class BitReverserOut extends FilterOutputStream
{
byte trueByte = (byte)255;
public BitReverserOut(OutputStream out){
super(out);
}
private byte flip(byte b){
return (byte)( ((b << 4) & 0xF0)
+ ((b >> 4) & 0x0F) );
}
public void write(byte b[], int off, int len)
throws IOException {
byte temp;
for(int i = off; i < len ; i++) {
temp = flip(b[i]); //(byte)(b[i] ^ trueByte);
// cause
// System.out.print(temp);
out.write(temp);
}
}
}
Listing 3.
FileOutputStream fileOut = new FileOutputStream("super_secret.txt");
BitReverserOut bitReverser = new BitReverserOut(fileOut);
PrintStream printStream = new PrintStream(bitReverser);
printStream.println("Code: The blue pig has
no legs. Reply: Corn grows in stone");
printStream.close();
Listing 4.
import java.io.*;
public class SuperSecretApp {
public static void main(String [] args){
try{
if(args[0].equals("out"))
{
FileOutputStream fileOut = new FileOutputStream("super_secret.txt");
BitReverserOut bitReverser = new BitReverserOut(fileOut);
PrintStream printStream = new PrintStream(bitReverser);
printStream.println("Code: The blue pig has
no legs. Reply: Corn grows in stone");
printStream.close();
}else if(args[0].equals("in")){
FileInputStream fileIn = new FileInputStream("super_secret.txt");
BitReverserIn bitReverser = new BitReverserIn(fileIn);
DataInputStream dis = new DataInputStream(bitReverser);
String str = dis.readLine( );
System.out.println(str);
}else
System.out.println("wrong arguments");
}catch(IOException e){System.out.println(e);}
}
}
class BitReverserOut extends FilterOutputStream
{
byte trueByte = (byte)255;
public BitReverserOut(OutputStream out){
super(out);
}
private byte flip(byte b){
return (byte)( ((b << 4) & 0xF0)
+ ((b >> 4) & 0x0F) );
}
public void write(byte b[], int off, int len)
throws IOException {
byte temp;
for(int i = off; i < len ; i++) {
temp = flip(b[i]); //(byte)(b[i] ^ trueByte);
// cause
// System.out.print(temp);
out.write(temp);
}
}
}
class BitReverserIn extends FilterInputStream
{
byte trueByte = (byte)255;
public BitReverserIn(InputStream in){
super(in);
}
private int flip(int i){
byte b = (byte)i;
return ( ((b << 4) & 0xF0) + ((b
>> 4) & 0x0F) );
}
public int read() throws IOException {
int r;
r = in.read();
// System.out.println(r);
if(r != -1)
{
r = flip(r);//((byte)r ^ trueByte);
}
return r;
}
public int read(byte b[], int off, int len)
throws IOException {
int r;
r = in.read(b, off, len);
for (int i = off; i < len ; i++) {
System.out.println(b[i]);
b[i] = (byte)(b[i] ^ trueByte); // cause
}
return r;
}
}
Listing 5.
Driver drvr = new CompanyXPropretaryDriver(
);
Connection cnct = drvr.connect(dbName,props);
...
public foo {
Statement stmt = cnct.createStatement( );
ResultSet rslt = stmt.executeQuery(Òselect
* from employeesÓ);
ResultSetMetaData = rslt.getMetaData( );
....
}
Listing 6.
public class CompanyAConnection implements
java.sql.Connection{
...
public Statement createStatement( ){
return new CompanyAStatement( );
}
...
}