Commit ef32150e authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

9780596002855

0 → 120000
+1 −0
Changes for 9780596002855: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
9780596002855
 No newline at end of file

CD-ROM/README.txt

0 → 100755
+9 −0
Changes for CD-ROM/README.txt: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line

Learning Java, 2nd Edition
--------------------------

This directory contains example source code and links to software for Learning Java, 2nd Edition, O'Reilly & Associates.

The example source code and expanded book material are copyright Pat Niemeyer or Jonathan Knudsen, 2002.  You may freely use and modify the examples for use in your own code. 

+43 −0
Changes for CD-ROM/examples/appa/CryptURLConnection.java: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
//file: CryptURLConnection.java
class CryptURLConnection extends URLConnection {
    static int defaultPort = 80;
    CryptInputStream cis;

    public String getContentType(  ) {
        return guessContentTypeFromName( url.getFile(  ) );
    }

    CryptURLConnection ( URL url, String crypType )
      throws IOException {
        super( url );
        try {
            String classname = "learningjava.protocolhandlers.crypt."
                + crypType + "CryptInputStream";
            cis = (CryptInputStream)
                   Class.forName(classname).newInstance(  );
        } catch ( Exception e ) {
            throw new IOException("Crypt Class Not Found: "+e);
        }
    }

    public void connect(  ) throws IOException {
        int port = ( url.getPort(  ) == -1 ) ?
                     defaultPort : url.getPort(  );
        Socket s = new Socket( url.getHost(  ), port );

        // Send the filename in plaintext
        OutputStream server = s.getOutputStream(  );
        new PrintWriter( new OutputStreamWriter( server, "8859_1" ),
                         true).println( "GET " + url.getFile(  ) );

        // Initialize the CryptInputStream
        cis.set( s.getInputStream(  ), server );
        connected = true;
    }

    public InputStream getInputStream(  ) throws IOException {
        if (!connected)
            connect(  );
        return ( cis );
    }
}
+22 −0
Changes for CD-ROM/examples/appa/Handler.java: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line
//file: Handler.java
package learningjava.protocolhandlers.crypt;
import java.io.*;
import java.net.*;

public class Handler extends URLStreamHandler {

    protected void parseURL(URL url, String spec,
                            int start, int end) {
        int slash = spec.indexOf('/');
        String crypType = spec.substring(start, slash-1);
        super.parseURL(url, spec, slash, end);
        setURL( url, "crypt:"+crypType, url.getHost(  ),
            url.getPort(), url.getFile(), url.getRef(  ) );
    }

    protected URLConnection openConnection(URL url)
      throws IOException {
        String crypType = url.getProtocol(  ).substring(6);
        return new CryptURLConnection( url, crypType );
    }
}
+19 −0
Changes for CD-ROM/examples/appa/rot13CryptInputStream.java: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
//file: rot13CryptInputStream.java
package learningjava.protocolhandlers.crypt;
import java.io.*;

abstract class CryptInputStream extends InputStream {
    InputStream in;
    OutputStream out;
    abstract public void set( InputStream in, OutputStream out );
} // end of class CryptInputStream

class rot13CryptInputStream extends CryptInputStream {

    public void set( InputStream in, OutputStream out ) {
        this.in = new learningjava.io.rot13InputStream( in );
    }
    public int read(  ) throws IOException {
        return in.read(  );
    }
}
Loading