Skip to Content
Java Network Programming, Second Edition
book

Java Network Programming, Second Edition

by Elliotte Rusty Harold
August 2000
Intermediate to advanced
760 pages
21h
English
O'Reilly Media, Inc.
Content preview from Java Network Programming, Second Edition

Configuring the Connection

The URLConnection class has seven protected instance fields that define exactly how the client will make the request to the server. These are:

protected URL     url;
protected boolean doInput = true;
protected boolean doOutput = false;
protected boolean allowUserInteraction = defaultAllowUserInteraction;
protected boolean useCaches = defaultUseCaches;
protected long    ifModifiedSince = 0;
protected boolean connected = false;

For instance, if doOutput is true, then you’ll be able to write data to the server over this URLConnection as well as read data from it. If useCaches is false, the connection will bypass any local caching and download the file from the server afresh.

Since these fields are all protected, their values are accessed and modified via obviously named setter and getter methods:

public URL     
            getURL(  )
public void    setDoInput(boolean doInput)
public boolean getDoInput(  )
public void    
            
            setDoOutput(boolean doOutput)
public boolean getDoOutput(  )
public void    setAllowUserInteraction(boolean allowUserInteraction)
public boolean getAllowUserInteraction(  )
public void    
            
            
            setUseCaches(boolean useCaches)
public boolean getUseCaches(  )
public void    setIfModifiedSince(long ifModifiedSince)
public long    getIfModifiedSince(  )

You can modify these fields only before the URLConnection is connected (that is, before you try to read content or headers from the connection). Most of the methods that set fields throw an IllegalAccessError if they are called while the connection ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Network Programming, 4th Edition

Java Network Programming, 4th Edition

Elliotte Rusty Harold
Java Concurrency, 2/e

Java Concurrency, 2/e

Douglas Schmidt

Publisher Resources

ISBN: 1565928709Supplemental ContentCatalog PageErrata