- Distributed Computing in Java 9
- Raja Malleswara Rao Pattamsetti
- 371字
- 2021-07-02 21:02:32
URL (base URL and relative URL)
Every constructor looks for the base URL, and if its value is null, then it considers the relative URL as the absolute URL. Also, you can use a relative URL for creating URL objects for named anchors. There are other URL constructors available in which you can pass all the four preceding components given separately. If a URL contains any special character, then such URLs can get encoded first so that the address gets validated as the legal address; then, they are passed to the URL constructor (for example, the space character is encoded as %20).
While constructing a URL object, if the URL string passed to the constructor is null or is an unknown protocol, then it throws MalformedURLException. Therefore, one should handle this kind of exception without fail while building the URL.
The URL object helps the user to either connect, access, or download any of the URL-related pages containing information from that respective web server. To do so, the URL object has methods such as openStream(), getContent(), and openConnection(). The openStream() method returns a java.io.InputStream that is capable of reading the data contents directly. When openConnection() is called on a URL object, it provides URLConnection in return. URLConnection can be used to query the header information of the data to get the length of the data object, the data type it contains, the encoding of data, and so on.
The getContent() method downloads the data object and returns the data-containing object. This method has a content handler that can convert data into a Java object. When we invoke the getContent() method of the URLConnection or URL object, it queries ContentHandlerFactory for ContentHandler to request the information from the requestor. The responsibility of ContentHandlerFactory is to validate MIMEType along with the encoding of DataObject to supply the ContentHandler belonging to that MIMEType.
The returned ContentHandler is then used to get an object that represents the data by invoking its getContent() method with URLConnection. ContentHandler reads raw data provided through InputStream of URLConnection, then it formats it to the required object representations and returns the object to the caller.
- Mastering Entity Framework Core 2.0
- Java高并發核心編程(卷2):多線程、鎖、JMM、JUC、高并發設計模式
- Instant Apache Stanbol
- C語言程序設計同步訓練與上機指導(第三版)
- Learning SciPy for Numerical and Scientific Computing(Second Edition)
- Tableau 10 Bootcamp
- 用戶體驗可視化指南
- 用案例學Java Web整合開發
- 持續集成與持續交付實戰:用Jenkins、Travis CI和CircleCI構建和發布大規模高質量軟件
- Microsoft 365 Certified Fundamentals MS-900 Exam Guide
- Illustrator CS6設計與應用任務教程
- MyBatis 3源碼深度解析
- 分布式架構原理與實踐
- Visual C++開發寶典
- Visual Basic程序設計基礎