Debian Codegraph @

demo/src/main/java/ODCHTest.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.io.*;
12 import jakarta.activation.*;
13
14 public class ODCHTest {
15 private FileDataSource fds = null;
16 private DataHandler dh = null;
17 private DataContentHandlerFactory dchf = null;
18 private String str;
19 /**
20 * main function
21 */
22 public static void main(String args[]) {
23 ODCHTest test = new ODCHTest();
24
25 if(args.length != 0) {
26 System.out.println("usage: ODCHTest");
27 System.exit(1);
28 }
29
30 // first let's get a DataSource
31
32
33 test.doit();
34 }
35
36 private void doit() {
37 ActivationDataFlavor xfer_flavors[];
38 Object content = null;
39
40 str = new String("This is a test");
41
42 // now let's create a DataHandler
43 dh = new DataHandler(str, "text/plain");
44 System.out.println("ODCHTest: DataHandler created with str & text/plain");
45
46 // now lets set a DataContentHandlerFactory
47 dchf = new SimpleDCF("text/plain:PlainDCH\n");
48 System.out.println("ODCHTest: Simple dchf created");
49
50 // now let's set the dchf in the dh
51 dh.setDataContentHandlerFactory(dchf);
52 System.out.println("ODCHTest: DataContentHandlerFactory set in DataHandler");
53
54 // get the dataflavors
55 xfer_flavors = dh.getTransferDataFlavors();
56 System.out.println("ODCHTest: dh.getTransferDF returned " +
57 xfer_flavors.length + " data flavors.");
58
59 // get the content:
60 try {
61 content = dh.getContent();
62 } catch (Exception e) { e.printStackTrace(); }
63
64 if(content == null)
65 System.out.println("ODCHTest: no content to be had!!!");
66 else {
67 System.out.println("ODCHTest: got content of the following type: " +
68 content.getClass().getName());
69 if(content == str)
70 System.out.println("get content works");
71
72 }
73 }
74
75 }