jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/soap/JpegDataContentHandler.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
45 extends Component |
45 extends Component |
46 implements DataContentHandler { |
46 implements DataContentHandler { |
47 public static final String STR_SRC = "java.awt.Image"; |
47 public static final String STR_SRC = "java.awt.Image"; |
48 |
48 |
49 /** |
49 /** |
50 * return the DataFlavors for this <code>DataContentHandler</code> |
50 * Return the DataFlavors for this <code>DataContentHandler</code> |
51 * @return The DataFlavors. |
51 * @return The DataFlavors. |
52 */ |
52 */ |
|
53 @Override |
53 public DataFlavor[] getTransferDataFlavors() { // throws Exception; |
54 public DataFlavor[] getTransferDataFlavors() { // throws Exception; |
54 DataFlavor flavors[] = new DataFlavor[1]; |
55 DataFlavor flavors[] = new DataFlavor[1]; |
55 |
56 |
56 try { |
57 try { |
57 flavors[0] = |
58 flavors[0] = |
65 |
66 |
66 return flavors; |
67 return flavors; |
67 } |
68 } |
68 |
69 |
69 /** |
70 /** |
70 * return the Transfer Data of type DataFlavor from InputStream |
71 * Return the Transfer Data of type DataFlavor from InputStream |
71 * @param df The DataFlavor. |
72 * @param df The DataFlavor |
72 * @param ins The InputStream corresponding to the data. |
73 * @param ds The DataSource |
73 * @return The constructed Object. |
74 * @return The constructed Object. |
74 */ |
75 */ |
|
76 @Override |
75 public Object getTransferData(DataFlavor df, DataSource ds) { |
77 public Object getTransferData(DataFlavor df, DataSource ds) { |
76 |
78 |
77 // this is sort of hacky, but will work for the |
79 // this is sort of hacky, but will work for the |
78 // sake of testing... |
80 // sake of testing... |
79 if (df.getMimeType().startsWith("image/jpeg")) { |
81 if (df.getMimeType().startsWith("image/jpeg")) { |
96 } |
98 } |
97 |
99 |
98 /** |
100 /** |
99 * |
101 * |
100 */ |
102 */ |
|
103 @Override |
101 public Object getContent(DataSource ds) { // throws Exception; |
104 public Object getContent(DataSource ds) { // throws Exception; |
102 InputStream inputStream = null; |
105 InputStream inputStream = null; |
103 BufferedImage jpegLoadImage = null; |
106 BufferedImage jpegLoadImage = null; |
104 |
107 |
105 try { |
108 try { |
107 jpegLoadImage = ImageIO.read(inputStream); |
110 jpegLoadImage = ImageIO.read(inputStream); |
108 |
111 |
109 } catch (Exception e) { |
112 } catch (Exception e) { |
110 } |
113 } |
111 |
114 |
112 return (Image) jpegLoadImage; |
115 return jpegLoadImage; |
113 } |
116 } |
114 |
117 |
115 /** |
118 /** |
116 * construct an object from a byte stream |
119 * Construct an object from a byte stream |
117 * (similar semantically to previous method, we are deciding |
120 * (similar semantically to previous method, we are deciding |
118 * which one to support) |
121 * which one to support) |
|
122 * @param obj object to write |
|
123 * @param mimeType requested MIME type of the resulting byte stream |
|
124 * @param os OutputStream |
119 */ |
125 */ |
|
126 @Override |
120 public void writeTo(Object obj, String mimeType, OutputStream os) |
127 public void writeTo(Object obj, String mimeType, OutputStream os) |
121 throws IOException { |
128 throws IOException { |
122 if (!mimeType.equals("image/jpeg")) |
129 if (!mimeType.equals("image/jpeg")) |
123 throw new IOException( |
130 throw new IOException( |
124 "Invalid content type \"" |
131 "Invalid content type \"" |