Debian Codegraph @

src/main/java/ezvcard/property/Photo.java

raw symbols SCIP
1 package ezvcard.property;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.nio.file.Path;
6
7 import ezvcard.parameter.ImageType;
8
9 /*
10 Copyright (c) 2012-2023, Michael Angstadt
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15
16 1. Redistributions of source code must retain the above copyright notice, this
17 list of conditions and the following disclaimer.
18 2. Redistributions in binary form must reproduce the above copyright notice,
19 this list of conditions and the following disclaimer in the documentation
20 and/or other materials provided with the distribution.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 The views and conclusions contained in the software and documentation are those
34 of the authors and should not be interpreted as representing official policies,
35 either expressed or implied, of the FreeBSD Project.
36 */
37
38 /**
39 * <p>
40 * Defines a photo, such as the person's portrait.
41 * </p>
42 *
43 * <p>
44 * <b>Code sample (creating)</b>
45 * </p>
46 *
47 * <pre class="brush:java">
48 * VCard vcard = new VCard();
49 *
50 * //URL
51 * Photo photo = new Photo("http://www.mywebsite.com/my-photo.jpg", ImageType.JPEG);
52 * vcard.addPhoto(photo);
53 *
54 * //binary data
55 * byte data[] = ...
56 * photo = new Photo(data, ImageType.JPEG);
57 * vcard.addPhoto(photo);
58 * </pre>
59 *
60 * <p>
61 * <b>Code sample (retrieving)</b>
62 * </p>
63 *
64 * <pre class="brush:java">
65 * VCard vcard = ...
66 * for (Photo photo : vcard.getPhotos()) {
67 * PhotoType contentType = photo.getContentType(); //e.g. "image/jpeg"
68 *
69 * String url = photo.getUrl();
70 * if (url != null) {
71 * //property value is a URL
72 * continue;
73 * }
74 *
75 * byte[] data = photo.getData();
76 * if (data != null) {
77 * //property value is binary data
78 * continue;
79 * }
80 * }
81 * </pre>
82 *
83 * <p>
84 * <b>Property name:</b> {@code PHOTO}
85 * </p>
86 * <p>
87 * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
88 * </p>
89 * @author Michael Angstadt
90 * @see <a href="http://tools.ietf.org/html/rfc6350#page-30">RFC 6350 p.30</a>
91 * @see <a href="http://tools.ietf.org/html/rfc2426#page-10">RFC 2426 p.10</a>
92 * @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.10</a>
93 */
94 public class Photo extends ImageProperty {
95 /**
96 * Creates a photo property.
97 * @param url the URL to the photo
98 * @param type the content type (e.g. JPEG)
99 */
100 public Photo(String url, ImageType type) {
101 super(url, type);
102 }
103
104 /**
105 * Creates a photo property.
106 * @param data the binary data of the photo
107 * @param type the content type (e.g. JPEG)
108 */
109 public Photo(byte[] data, ImageType type) {
110 super(data, type);
111 }
112
113 /**
114 * Creates a photo property.
115 * @param in an input stream to the binary data (will be closed)
116 * @param type the content type (e.g. JPEG)
117 * @throws IOException if there's a problem reading from the input stream
118 */
119 public Photo(InputStream in, ImageType type) throws IOException {
120 super(in, type);
121 }
122
123 /**
124 * Creates a photo property.
125 * @param file the image file
126 * @param type the content type (e.g. JPEG)
127 * @throws IOException if there's a problem reading from the file
128 */
129 public Photo(Path file, ImageType type) throws IOException {
130 super(file, type);
131 }
132
133 /**
134 * Copy constructor.
135 * @param original the property to make a copy of
136 */
137 public Photo(Photo original) {
138 super(original);
139 }
140
141 @Override
142 public Photo copy() {
143 return new Photo(this);
144 }
145 }