Debian Codegraph @

demo/src/main/java/DHURL.java

raw
1 /*
2 * Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0, which is available at
6 * http://www.eclipse.org/org/documents/edl-v10.php.
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
10
11 import java.net.*;
12 import java.io.*;
13 import jakarta.activation.*;
14
15 public class DHURL {
16 URL url = null;
17 DataHandler dh = null;
18
19 public static void main(String args[]){
20 DHURL test = new DHURL();
21
22 if(args.length == 0) {
23 System.out.println("usage: DHURL url");
24 System.exit(1);
25 }
26
27 test.setURL(args[0]);
28
29 test.doit();
30
31 }
32
33 public void setURL(String url) {
34
35 try {
36 this.url = new URL(url);
37 } catch(MalformedURLException e) {
38 e.printStackTrace();
39 System.out.println("malformed URL!!!");
40 System.exit(1);
41 }
42
43 }
44
45 public void doit() {
46 System.out.print("Creating DataHandler...");
47 dh = new DataHandler(url);
48 System.out.println("...done.");
49
50 System.out.println("The MimeType of the DH : " +
51 dh.getContentType());
52 try {
53 InputStream is = dh.getInputStream();
54 if(is != null)
55 System.out.println("got an inputstream");
56 } catch(Exception e) {
57 e.printStackTrace();
58 }
59
60
61 }
62
63
64 }