public class Photo extends ImageProperty
Defines a photo, such as the person's portrait.
Code sample (creating)
VCard vcard = new VCard(); //URL Photo photo = new Photo("http://www.mywebsite.com/my-photo.jpg", ImageType.JPEG); vcard.addPhoto(photo); //binary data byte data[] = ... photo = new Photo(data, ImageType.JPEG); vcard.addPhoto(photo);
Code sample (retrieving)
VCard vcard = ... for (Photo photo : vcard.getPhotos()) { PhotoType contentType = photo.getContentType(); //e.g. "image/jpeg" String url = photo.getUrl(); if (url != null) { //property value is a URL continue; } byte[] data = photo.getData(); if (data != null) { //property value is binary data continue; } }
Property name: PHOTO
Supported versions: 2.1, 3.0, 4.0
contentType, data, url
group, parameters
Constructor and Description |
---|
Photo(byte[] data,
ImageType type)
Creates a photo property.
|
Photo(InputStream in,
ImageType type)
Creates a photo property.
|
Photo(Path file,
ImageType type)
Creates a photo property.
|
Photo(Photo original)
Copy constructor.
|
Photo(String url,
ImageType type)
Creates a photo property.
|
Modifier and Type | Method and Description |
---|---|
Photo |
copy()
Creates a copy of this property object.
|
_validate, equals, getAltId, getContentType, getData, getPids, getPref, getType, getUrl, hashCode, setAltId, setContentType, setData, setPref, setType, setUrl, toStringValues
addParameter, compareTo, getGroup, getParameter, getParameters, getParameters, getSupportedVersions, isSupportedBy, removeParameter, setGroup, setParameter, setParameters, toString, validate
public Photo(String url, ImageType type)
url
- the URL to the phototype
- the content type (e.g. JPEG)public Photo(byte[] data, ImageType type)
data
- the binary data of the phototype
- the content type (e.g. JPEG)public Photo(InputStream in, ImageType type) throws IOException
in
- an input stream to the binary data (will be closed)type
- the content type (e.g. JPEG)IOException
- if there's a problem reading from the input streampublic Photo(Path file, ImageType type) throws IOException
file
- the image filetype
- the content type (e.g. JPEG)IOException
- if there's a problem reading from the filepublic Photo copy()
VCardProperty
Creates a copy of this property object.
The default implementation of this method uses reflection to look for a copy constructor. Child classes SHOULD override this method to avoid the performance overhead involved in using reflection.
The child class's copy constructor, if present, MUST invoke the
VCardProperty.VCardProperty(VCardProperty)
super constructor to ensure that
the group name and parameters are also copied.
This method MUST be overridden by the child class if the child class does
not have a copy constructor. Otherwise, an
UnsupportedOperationException
will be thrown when an attempt is
made to copy the property (such as in the VCard
class's copy constructor
).
copy
in class VCardProperty
Copyright © 2012–2023 Michael Angstadt. All rights reserved.