Skip to content
Related Articles

Related Articles Class in Java

View Discussion
Improve Article
Save Article
  • Last Updated : 29 Jun, 2021
View Discussion
Improve Article
Save Article

CacheRequest class is used in java whenever there is a need for, storage of resources in ResponseCache. More precisely instances of this class provide an advantage for the OutputStream object to store resource data into the cache, in fact, This OutputStream object is invoked by protocol handlers. CacheRequest class belongs to package along with other classes such as Authenticator, CacheResponse, ServerSocket, SocketAddress, and many more.

Authenticator Inet6Address ServerSocket
CacheRequest InetAddress Socket
CacheResponse InetSocketAddress SocketAddress
ContentHandler InterfaceAddress SocketImpl
CookieHandler JarURLConnection  SocketPermission
CookieManager MulticastSocket URI
DatagramPacket NetPermission URL

Java.Net Package is a container for powerful classes that provides networking infrastructure for java. Now, dwelling onto the two methods present in this class which are as follows:

  1. abort() Method
  2. getBody() Method

Method 1: abort() Method

It allows cache store operation to be interrupted and abandoned. Hence, it is used for aborting cache response, whenever an IOException occurs current cache operation is aborted. Hence, in simpler words, it aborts the attempt to cache the response.

Syntax : 

public abstract void abort()

Exceptions: It throws IOException if any input-output error is encountered

Method 2: getBody() Method 

It simply returns an InputStream from which the response body can be accessed.


public abstract OutputStream getBody ()

Return Type: OutputStream for which the response should be initiated.

Exceptions: It throws IOException if any input-output error is encountered




// Java Program to illustrate CacheRequest Class
// package
// Importing IOException class from
// java,io package
// Importing all classes from package package
// to create an applet to run on anetwork
// Importing List and Map classes from
// java.util package
import java.util.List;
import java.util.Map;
// Main class
public class GFG {
    // Main driver method
    public static void main(String args[]) throws Exception
        // Passing the string uri
        String ur = "";
        // Now, calling the constructor of the URI class
        URI ur1 = new URI(ur);
        // Passing the url
        URL url = new URL(
        // Now, calling the constructor of the URLConnection
        URLConnection uc = url.openConnection();
        ResponseCache responseCache = new ResponseCache() {
            // Calling the abstract methods
            public CacheResponse get(
                URI ur, String reqMethod,
                Map<String, List<String> > rqstHeaders)
                throws IOException
                return null;
            public CacheRequest put(URI ur,
                                    URLConnection conn)
                throws IOException
                return null;
        // Display message only
            "The put() method has been initiated and called Successfully!");
        // The put() method returns the
        // CacheRequest for recording
        System.out.println("The put() method returns: "
                           + responseCache.put(ur1, uc));


The put() method has been initiated and called Successfully!
The put() method returns: null

Finally, we are over with the sheer technical stuff related to this class lets finally do have a peek over the application in the real-world of this class. This class is indirectly used in the daily life of a software person as it provides classes for implementing networking applications in wide versatility. 

  • Web
  • File Transfer
  • Electronic Mail.
  • Remote terminal access


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!