Generated by
JDiff

java.net Documentation Differences

This file contains all the changes in documentation in the package java.net as colored differences. Deletions are shown like this, and additions are shown like this.
If no deletions or additions are shown in an entry, the HTML tags will be what has changed. The new HTML tags are shown in the differences. If no documentation existed, and then some was added in a later version, this change is noted in the appropriate class pages of differences, but the change is not shown on this page. Only changes in existing text are shown here. Similarly, documentation which was inherited from another class or interface is not shown here.
Note that an HTML error in the new documentation may cause the display of other documentation changes to be presented incorrectly. For instance, failure to close a <code> tag will cause all subsequent paragraphs to be displayed differently.

Class Authenticator

The class Authenticator represents an object that knows how to obtain authentication for a network connection. Usually it will do this by prompting the user for information.

Applications use this class by creating a subclass and registering an instance of that subclass with the system with setDefault(). When authentication is required the system will invoke a method on the subclass (like getPasswordAuthentication). The subclass's method can query about the authentication being requested with a number of inherited methods (getRequestingXXX()) and form an appropriate message for the user.

All methods that request authentication have a default implementation that fails. @see java.net.Authenticator.#setDefault(java.net.ConnectionAuthenticatorAuthenticator) @see java.net.Authenticator#getPasswordAuthentication() @author Bill Foote @version 1.13 0920 02/2402/9800 @since JDK11.2

Class Authenticator, int getRequestingPort()

Gets the port number for the requested connection. @return an int indicating the port for the requested connection.
Class Authenticator, String getRequestingPrompt()

Gets the prompt string given by the requestor. @return the prompt string given by the requestor (realm for http requests)
Class Authenticator, String getRequestingProtocol()

Give the protocol that's requesting the connection. Often this will be based on a URL but in a future JDKSDK it could be for example "SOCKS" for a password-protected SOCKS5 firewall. @return the protcol optionally followed by "/version" where version is a version number. @see java.net.URL.#getProtocol()
Class Authenticator, String getRequestingScheme()

@returnGets the scheme of the requestor (the HTTP scheme for an HTTP firewall for example). @return the scheme of the requestor
Class Authenticator, InetAddress getRequestingSite()

Gets the InetAddress of the site requesting authorization or null if not available. @return the InetAddress of the site requesting authorization or null if it's not available.
Class Authenticator, PasswordAuthentication requestPasswordAuthentication(InetAddress, int, String, String, String)

Ask the authenticator that has been registered with the system for a password.

First if there is a security manager its checkPermission method is called with a NetPermission("requestPasswordAuthentication") permission. This may result in a java.lang.SecurityException. @param addr The InetAddress of the site requesting authorization or null if not known. @param port the port for the requested connection @param protocol The protocol that's requesting the connection ({@seelink java.net.Authenticator.#getProtocol()}) @param prompt A prompt string for the user @param scheme The authentication scheme @return The username/password or null if one can't be gotten. @throws SecurityException if a security manager exists and its checkPermission method doesn't allow the password authentication request. @see SecurityManager#checkPermission @see java.net.NetPermission


Class ContentHandler

The abstract class ContentHandler is the superclass of all classes that read an Object from a URLConnection.

An application does not generally call the getContent method in this class directly. Instead an application calls the getContent method in class URL or in URLConnection. The application's content handler factory (an instance of a class that implements the interface ContentHandlerFactory set up by a call to setContentHandler) is called with a String giving the MIME type of the object being received on the socket. The factory returns an instance of a subclass of ContentHandler and its getContent method is called to create the object.

If no content handler could be found URLConnection will look for a content handler in a user-defineable set of places. By default it looks in sun.net.www.content but users can define a vertical-bar delimited set of class prefixes to search through in addition by defining the java.content.handler.pkgs property. The class name must be of the form:

 {package-prefix}.{major}.{minor} e.g. YoyoDyne.experimental.text.plain 
If the loading of the content handler class would be performed by a classloader that is outside of the the delegation chain of the caller the JVM will need the RuntimePermission "getClassLoader". @author James Gosling @version 1.10 0914 02/2102/9800 @see java.net.ContentHandler#getContent(java.net.URLConnection) @see java.net.ContentHandlerFactory @see java.net.URL#getContent() @see java.net.URLConnection @see java.net.URLConnection#getContent() @see java.net.URLConnection#setContentHandlerFactory(java.net.ContentHandlerFactory) @since JDK1.0

Class ContentHandlerFactory

This interface defines a factory for content handlers. An implementation of this interface should map a MIME type into an instance of ContentHandler.

This interface is used by the URLStreamHandler class to create a ContentHandler for a MIME type. @author James Gosling @version 1.7 099 02/2102/9800 @see java.net.ContentHandler @see java.net.URLStreamHandler @since JDK1.0


Class DatagramPacket

This class represents a datagram packet.

Datagram packets are used to implement a connectionless packet delivery service. Each message is routed from one machine to another based solely on information contained within that packet. Multiple packets sent from one machine to another might be routed differently and might arrive in any order. @author Pavani Diwanji @author Benjamin Renaud @version 1.25 0630 02/0602/9800 @since JDK1.0

Class DatagramPacket, constructor DatagramPacket(byte[], int, InetAddress, int)

Constructs a datagram packet for sending packets of length length to the specified port number on the specified host. The length argument must be less than or equal to buf.length. @param buf the packet data. @param length the packet length. @param addraddress the destination address. @param port the destination port number. @see java.net.InetAddress
Class DatagramPacket, constructor DatagramPacket(byte[], int, int)

Constructs a DatagramPacket for receiving packets of length length specifying an offset into the buffer.

The length argument must be less than or equal to buf.length. @param buf buffer for holding the incoming datagram. @param offset the offset for the buffer @param length the number of bytes to read. @since JDK1.2

Class DatagramPacket, constructor DatagramPacket(byte[], int, int, InetAddress, int)

Constructs a datagram packet for sending packets of length length with offset ioffsetto the specified port number on the specified host. The length argument must be less than or equal to buf.length. @param buf the packet data. @param offset the packet data offset. @param length the packet data length. @param addraddress the destination address. @param port the destination port number. @see java.net.InetAddress @since JDK1.2
Class DatagramPacket, InetAddress getAddress()

Returns the IP address of the machine to which this datagram is being sent or from which the datagram was received. @return the IP address of the machine to which this datagram is being sent or from which the datagram was received. @see java.net.InetAddress @see #setAddress(java.net.InetAddress)
Class DatagramPacket, byte[] getData()

Returns the data received or the data to be sent. @return the data received or the data to be sent. @see #setData(byte[] int int)
Class DatagramPacket, int getLength()

Returns the length of the data to be sent or the length of the data received. @return the length of the data to be sent or the length of the data received. @see #setLength(int)
Class DatagramPacket, int getOffset()

Returns the offset of the data to be sent or the offset of the data received. @return the offset of the data to be sent or the offset of the data received. @since JDK1.2
Class DatagramPacket, int getPort()

Returns the port number on the remote host to which this datagram is being sent or from which the datagram was received. @return the port number on the remote host to which this datagram is being sent or from which the datagram was received. @see #setPort(int)
Class DatagramPacket, void setAddress(InetAddress)

Sets the IP address of the machine to which this datagram is being sent. @param iaddr the InetAddress @since JDK1.1 @see #getAddress()
Class DatagramPacket, void setData(byte[], int, int)

Set the data buffer for this packet. This sets the data length and offset of the packet. @param buf the buffer to set for this packet @param offset the offset into the data @param length the length of the data @exception NullPointerException if the argument is null @see #getData @see #getOffset @see #getLength @since JDK1.12
Class DatagramPacket, void setPort(int)

Sets the port number on the remote host to which this datagram is being sent. @param iport the port number @since JDK1.1 @see #setPort(int)

Class DatagramSocket

This class represents a socket for sending and receiving datagram packets.

A datagram socket is the sending or receiving point for a packet delivery service. Each packet sent or received on a datagram socket is individually addressed and routed. Multiple packets sent from one machine to another may be routed differently and may arrive in any order.

UDP broadcasts sends and receives are always enabled on a DatagramSocket. @author Pavani Diwanji @version 1.37 1049 02/3002/9800 @see java.net.DatagramPacket @since JDK1.0

Class DatagramSocket, InetAddress getLocalAddress()

Gets the local address to which the socket is bound.

If there is a security manager its checkConnect method is first called with the host address and -1 as its arguments to see if the operation is allowed. @exception SecurityException if a security manager exists and its checkConnect method doesn't allow the operation. @see SecurityManager#checkConnect @return an InetAddress representing the local address to which the socket is bound @since 1.1

Class DatagramSocket, int getReceiveBufferSize()

Get value of the SO_RCVBUF option for this socketDatagramSocket that is the buffer size used by the platform for input on this DatagramSocket. @return the value of the SO_RCVBUF option for this SocketDatagramSocket @exception SocketException if there is an error in the underlying protocol such as a TCP error. @see #setReceiveBufferSize(int)
Class DatagramSocket, int getSendBufferSize()

Get value of the SO_SNDBUF option for this socketDatagramSocket that is the buffer size used by the platform for output on this DatagramSocket. @return the value of the SO_SNDBUF option for this SocketDatagramSocket @exception SocketException if there is an error in the underlying protocol such as a TCP error. @see #setSendBufferSize
Class DatagramSocket, int getSoTimeout()

Retrive setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e. timeout of infinity). @return the setting for SO_TIMEOUT @throws SocketException if there is an error in the underlying protocol such as a TCP error. @since JDK1.1 @see #setSoTimeout(int)
Class DatagramSocket, void setReceiveBufferSize(int)

Sets the SO_RCVBUF option to the specified value for this DatagramSocket. The SO_RCVBUF option is used by the platform's networking code as a hint for the size to use to allocate set the underlying network I/O buffers.

Increasing buffer size can increase the performance of network I/O for high-volume connection while decreasing it can help reduce the backlog of incoming data. For UDP this sets the maximum size of a packet that may be sent on this socketDatagramSocket.

Because SO_RCVBUF is a hint applications that want to verify what size the buffers were set to should call #getReceiveBufferSize.() @param size the size to which to set the receive buffer size. This value must be greater than 0. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @exception IllegalArgumentException if the value is 0 or is negative. @see #getReceiveBufferSize()

Class DatagramSocket, void setSendBufferSize(int)

Sets the SO_SNDBUF option to the specified value for this DatagramSocket. The SO_SNDBUF option is used by the platform's networking code as a hint for the size to use to allocate set the underlying network I/O buffers.

Increasing buffer size can increase the performance of network I/O for high-volume connection while decreasing it can help reduce the backlog of incoming data. For UDP this sets the maximum size of a packet that may be sent on this socket.

Because SO_SNDBUF is a hint applications that want to verify what size the buffers were set to should call #getSendBufferSize.() @param size the size to which to set the send buffer size. This value must be greater than 0. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @exception IllegalArgumentException if the value is 0 or is negative. @see #getSendBufferSize()

Class DatagramSocket, void setSoTimeout(int)

Enable/disable SO_TIMEOUT with the specified timeout in milliseconds. With this option set to a non-zero timeout a call to receive() for this DatagramSocket will block for only this amount of time. If the timeout expires a java.io.InterruptedIOException is raised though the ServerSocket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout. @param timeout the specified timeout in milliseconds. @throws SocketException if there is an error in the underlying protocol such as a TCP error. @since JDK1.1 @see #getSoTimeout()

Class DatagramSocketImpl, void bind(int, InetAddress)

Binds a datagram socket to a local port and address. @param lport the local port @param laddr the local address @exception SocketException if there is an error in the underlying protocol such as a TCP error.
Class DatagramSocketImpl, void create()

Creates a datagram socket. @exception SocketException if there is an error in the underlying protocol such as a TCP error.
Class DatagramSocketImpl, FileDescriptor getFileDescriptor()

GetGets the datagram socket file descriptor. @return a FileDescriptor object representing the datagram socket file descriptor
Class DatagramSocketImpl, int getLocalPort()

GetGets the local port. @return an int representing the local port value
Class DatagramSocketImpl, byte getTTL()

Retrieve the TTL (time-to-live) option. @exception IOException if an I/O exception occurs while retrieving the time-to-live option @deprecated use getTimeToLive instead. @return a byte representing the TTL value @see #setTTL(byte)
Class DatagramSocketImpl, int getTimeToLive()

Retrieve the TTL (time-to-live) option. @exception IOException if an I/O exception occurs while retrieving the time-to-live option @return an int representing the time-to-live value @see #setTimeToLive(int)
Class DatagramSocketImpl, void join(InetAddress)

Join the multicast group. @param inetaddr multicast address to join. @exception IOException if an I/O exception occurs while joining the multicast group.
Class DatagramSocketImpl, void leave(InetAddress)

Leave the multicast group. @param inetaddr multicast address to leave. @exception IOException if an I/O exception occurs while leaving the multicast group.
Class DatagramSocketImpl, int peek(InetAddress)

Peek at the packet to see who it is from. @param i an InetAddress object @return the address which the packet came from. @exception IOException if an I/O exception occurs
Class DatagramSocketImpl, void receive(DatagramPacket)

Receive the datagram packet. @param p the Packet Received. @exception IOException if an I/O exception occurs while receiving the datagram packet.
Class DatagramSocketImpl, void send(DatagramPacket)

Sends a datagram packet. The packet contains the data and the destination address to send the packet to. @param p the packet to be sent. @exception IOException if an I/O exception occurs while sending the datagram packet.
Class DatagramSocketImpl, void setTTL(byte)

Set the TTL (time-to-live) option. @param TTL to bettl a byte set.specifying the TTL value @deprecated use setTimeToLive instead. @exception IOException if an I/O exception occurs while setting the time-to-live option. @see #getTTL()
Class DatagramSocketImpl, void setTimeToLive(int)

Set the TTL (time-to-live) option. @param TTLttl an int specifying the time-to-live value @exception IOException if an I/O beexception setoccurs while setting the time-to-live option. @see #getTimeToLive()
Class DatagramSocketImpl, FileDescriptor fd

The file descriptor object.

Class FileNameMap

A simple interface which provides a mechanism to map between between a file name and a MIME type string. @version 1.8 0911 02/2102/9800 @author Steven B. Byrne @since JDK1.1

Class HttpURLConnection

A URLConnection with support for HTTP-specific features. See the spec for details.

Each HttpURLConnection instance is used to make a single request but the underlying network connection to the HTTP server may be transparently shared by other instances. Calling the close() methods on the InputStream or OutputStream of an HttpURLConnection after a request may free network resources associated with this instance but has no effect on any shared persistent connection. Calling the disconnect() method may close the underlying socket if a persistent connection is otherwise idle at that time. @see java.net.HttpURLConnection#disconnect() @since JDK1.1

Class HttpURLConnection, constructor HttpURLConnection(URL)

Constructor for the URLStreamHandler. @param u the URL
Class HttpURLConnection, void disconnect()

CloseIndicates thethat other connectionrequests to the server are unlikely in the near future. Calling disconnect() should not imply that this HttpURLConnection instance can be reused for other requests.
Class HttpURLConnection, String getRequestMethod()

Get the request method. @return the HTTP request method @see #setRequestMethod(java.lang.String)
Class HttpURLConnection, int getResponseCode()

Gets HTTP response status. Fromfrom responses like:
 HTTP/1.0 200 OK HTTP/1.0 401 Unauthorized 
Extracts the ints 200 and 401 respectively. Returns -1 if none can be discerned from the response (i.e. the response is not valid HTTP). @throws IOException if an error occurred connecting to the server. @return the HTTP Status-Code
Class HttpURLConnection, String getResponseMessage()

Gets the HTTP response message if any returned along with the response code from a server. From responses like:
 HTTP/1.0 200 OK HTTP/1.0 404 Not Found 
Extracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP). @throws IOException if an error occurred connecting to the server. @return the HTTP response message or null
Class HttpURLConnection, void setFollowRedirects(boolean)

Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this class. True by default. Applets cannot change this variable.

If there is a security manager this method first calls the security manager's checkSetFactory method to ensure the operation is allowed. This could result in a SecurityException. @param set a boolean indicating whether or not to follow HTTP redirects. @exception SecurityException if a security manager exists and its checkSetFactory method doesn't allow the operation. @see SecurityManager#checkSetFactory @see #getFollowRedirects()

Class HttpURLConnection, void setRequestMethod(String)

Set the method for the URL request one of: are legal subject to protocol restrictions. The default method is GET. @param method the HTTP method @exception ProtocolException if the method cannot be reset or if the requested method isn't valid for HTTP. @see #getRequestMethod()
Class HttpURLConnection, boolean usingProxy()

Indicates if the connection is going through a proxy. @return a boolean indicating if the connection is using a proxy.
Class HttpURLConnection, int HTTP_BAD_REQUEST

4XXHTTP Status-Code 400: clientBad errorRequest.
Class HttpURLConnection, int HTTP_MULT_CHOICE

3XXHTTP Status-Code 300: relocation/redirectMultiple Choices.
Class HttpURLConnection, int HTTP_OK

2XX:HTTP Status-Code generally200: "OK".
Class HttpURLConnection, int HTTP_SERVER_ERROR

5XX:@deprecated serverit erroris misplaced and shouldn't have existed.

Class InetAddress

This class represents an Internet Protocol (IP) address.

Applications should use the methods getLocalHost getByName or getAllByName to create a new InetAddress instance. @author Chris Warth @version 1.66 0570 02/1602/00 @see java.net.InetAddress#getAllByName(java.lang.String) @see java.net.InetAddress#getByName(java.lang.String) @see java.net.InetAddress#getLocalHost() @since JDK1.0

Class InetAddress, String getHostName()

ReturnsGets the hostname for this address. If the host is equal to nullname thenfor this address refers to any of the local machine's available networkIP addressesaddress.

If there is a security manager its checkConnect method is first called with the hostname and -1 as its arguments to see if the operation is allowed. @return the host name for this IP address. @exception SecurityException if a security manager exists and its checkConnect method doesn't allow the operation . @see SecurityManager#checkConnect

Class InetAddress, boolean isMulticastAddress()

Utility routine to check if the InetAddress is aan IP multicast address. IP multicast address is a Class D address i.e first four bits of the address are 1110. @return a boolean indicating if the InetAddress is an IP multicast address @since JDK1.1

Class JarURLConnection

A URL Connection to a Java ARchive (JAR) file or an entry in a JAR file.

The syntax of a JAR URL is:

 jar:<url> /{entry} 

for example:

jar:http://www.foo.com/bar/baz.jar /COM/foo/Quux.class

Jar URLs should be used to either refer to singlea JAR entriesfile or as base URLs toentries refer toin a JAR files as codebases or relative URLsfile. The example above is a full JAR URL which refers to a JAR entry. If the entry name is omitted the URL refers to the whole JAR file: jar:http://www.foo.com/bar/baz.jar /

Users should cast the generic URLConnection to a JarURLConnection when they know that the URL they created is a JAR URL and they need JAR-specific functionality. For example:

 URL url = new URL("jar:file:/home/duke/duke.jar /"); JarURLConnection jarConnection = (JarURLConnection)url.openConnection(); Manifest manifest = jarConnection.getManifest(); 

Examples:

A Jar entry
jar:http://www.foo.com/bar/baz.jar /COM/foo/Quux.class
A Jar file
jar:http://www.foo.com/bar/baz.jar /
A Jar directory
jar:http://www.foo.com/bar/baz.jar /COM/foo/

/ is refered to as the separator.

When constructing a JAR url via new URL(context spec) the following rules apply:

@see java.net.URL @see java.net.URLConnection @see java.util.jar.JarFile @see java.util.jar.JarInputStream @see java.util.jar.Manifest @see java.util.zip.ZipEntry @author Benjamin Renaud @since JDK11.2
Class JarURLConnection, Certificate[] getCertificates()

/** Return the Certificate object for this connection if the URL for it points to a JAR file entry null otherwise. This method can only be called once the connection has been completely verified by reading from the input stream until the end of the stream has been reached. Otherwise this method will return null @return the Certificate object for this connection if the URL for it points to a JAR file entry null otherwise. @exception IOException if getting the JAR entry causes an IOException to be thrown. @see #getJarEntry

Class MalformedURLException

Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a specification string or the string could not be parsed. @author Arthur van Hoff @version 1.11 0913 02/2102/9800 @since JDK1.0

Class MulticastSocket

The multicast datagram socket class is useful for sending and receiving IP multicast packets. A MulticastSocket is a (UDP) DatagramSocket with additional capabilities for joining "groups" of other multicast hosts on the internet.

A multicast group is specified by a class D IP address thoseand by a standard UDP port number. Class D IP addresses are in the range 224.0.0.10 to 239.255.255.255 inclusive. and byThe address a224.0.0.0 standard UDP portis reserved and numbershould not be used.

One would join a multicast group by first creating a MulticastSocket with the desired port then invoking the joinGroup(InetAddress groupAddr) method:

 // join a Multicast group and send the group salutations ... byte[]String msg = {'H' 'e' 'l' 'l' 'o'}"Hello"; InetAddress group = InetAddress.getByName("228.5.6.7"); MulticastSocket s = new MulticastSocket(6789); s.joinGroup(group); DatagramPacket hi = new DatagramPacket(msg.getBytes() msg.length() group 6789); s.send(hi); // get their responses byte[] buf = new byte[1000]; DatagramPacket recv = new DatagramPacket(buf buf.length); s.receive(recv); ... // OK I'm done talking - leave the group... s.leaveGroup(group); 
When one sends a message to a multicast group all subscribing recipients to that host and port receive the message (within the time-to-live range of the packet see below). The socket needn't be a member of the multicast group to send messages to it.

When a socket subscribes to a multicast group/port it receives datagrams sent by other hosts to the group/port as do all other members of the group and port. A socket relinquishes membership in a group by the leaveGroup(InetAddress addr) method. Multiple MulticastSocket's may subscribe to a multicast group and port concurrently and they will all receive group datagrams.

Currently applets are not allowed to use multicast sockets. @author Pavani Diwanji @since JDK1.1

Class MulticastSocket, constructor MulticastSocket()

Create a multicast socket.

If there is a security manager its checkListen method is first called with 0 as its argument to ensure the operation is allowed. This could result in a SecurityException. @exception IOException if an I/O exception occurs while creating the MulticastSocket @exception SecurityException if a security manager exists and its checkListen method doesn't allow the operation. @see SecurityManager#checkListen

Class MulticastSocket, constructor MulticastSocket(int)

Create a multicast socket and bind it to a specific port.

If there is a security manager its checkListen method is first called with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException. @param port port to use @exception IOException if an I/O exception occurs while creating the MulticastSocket @exception SecurityException if a security manager exists and its checkListen method doesn't allow the operation. @see SecurityManager#checkListen

Class MulticastSocket, InetAddress getInterface()

Retrieve the address of the network interface used for multicast packets. @return An InetAddress representing the address of the network interface used for multicast packets. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @see #setInterface(java.net.InetAddress)
Class MulticastSocket, byte getTTL()

Get the default time-to-live for multicast packets sent out on the socket. @exception IOException if an I/O exception occurs while getting the default time-to-live value @deprecated use the getTimeToLive method instead which returns an int instead of a byte. @see #setTTL(byte)
Class MulticastSocket, int getTimeToLive()

Get the default time-to-live for multicast packets sent out on the socket. @exception IOException if an I/O exception occurs while getting the default time-to-live value @return the default time-to-live value @see #setTimeToLive(int)
Class MulticastSocket, void setInterface(InetAddress)

Set the multicast network interface used by methods whose behavior would be affected by the value of the network interface. Useful for multihomed hosts. @param inf the InetAddress @exception SocketException if there is an error in the underlying protocol such as a TCP error. @see #getInterface()
Class MulticastSocket, void setTTL(byte)

Set the default time-to-live for multicast packets sent out on this socket. The TTL sets the IP time-to-live for DatagramPackets sent to a MulticastGroup which specifies how many "hops" that the packet will be forwarded on the network before it expires.

The ttl is an unsigned 8-bit quantity and so must be in the range 0 < ttl < 0xFF . @param ttl the time-to-live @exception IOException if an I/O exception occurs while setting the default time-to-live value @deprecated use the setTimeToLive method instead which uses int instead of byte as the type for ttl. @see #getTTL()

Class MulticastSocket, void setTimeToLive(int)

Set the default time-to-live for multicast packets sent out on this socket. The TTL sets the IP time-to-live for DatagramPackets sent to a MulticastGroup which specifies how many "hops" that the packet will be forwarded on the network before it expires.

The ttl must be in the range 0 < ttl < 255 or an IllegalArgumentException will be thrown. @exception IOException if an I/O exception occurs while setting the default time-to-live value @param ttl the time-to-live @see #getTimeToLive()


Class NetPermission

This class is for various network permissions. A NetPermission contains a name (also referred to as a "target name") but no actions list; you either have the named permission or you don't.

The target name is the name of the network permission (see below). The naming convention follows the hierarchical property naming convention. Also an asterisk may appear at the end of the name following a "." or by itself to signify a wildcard match. For example: "foo.*" or "*" is valid "*foo" or "a*b" is not valid.

The following table lists all the possible NetPermission target names and for each provides a description of what the permission allows and a discussion of the risks of granting code the permission.

Permission Target Name What the Permission Allows Risks of Allowing this Permission
setDefaultAuthenticator The ability to set the way authentication information is retrieved when a proxy or HTTP server asks for authentication Malicious code can set an authenticator that monitors and steals user authentication input as it retrieves the input from the user.
requestPasswordAuthentication The ability to ask the authenticator registered with the system for a password Malicious code may steal this password.
specifyStreamHandler The ability to specify a stream handler when constructing a URL Malicious code may create a URL with resources that it would normally not have access to (like file:/foo/fum/) specifying a stream handler that gets the actual bytes from someplace it does have access to. Thus it might be able to trick the system into creating a ProtectionDomain/CodeSource for a class even though that class really didn't come from that location.
@see java.security.BasicPermission @see java.security.Permission @see java.security.Permissions @see java.security.PermissionCollection @see java.lang.SecurityManager @version 1.37 9939 00/0402/2202 @author Marianne Mueller @author Roland Schemers


Class PasswordAuthentication

The class PasswordAuthentication is a data holder that is used by Authenticator. It is simply a repository for a user name and a password. @see java.net.Authenticator @see java.net.Authenticator#getPasswordAuthentication() @author Bill Foote @version 1.6 0610 02/2902/9800 @since JDK11.2

Class ProtocolException

Thrown to indicate that there is an error in the underlying protocol such as a TCP error. @author Chris Warth @version 1.11 0913 02/2102/9800 @since JDK1.0

Class ServerSocket

This class implements server sockets. A server socket waits for requests to come in over the network. It performs some operation based on that request and then possibly returns a result to the requester.

The actual work of the server socket is performed by an instance of the SocketImpl class. An application can change the socket factory that creates the socket implementation to configure itself to create sockets appropriate to the local firewall. @author unascribed @version 1.35 0943 01/2721/0001 @see java.net.SocketImpl @see java.net.ServerSocket#setSocketFactory(java.net.SocketImplFactory) @since JDK1.0

Class ServerSocket, constructor ServerSocket(int, int)

Creates a server socket and binds it to the specified local port number with the specified backlog. A port number of 0 creates a socket on any free port.

The maximum queue length for incoming connection indications (a request to connect) is set to the backlog parameter. If a connection indication arrives when the queue is full the connection is refused.

If the application has specified a server socket factory that factory's createSocketImpl method is called to create the actual socket implementation. Otherwise a "plain" socket is created.

If there is a security manager its checkListen method is called with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException. @param port the specified port or 0 to use any free port. @param backlog the maximum length of the queue. @exception IOException if an I/O error occurs when opening the socket. @exception SecurityException if a security manager exists and its checkListen method doesn't allow the operation. @see java.net.SocketImpl @see java.net.SocketImplFactory#createSocketImpl() @see java.net.ServerSocket#setSocketFactory(java.net.SocketImplFactory) @see SecurityManager#checkListen

Class ServerSocket, constructor ServerSocket(int, int, InetAddress)

Create a server with the specified port listen backlog and local IP address to bind to. The bindAddr argument can be used on a multi-homed host for a ServerSocket that will only accept connect requests to one of its addresses. If bindAddr is null it will default accepting connections on any/all local addresses. The port must be between 0 and 65535 inclusive.

If there is a security manager this method calls its checkListen method with the port argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

@param port the local TCP port @param backlog the listen backlog @param bindAddr the local InetAddress the server will bind to @throws SecurityException if a security manager exists and its checkListen method doesn't allow the operation. @seethrows IOException if an I/O SocketConstantserror occurs when opening the socket. @see SocketOptionSocketOptions @see SocketImpl @see SecurityManager#checkListen @since JDK1.1

Class ServerSocket, Socket accept()

Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.

A new Socket s is created and if there is a security manager the security manager's checkAccept method is called with s.getInetAddress().getHostAddress() and s.getPort() as its arguments to ensure the operation is allowed. This could result in a SecurityException. @exception IOException if an I/O error occurs when waiting for a connection. @exception SecurityException if a security manager exists and its checkListen method doesn't allow the operation. @return the new Socket @see SecurityManager#checkAccept

Class ServerSocket, int getSoTimeout()

Retrive setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e. timeout of infinity). @return the SO_TIMEOUT value @exception IOException if an I/O error occurs @since JDK1.1 @see #setSoTimeout(int)
Class ServerSocket, void implAccept(Socket)

Subclasses of ServerSocket use this method to override accept() to return their own subclass of socket. So a FooServerSocket will typically hand this method an empty FooSocket(). On return from implAccept the FooSocket will be connected to a client. @param s the Socket @throws IOException if an I/O error occurs when waiting for a connection. @since JDK1.1
Class ServerSocket, void setSoTimeout(int)

Enable/disable SO_TIMEOUT with the specified timeout in milliseconds. With this option set to a non-zero timeout a call to accept() for this ServerSocket will block for only this amount of time. If the timeout expires a java.io.InterruptedIOException is raised though the ServerSocket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout. @param timeout the specified timeout in milliseconds @exception SocketException if there is an error in the underlying protocol such as a TCP error. @since JDK1.1 @see #getSoTimeout()

Class Socket

This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines.

The actual work of the socket is performed by an instance of the SocketImpl class. An application by changing the socket factory that creates the socket implementation can configure itself to create sockets appropriate to the local firewall. @author unascribed @version 1.42 0953 02/2402/9800 @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory) @see java.net.SocketImpl @since JDK1.0

Class Socket, constructor Socket(InetAddress, int, InetAddress, int)

Creates a socket and connects it to the specified remote address on the specified remote port. The Socket will also bind() to the local address and port supplied.

If there is a security manager its checkConnect method is called with the host address and port as its arguments. This could result in a SecurityException. @param address the remote address @param port the remote port @param localAddr the local address the socket is bound to @param localPort the local port the socket is bound to @exception IOException if an I/O error occurs when creating the socket. @exception SecurityException if a security manager exists and its checkConnect method doesn't allow the operation. @see SecurityManager#checkConnect @since JDK1.1

Class Socket, constructor Socket(SocketImpl)

Creates an unconnected Socket with a user-specified SocketImpl.

The@param impl parameter is an instance of a SocketImpl the subclass wishes to use on the Socket. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @since JDK1.1

Class Socket, constructor Socket(String, int)

Creates a stream socket and connects it to the specified port number on the named host.

If the application has specified a server socket factory that factory's createSocketImpl method is called to create the actual socket implementation. Otherwise a "plain" socket is created.

If there is a security manager its checkConnect method is called with the host address and port as its arguments. This could result in a SecurityException. @param host the host name. @param port the port number. @exception UnknownHostException if the IP address of the host could not be determined. @exception IOException if an I/O error occurs when creating the socket. @exception SecurityException if a security manager exists and its checkConnect method doesn't allow the operation. @see java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory) @see java.net.SocketImpl @see java.net.SocketImplFactory#createSocketImpl() @see SecurityManager#checkConnect

Class Socket, constructor Socket(String, int, InetAddress, int)

Creates a socket and connects it to the specified remote host on the specified remote port. The Socket will also bind() to the local address and port supplied.

If there is a security manager its checkConnect method is called with the host address and port as its arguments. This could result in a SecurityException. @param host the name of the remote host @param port the remote port @param localAddr the local address the socket is bound to @param localPort the local port the socket is bound to @exception IOException if an I/O error occurs when creating the socket. @exception SecurityException if a security manager exists and its checkConnect method doesn't allow the operation. @see SecurityManager#checkConnect @since JDK1.1

Class Socket, InetAddress getLocalAddress()

Gets the local address to which the socket is bound. @return the local address to which the socket is bound. @since JDK1.1
Class Socket, int getReceiveBufferSize()

GetGets the value of the SO_RCVBUF option for this socketSocket that is the buffer size used by the platform for input on this Socket. @return the value of the SO_RCVBUF option for this Socket. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @see #setReceiveBufferSize(int)
Class Socket, int getSendBufferSize()

Get value of the SO_SNDBUF option for this socketSocket that is the buffer size used by the platform for output on this Socket. @return the value of the SO_SNDBUF option for this Socket. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @see #setSendBufferSize(int)
Class Socket, int getSoLinger()

Returns setting for SO_LINGER. -1 returns implies that the option is disabled. The setting only affects socket close. @return the setting for SO_LINGER. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @since JDK1.1 @see #setSoLinger(boolean int)
Class Socket, int getSoTimeout()

Returns setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e. timeout of infinity). @return the setting for SO_TIMEOUT @exception SocketException if there is an error in the underlying protocol such as a TCP error. @since JDK1.1 @see #setSoTimeout(int)
Class Socket, boolean getTcpNoDelay()

Tests if TCP_NODELAY is enabled. @return a boolean indicating whether or not TCP_NODELAY is enabled. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @since JDK1.1 @see #setTcpNoDelay(boolean)
Class Socket, void setReceiveBufferSize(int)

Sets the SO_RCVBUF option to the specified value for this DatagramSocketSocket. The SO_RCVBUF option is used by the platform's networking code as a hint for the size to use to allocate set the underlying network I/O buffers.

Increasing buffer size can increase the performance of network I/O for high-volume connection while decreasing it can help reduce the backlog of incoming data. For UDP this sets the maximum size of a packet that may be sent on this socketSocket.

Because SO_RCVBUF is a hint applications that want to verify what size the buffers were set to should call #getReceiveBufferSize.() @param size the size to which to set the receive buffer size. This value must be greater than 0. @exception IllegalArgumentException if the value is 0 or is negative. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @see #getReceiveBufferSize()

Class Socket, void setSendBufferSize(int)

Sets the SO_SNDBUF option to the specified value for this DatagramSocketSocket. The SO_SNDBUF option is used by the platform's networking code as a hint for the size to use to allocate set the underlying network I/O buffers.

Increasing buffer size can increase the performance of network I/O for high-volume connection while decreasing it can help reduce the backlog of incoming data. For UDP this sets the maximum size of a packet that may be sent on this socketSocket.

Because SO_SNDBUF is a hint applications that want to verify what size the buffers were set to should call #getSendBufferSize() @exception SocketException if there is an error in the underlying protocol such as a TCP error. @param size the size to which to set the send buffer size. This value must be greater than 0. @exception IllegalArgumentException if the value is 0 or is negative. @see #getSendBufferSize()

Class Socket, void setSoLinger(boolean, int)

Enable/disable SO_LINGER with the specified linger time in seconds. IfThe the specifiedmaximum timeout value exceeds 65is 535platform itspecific. will be reduced to 65 535The setting only affects socket close. @param on whether or not to linger on. @param linger how to linger for if on is true. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @exception IllegalArgumentException if the linger value is negative. @since JDK1.1 @see #getSoLinger()
Class Socket, void setSoTimeout(int)

Enable/disable SO_TIMEOUT with the specified timeout in milliseconds. With this option set to a non-zero timeout a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires a java.io.InterruptedIOException is raised though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout. @param timeout the specified timeout in milliseconds. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @since JDK 1.1 @see #getSoTimeout()
Class Socket, void setTcpNoDelay(boolean)

Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm). @param on true to enable TCP_NODELAY false to disable. @exception SocketException if there is an error in the underlying protocol such as a TCP error. @since JDK1.1 @see #getTcpNoDelay()

Class SocketException

Thrown to indicate that there is an error in the underlying protocol such as a TCP error. @author Jonathan Payne @version 1.11 0914 02/2102/9800 @since JDK1.0
Class SocketException, constructor SocketException()

Constructs a new ProtocolExceptionSocketException with no detail message.
Class SocketException, constructor SocketException(String)

Constructs a new ProtocolExceptionSocketException with the specified detail message. @param hostmsg the detail message.

Class SocketImpl

The abstract class SocketImpl is a common superclass of all classes that actually implement sockets. It is used to create both client and server sockets.

A "plain" socket implements these methods exactly as described without attempting to go through a firewall or proxy. @author unascribed @version 1.26 0931 01/2721/0001 @since JDK1.0


Class SocketImplFactory

This interface defines a factory for socket implementations. It is used by the classes Socket and ServerSocket to create actual socket implementations. @author Arthur van Hoff @version 1.12 0915 02/2102/9800 @see java.net.Socket @see java.net.ServerSocket @since JDK1.0
Class SocketImplFactory, SocketImpl createSocketImpl()

Creates a new SocketImpl instance. @return a new instance of SocketImpl. @see java.ionet.SocketImpl

Class SocketOptions

Interface of methods to get/set socket options. This interface is implemented by: SocketImpl and DatagramSocketImpl. Subclasses of these should override the methods of this interface in order to support their own options.

The methods and constants which specify options in this interface are for implementation only. If you're not subclassing SocketImpl or DatagramSocketImpl you won't use these directly. There are type-safe methods to get/set each of these options in Socket ServerSocket DatagramSocket and MulticastSocket.

A subset of the standard BSD-style socket options are supported in the JDK base classes PlainSocketImpl and PlainDatagramSocketImpl. A brief description of each and their use is provided.

@version 1.12 0720 02/1002/9800 @author David Brown

Class SocketOptions, Object getOption(int)

Fetch the value of an option. Binary options will return java.lang.Boolean(true) if enabled java.lang.Boolean(false) if disabled e.g.:
 SocketImpl s; ... Boolean noDelay = (Boolean)(s.getOption(TCP_NODELAY)); if (noDelay.booleanValue()) { // true if TCP_NODELAY is enabled... ... } 

For options that take a particular type as a parameter getOption(int) will return the paramter's value else it will return java.lang.Boolean(false):

 Object o = s.getOption(SO_LINGER); if (o instanceof Integer) { System.out.print("Linger time is " + ((Integer)o).intValue()); } else { // the true type of o is java.lang.Boolean(false); } 
@param optID an int identifying the option to fetch @return the value of the option @throws SocketException if the socket is closed @throws SocketException if optID is unknown along the protocol stack (including the SocketImpl) @see #setOption(int java.lang.Object)
Class SocketOptions, void setOption(int, Object)

Enable/disable the option specified by optID. If the option is to be enabled and it takes an option-specific "value" this is passed in value. The actual type of value is option-specific and it is an error to pass something that isn't of the expected type:
 SocketImpl s; ... s.setOption(SO_LINGER new Integer(10)); // OK - set SO_LINGER w/ timeout of 10 sec. s.setOption(SO_LINGER new Double(10)); // ERROR - expects java.lang.Integer 
If the requested option is binary it can be set using this method by a java.lang.Boolean:
 s.setOption(TCP_NODELAY new Boolean(true)); // OK - enables TCP_NODELAY a binary option 

Any option can be disabled using this method with a Boolean(false):
 s.setOption(TCP_NODELAY new Boolean(false)); // OK - disables TCP_NODELAY s.setOption(SO_LINGER new Boolean(false)); // OK - disables SO_LINGER 

For an option that has a notion of on and off and requires a particularnon-boolean parameter setting its value to anything other than Boolean(false) implicitly enables it.
Throws SocketException if the option is unrecognized the socket is closed or some low-level error occurred
@param optID identifies the option @param value the parameter of the socket option @throws SocketException if the option is unrecognized the socket is closed or some low-level error occurred @see #getOption(int)
Class SocketOptions, int SO_BINDADDR

Fetch the local address binding of a socket (this option cannot be "set" only "gotten" since sockets are bound at creation time and so the locally bound address cannot be changed). The default local address of a socket is INADDR_ANY meaning any local address on a multi-homed host. A multi-homed host can use this option to accept connections to only one of its addresses (in the case of a ServerSocket or DatagramSocket) or to specify its return address to the peer (for a Socket or DatagramSocket). The parameter of this option is an InetAddress.

This option must be specified in the constructor.

Valid for: SocketImpl DatagramSocketImpl

@see Socket#getLocalAddress @see Server#getLocalAddress @see DatagramSocket#getLocalAddress

Class SocketOptions, int SO_RCVBUF

Set a hint the size of the underlying buffers used by the platform for incoming network I/O. When used in set this is a suggestion to the kernel from the application about the size of buffers to use for the data to be received over the socket. When used in get this must return the size of the buffer actually used by the platform when receiving in data on this socket. Valid for all sockets: SocketImpl DatagramSocketImpl @see Socket#setReceiveSizesetReceiveBufferSize @see Socket#getReceiveBufferSize @see DatagramSocket#setReceiveSizesetReceiveBufferSize @see DatagramSocket#getReceiveBufferSize
Class SocketOptions, int SO_SNDBUF

Set a hint the size of the underlying buffers used by the platform for outgoing network I/O. When used in set this is a suggestion to the kernel from the application about the size of buffers to use for the data to be sent over the socket. When used in get this must return the size of the buffer actually used by the platform when sending out data on this socket. Valid for all sockets: SocketImpl DatagramSocketImpl @see Socket#setSendSizesetSendBufferSize @see Socket#getSendBufferSize @see DatagramSocket#setSendSizesetSendBufferSize @see DatagramSocket#getSendBufferSize

Class SocketPermission

This class represents access to a network via sockets. A SocketPermission consists of a host specification and a set of "actions" specifying ways to connect to that host. The host is specified as
 host = (hostname | IPaddress)[:portrange] portrange = portnumber | -portnumber | portnumber-[portnumber] 
The host is expressed as a DNS name as a numerical IP address or as "localhost" (for the local machine). The wildcard "*" may be included once in a DNS name host specification. If it is included it must be in the leftmost position as in "*.sun.com".

The port or portrange is optional. A port specification of the form "N-" where N is a port number signifies all ports numbered N and above while a specification of the form "-N" indicates all ports numbered N and below.

The possible ways to connect to the host are

 accept connect listen resolve 
The "listen" action is only meaningful when used with "localhost". The "resolve" (resolve host/ip name service lookups) action is implied when any of the other actions are present.

As an example of the creation and meaning of SocketPermissions note that if the following permission:

 p1 = new SocketPermission("puffin.eng.sun.com:7777" "connect accept"); 
is granted to some code it allows that code to connect to port 7777 on puffin.eng.sun.com and to accept connections on that port.

Similarly if the following permission:

 p1 = new SocketPermission("puffin.eng.sun.com:7777" "connect accept"); p2 = new SocketPermission("localhost:1024-" "accept connect listen"); 
is granted to some code it allows that code to accept connections on connect to or listen on any port between 1024 and 65535 on the local host.

Note: Granting code permission to accept or make connections to remote hosts may be dangerous because malevolent code can then more easily transfer and share confidential data among parties who may not otherwise have access to the data. @see java.security.Permissions @see SocketPermissionsSocketPermission @version 1.2835 00/0604/2117 @author Marianne Mueller @author Roland Schemers @serial exclude


Class URL

Class URL represents a Uniform Resource Locator a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory or it can be a reference to a more complicated object such as a query to a database or to a search engine. More information on the types of URLs and their formats can be found at:
 http://www.ncsa.uiuc.edu/demoweb/url-primer.html 

In general a URL can be broken into several parts. The previous example of a URL indicates that the protocol to use is http (HyperText TransportTransfer Protocol) and that the information resides on a host machine named www.ncsa.uiuc.edu. The information on that host machine is named /demoweb/url-primer.html. The exact meaning of this name on the host machine is both protocol dependent and host dependent. The information normally resides in a file but it could be generated on the fly. This component of the URL is called the filepath component even though the information is not necessarily in a file.

A URL can optionally specify a "port" which is the port number to which the TCP connection is made on the remote host machine. If the port is not specified the default port for the protocol is used instead. For example the default port for http is 80. An alternative port could be specified as:

 http://www.ncsa.uiuc.edu:8080/demoweb/url-primer.html 

A URL may have appended to it ana "anchorfragment" also known as a "ref" or a "reference". The anchorfragment is indicated by the sharp sign character "#" followed by more characters. For example

 http://java.sun.com/index.html#chapter1 

This anchorfragment is not technically part of the URL. Rather it indicates that after the specified resource is retrieved the application is specifically interested in that part of the document that has the tag chapter1 attached to it. The meaning of a tag is resource specific.

An application can also specify a "relative URL" which contains only enough information to reach the resource relative to another URL. Relative URLs are frequently used within HTML pages. For example if the contents of the URL:

 http://java.sun.com/index.html 
contained within it the relative URL:
 FAQ.html 
it would be a shorthand for:
 http://java.sun.com/FAQ.html 

The relative URL need not specify all the components of a URL. If the protocol host name or port number is missing the value is inherited from the fully specified URL. The file component must be specified. The optional anchorfragment is not inherited. @author James Gosling @version 1.6194 0402/1602/9800 @since JDK1.0

Class URL, constructor URL(String, String, String)

Creates an absolutea URL from the specified protocol name host name and file name. The default port for the specified protocol is used.

This method is equivalent to calling the four-argument constructor with the arguments being protocol host -1 and file. @param protocol the name of the protocol to use. @param host the host to connect toname of the host. @param file the file on thatthe host. @exception MalformedURLException if an unknown protocol is specified. @see java.net.URL#URL(java.lang.String java.lang.String int java.lang.String)

Class URL, constructor URL(String, String, int, String)

Creates a URL object from the specified protocol host port number and file. Specifying a port number of -1 indicates that the URL should use the default port for the protocol.

If this is the first URL object being created with the specified protocol a stream protocol handler object an instance of class URLStreamHandler is created for that protocol:

  1. If the application has previously set up an instance of URLStreamHandlerFactory as the stream handler factory then the createURLStreamHandler method of that instance is called with the protocol string as an argument to create the stream protocol handler.
  2. If no URLStreamHandlerFactory has yet been set up or if the factory's createURLStreamHandler method returns null then the constructor finds the value of the system property:
     java.protocol.handler.pkgs 
    If the value of that system property is not null it is interpreted as a list of packages separated by a vertical slash character '|'. The constructor tries to load the class named:
     <package>.<protocol>.Handler 
    where <package> is replaced by the name of the package and <protocol> is replaced by the name of the protocol. If this class does not exist or if the class exists but it is not a subclass of URLStreamHandler then the next package in the list is tried.
  3. If the previous step fails to find a protocol handler then the constructor tries to load the class named:
     sun.net.www.protocol.<protocol>.Handler 
    If this class does not exist or if the class exists but it is not a subclass of URLStreamHandler then a MalformedURLException is thrown.
@param protocol the name of the protocol to use. @param host the name of the host. @param port the port number on the host. @param file the host file. on the host @exception MalformedURLException if an unknown protocol is specified. @see java.lang.System#getProperty(java.lang.String) @see java.net.URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory) @see java.net.URLStreamHandler @see java.net.URLStreamHandlerFactory#createURLStreamHandler(java.lang.String)
Class URL, constructor URL(String, String, int, String, URLStreamHandler)

Creates a URL object from the specified protocol host port number file and handler. Specifying a port number of -1 indicates that the URL should use the default port for the protocol. Specifying a handler of null indicates that the URL should use a default stream handler for the protocol as outlined for: java.net.URL#URL(java.lang.String java.lang.String int java.lang.String)

If the handler is not null and there is a security manager the security manager's checkPermission method is called with a NetPermission("specifyStreamHandler") permission. This may result in a SecurityException. @param protocol the name of the protocol to use. @param host the name of the host. @param port the port number on the host. @param file the host file. on the host @param handler the stream handler for the URL. @exception MalformedURLException if an unknown protocol is specified. @exception SecurityException if a security manager exists and its checkPermission method doesn't allow specifying a stream handler explicitly. @see java.lang.System#getProperty(java.lang.String) @see java.net.URL#setURLStreamHandlerFactory(java.net.URLStreamHandlerFactory) @see java.net.URLStreamHandler @see java.net.URLStreamHandlerFactory#createURLStreamHandler(java.lang.String) @see SecurityManager#checkPermission @see java.net.NetPermission

Class URL, constructor URL(URL, String)

Creates a URL by parsing the specificationgiven spec within a specified context. If theThe contextnew argumentURL is notcreated nullfrom the given context URL and the spec argument is a partial URLas described in RFC2396 specification"Uniform then any of theResource Identifiers : Generic stringsSyntax" missing: components
 are<scheme>://<authority><path> <query>#<fragment> inherited
fromThe reference is parsed into the contextscheme argument.authority The specification givenpath query and fragment byparts. If the Stringpath argumentcomponent is parsedempty to determine if it specifies aand the scheme authority and query protocol.components If theare undefined Stringthen contains an ASCII colonthe new URL is ':'a character beforereference to the firstcurrent occurrencedocument. of an ASCII slash characterOtherwise the any fragment and '/'query thenparts present in the charactersspec are used beforein the colonnew URL. compriseIf the protocol.scheme component Ifis defined in the given spec argumentand does not specify amatch protocol:the scheme Ifof the context argument is notthen the new nullURL then the protocol is copied fromis created as an absolute URL based on the context argumentspec alone. IfOtherwise the context argumentscheme component is null theninherited afrom MalformedURLExceptionthe is throwncontext URL. If the specauthority argument does specify acomponent is present in protocol:the spec Ifthen the context argumentspec is nulltreated or specifies a different protocol than the specificationas absolute and the spec authority and path argumentwill replace the context argument is ignoredauthority and path. If the context argumentauthority component is not null andabsent specifiesin the same protocolspec asthen the specification theauthority hostof portthe number andnew URL filewill are copiedbe inherited from the context argument. intoIf the newlyspec's createdpath URL.component begins Thewith a slash character constructor"/" then searches forthe an appropriate stream protocol handler of typepath is treated as absolute and the URLStreamHandlerspec as outlinedpath replaces for:the context java.net.URL#URL(java.langpath.String java.lang.StringOtherwise intthe java.lang.String)path is The stream protocoltreated as a handler'srelative parseURLpath methodand is calledappended to parsethe context path. The path is canonicalized through the remainingremoval of directory changes made fieldsby occurences of the".." specificationand that".". override any defaults set by the contextFor a more detailed description of URL argumentparsing refer to RFC2396. @param context the context in which to parse the specification. @param spec athe String representationto ofparse as a URL. @exception MalformedURLException if no protocol is specified or an unknown protocol is found. @see java.net.URL#URL(java.lang.String java.lang.String int java.lang.String) @see java.net.URLStreamHandler @see java.net.URLStreamHandler#parseURL(java.net.URL java.lang.String int int)
Class URL, constructor URL(URL, String, URLStreamHandler)

Creates a URL by parsing the specification spec within a specified context. If the context argument is not null and the spec argument is a partial URL specification then any of the strings missing components are inherited from the context argument. The specification given by the String argument is parsed to determine if it specifies a protocol. If the String contains an ASCII colon ':' character before the first occurrence of an ASCII slash character '/' then the characters before the colon comprise the protocol. If the spec argument does not specify a protocol: If the context argument is not null then the protocol is copied from the context argument. If the context argument is null then a MalformedURLException is thrown. If the spec argument does specify a protocol: Ifwith the context argument is nullspecified or specifieshandler within a different protocol than the specification argument thespecified context argument is ignored. If the context argumenthandler is not null and specifies the same protocolparsing occurs as the specification the host port numberwith and file are copied from the context argument into the newlytwo created URL. If the argument handler is specified then it will be used as the stream handler for the URL and will override that of the context. Specifying a stream handler requires the NetPermission "specifyStreamHandler" or a SecurityException will be thrown. Otherwise if handler is null and the context is valid then the protocol handler of the context will be inherited. The stream protocol handler's parseURL method is called to parse the remaining fields of the specification that override any defaults set by the context argumentconstructor. @param context the context in which to parse the specification. @param spec athe String representationto parse ofas a URL. @param handler the stream handler for the URL. @exception MalformedURLException if no protocol is specified or an unknown protocol is found. @exception SecurityException if a security manager exists and its checkPermission method doesn't allow specifying a stream handler. @see java.net.URL#URL(java.lang.String java.lang.String int java.lang.String) @see java.net.URLStreamHandler @see java.net.URLStreamHandler#parseURL(java.net.URL java.lang.String int int)
Class URL, String getHost()

Returns the host name of this URL if applicable. For "file" protocol this is an empty string. @return the host name of this URL.
Class URL, String getProtocol()

Returns the protocol name of this URL. @return the protocol of this URL.
Class URL, void set(String, String, int, String, String)

Sets the fields of the URL. This is not a public method so that only URLStreamHandlers can modify URL fields. URLs are otherwise constant. @param protocol the name of the protocol to use @param host the host name to connecto toof the host @param port the protocol port to connectnumber on tothe host @param file the specified file name on thatthe host @param ref the internal reference in the URL

Class URLClassLoader

This class loader is used to load classes and resources from a search path of URLs referring to both JAR files and directories. Any URL that ends with a '/' is assumed to refer to a directory. Otherwise the URL is assumed to refer to a JAR file which will be opened as needed.

The AccessControlContext of the thread that created the instance of URLClassLoader will be used when subsequently loading classes and resources.

The classes that are loaded are by default granted permission only to access the URLs specified when the URLClassLoader was created. @author David Connelly @version 1.66 0670 03/2109/00 @since JDK11.2

Class URLClassLoader, Package definePackage(String, Manifest, URL)

Defines a new package by name in this ClassLoader. The attributes contained in the specified Manifest will be used to obtain package version and sealing information. For sealed packages the additional URL specifies the code source URL from which the package was loaded. @param name the package name @param man the Manifest containing package version and sealing information @param url the code source url for the package or null if none @exception IllegalArgumentException if the package name duplicates an existing package either in this class loader or one of its ancestors @return the newly defined Package object
Class URLClassLoader, URL findResource(String)

Finds the resource with the specified name on the URL search path. Returns@param name the name of the resource @return a URL for the resource or null if the resource could not be found. @param name the name of the resource
Class URLClassLoader, URL[] getURLs()

Returns the search path of URLs for loading classes and resources. This includes the original list of URLs specified to the constructor along with any URLs subsequently appended by the addURL() method. @return the search path of URLs for loading classes and resources.

Class URLConnection

The abstract class URLConnection is the superclass of all classes that represent a communications link between the application and a URL. Instances of this class can be used both to read from and to write to the resource referenced by the URL. In general creating a connection to a URL is a multistep process:

openConnection() connect()
Manipulate parameters that affect the connection to the remote resource. Interact with the resource; query header fields and contents.
---------------------------->
time
  1. The connection object is created by invoking the openConnection method on a URL.
  2. The setup parameters and general request properties are manipulated.
  3. The actual connection to the remote object is made using the connect method.
  4. The remote object becomes available. The header fields and the contents of the remote object can be accessed.

The setup parameters are modified using the following methods:

and the general request properties are modified using the method:

Default values for the AllowUserInteraction and UseCaches parameters can be set using the methods setDefaultAllowUserInteraction and setDefaultUseCaches. Default values for general request properties can be set using the setDefaultRequestProperty method.

Each of the above set methods has a corresponding get method to retrieve the value of the parameter or general request property. The specific parameters and general request properties that are applicable are protocol specific.

The following methods are used to access the header fields and the contents after the connection is made to the remote object:

Certain header fields are accessed frequently. The methods:

provide convenient access to these fields. The getContentType method is used by the getContent method to determine the type of the remote object; subclasses may find it convenient to override the getContentType method.

In the common case all of the pre-connection parameters and general request properties can be ignored: the pre-connection parameters and request properties default to sensible values. For most clients of this interface there are only two interesting methods: getInputStream and getObject which are mirrored in the URL class by convenience methods.

More information on the request properties and header fields of an http connection can be found at:

 http://www.w3ietf.org/hypertext/WWW/Protocols/HTTP1.0rfc/draft-ietf-http-specrfc2068.htmltxt 
Note about fileNameMap: In versions prior to JDK 1.1.6 field fileNameMap of URLConnection was public. In JDK 1.1.6 and later fileNameMap is private; accessor and mutator methods getFileNameMap and setFileNameMap are added to access it. This change is also described on the JDK Compatibility page. @author James Gosling @version 1.60 0474 02/2202/9900 @see java.net.URL#openConnection() @see java.net.URLConnection#connect() @see java.net.URLConnection#getContent() @see java.net.URLConnection#getContentEncoding() @see java.net.URLConnection#getContentLength() @see java.net.URLConnection#getContentType() @see java.net.URLConnection#getDate() @see java.net.URLConnection#getExpiration() @see java.net.URLConnection#getHeaderField(int) @see java.net.URLConnection#getHeaderField(java.lang.String) @see java.net.URLConnection#getInputStream() @see java.net.URLConnection#getLastModified() @see java.net.URLConnection#getOutputStream() @see java.net.URLConnection#setAllowUserInteraction(boolean) @see java.net.URLConnection#setDefaultRequestProperty(java.lang.String java.lang.String) @see java.net.URLConnection#setDefaultUseCaches(boolean) @see java.net.URLConnection#setDoInput(boolean) @see java.net.URLConnection#setDoOutput(boolean) @see java.net.URLConnection#setIfModifiedSince(long) @see java.net.URLConnection#setRequestProperty(java.lang.String java.lang.String) @see java.net.URLConnection#setUseCaches(boolean) @since JDK1.0
Class URLConnection, boolean getAllowUserInteraction()

Returns the value of the allowUserInteraction field for this object. @return the value of the allowUserInteraction field for this object. @see java.net.URLConnection#allowUserInteractionsetAllowUserInteraction(boolean)
Class URLConnection, boolean getDefaultAllowUserInteraction()

Returns the default value of the allowUserInteraction field.

Ths default is "sticky" being a part of the static state of all URLConnections. This flag applies to the next and all following URLConnections that are created. @return the default value of the allowUserInteraction field. @see java.net.URLConnection#allowUserInteractionsetDefaultAllowUserInteraction(boolean)

Class URLConnection, String getDefaultRequestProperty(String)

Returns the value of the default request property. Default request properties are set for every connection. @param key the keyword by which the request is known (e.g. "accept"). @return the value of the default request property for the specified key. @see java.net.URLConnection#getRequestProperty(java.lang.String) @deprecated The instance specific getRequestProperty method should be used after an appropriate instance of URLConnection is obtained. @see #setDefaultRequestProperty(java.lang.String java.lang.String)
Class URLConnection, boolean getDefaultUseCaches()

Returns the default value of a URLConnection's useCaches flag.

Ths default is "sticky" being a part of the static state of all URLConnections. This flag applies to the next and all following URLConnections that are created. @return the default value of a URLConnection's useCaches flag. @see java.net.URLConnection#useCachessetDefaultUseCaches(boolean)

Class URLConnection, boolean getDoInput()

Returns the value of this URLConnection's doInput flag. @return the value of this URLConnection's doInput flag. @see java.net.URLConnection#doInputsetDoInput(boolean)
Class URLConnection, boolean getDoOutput()

Returns the value of this URLConnection's doOutput flag. @return the value of this URLConnection's doOutput flag. @see java.net.URLConnection#doOutputsetDoOutput(boolean)
Class URLConnection, FileNameMap getFileNameMap()

ReturnsLoads filename map (a mimetable) from a data file. It will first try to load the FileNameMapuser-specific table defined by "content.types.user.table" property. If that fails it tries to load the default built-in table at lib/content-types.properties under java home. @returnsreturn the FileNameMap @since JDK11.2 @see #setFileNameMap(java.net.FileNameMap)
Class URLConnection, long getIfModifiedSince()

Returns the value of this object's ifModifiedSince field. @return the value of this object's ifModifiedSince field. @see java.net.URLConnection#ifModifiedSincesetIfModifiedSince(long)
Class URLConnection, String getRequestProperty(String)

Returns the value of the named general request property for this connection. @param key the keyword by which the request is known (e.g. "accept"). @return the value of the named general request property for this connection. @see #setRequestProperty(java.lang.String java.lang.String)
Class URLConnection, boolean getUseCaches()

Returns the value of this URLConnection's useCaches field. @return the value of this URLConnection's useCaches field. @see java.net.URLConnection#useCachessetUseCaches(boolean)
Class URLConnection, void setAllowUserInteraction(boolean)

Set the value of the allowUserInteraction field of this URLConnection. @param allowuserinteraction the new value. @see java.net.URLConnection#allowUserInteractiongetAllowUserInteraction()
Class URLConnection, void setDefaultAllowUserInteraction(boolean)

Sets the default value of the allowUserInteraction field for all future URLConnection objects to the specified value. @param defaultallowuserinteraction the new value. @see java.net.URLConnection#allowUserInteractiongetDefaultAllowUserInteraction()
Class URLConnection, void setDefaultRequestProperty(String, String)

Sets the default value of a general request property. When a URLConnection is created it is initialized with these properties. @param key the keyword by which the request is known (e.g. "accept"). @param value the value associated with the key. @see java.net.URLConnection#setRequestProperty(java.lang.String java.lang.String) @deprecated The instance specific setRequestProperty method should be used after an appropriate instance of URLConnection is obtained. @see #getDefaultRequestProperty(java.lang.String)
Class URLConnection, void setDefaultUseCaches(boolean)

Sets the default value of the useCaches field to the specified value. @param defaultusecaches the new value. @see java.net.URLConnection#useCachesgetDefaultUseCaches()
Class URLConnection, void setDoInput(boolean)

Sets the value of the doInput field for this URLConnection to the specified value.

A URL connection can be used for input and/or output. Set the DoInput flag to true if you intend to use the URL connection for input false if not. The default is true unless DoOutput is explicitly set to true in which case DoInput defaults to false. @param valuedoinput the new value. @see java.net.URLConnection#doInput @see #getDoInput()

Class URLConnection, void setDoOutput(boolean)

Sets the value of the doOutput field for this URLConnection to the specified value.

A URL connection can be used for input and/or output. Set the DoOutput flag to true if you intend to use the URL connection for output false if not. The default is false. @param valuedooutput the new value. @see java.net.URLConnection#doOutputgetDoOutput()

Class URLConnection, void setFileNameMap(FileNameMap)

Sets the FileNameMap.

If there is a security manager this method first calls the security manager's checkSetFactory method to ensure the operation is allowed. This could result in a SecurityException. @param map the FileNameMap to be set @exception SecurityException if a security manager exists and its checkSetFactory method doesn't allow the operation. @see SecurityManager#checkSetFactory @see #getFileNameMap() @since JDK11.2

Class URLConnection, void setIfModifiedSince(long)

Sets the value of the ifModifiedSince field of this URLConnection to the specified value. @param valueifmodifiedsince the new value. @see java.net.URLConnection#ifModifiedSincegetIfModifiedSince()
Class URLConnection, void setRequestProperty(String, String)

Sets the general request property. If a property with the key already exists overwrite its value with the new value.

NOTE: HTTP requires all request properties which can legally have multiple instances with the same key to use a comma-seperated list syntax which enables multiple properties to be appended into a single property. @param key the keyword by which the request is known (e.g. "accept"). @param value the value associated with it. @see #getRequestProperty(java.lang.String)

Class URLConnection, void setUseCaches(boolean)

Sets the value of the useCaches field of this URLConnection to the specified value.

Some protocols do caching of documents. Occasionally it is important to be able to "tunnel through" and ignore the caches (e.g. the "reload" button in a browser). If the UseCaches flag on a connection is true the connection is allowed to use whatever caches it can. If false caches are to be ignored. The default value comes from DefaultUseCaches which defaults to true. @param usecaches a boolean indicating whether or not to allow caching @see java.net.URLConnection#useCachesgetUseCaches()


Class URLDecoder

The class contains a utility method for converting from a MIME format called "x-www-form-urlencoded" to a String

To convert to a String each character is examined in turn:

@author Mark Chamness @author Michael McCloskey @version 1.2 069 02/2902/9800 @since JDK11.2

Class URLEncoder

The class contains a utility method for converting a String into a MIME format called "x-www-form-urlencoded" format.

To convert a String each character is examined in turn:

@author Herb Jellinek @version 1.15 0618 02/2902/9800 @since JDK1.0

Class URLStreamHandler

The abstract class URLStreamHandler is the common superclass for all stream protocol handlers. A stream protocol handler knows how to make a connection for a particular protocol type such as http ftp or gopher.

In most cases an instance of a URLStreamHandler subclass is not created directly by an application. Rather the first time a protocol name is encountered when constructing a URL the appropriate stream protocol handler is automatically loaded. @author James Gosling @version 1.26 0741 02/0702/9800 @see java.net.URL#URL(java.lang.String java.lang.String int java.lang.String) @since JDK1.0


Class URLStreamHandlerFactory

This interface defines a factory for URL stream protocol handlers.

It is used by the URL class to create a URLStreamHandler for a specific protocol. @author Arthur van Hoff @version 1.12 0915 02/2102/9800 @see java.net.URL @see java.net.URLStreamHandler @since JDK1.0

Class URLStreamHandlerFactory, URLStreamHandler createURLStreamHandler(String)

Creates a new URLStreamHandler instance with the specified protocol. @param protocol the protocol ("ftp" "http" "nntp" etc.). @return a URLStreamHandler for the specific protocol. @see java.ionet.URLStreamHandler

Class UnknownHostException

Thrown to indicate that the IP address of a host could not be determined. @author Jonathan Payne @version 1.10 0912 02/2102/9800 @since JDK1.0

Class UnknownServiceException

Thrown to indicate that an unknown service exception has occurred. Either the MIME type returned by a URL connection does not make sense or the application is attempting to write to a read-only URL connection. @author unascribed @version 1.9 0911 02/2102/9800 @since JDK1.0