public class StringToByteArrayConverter extends Object implements com.vaadin.v7.data.util.converter.Converter<String,byte[]>
String
to
a byte[]
and back.Constructor and Description |
---|
StringToByteArrayConverter()
Creates a new
StringToByteArrayConverter with the default
IDataUrlSerializer and automatic MimeType guessing. |
StringToByteArrayConverter(eu.maxschuster.dataurl.IDataUrlSerializer serializer)
Creates a new
StringToByteArrayConverter with the given
IDataUrlSerializer and automatic MimeType guessing. |
StringToByteArrayConverter(eu.maxschuster.dataurl.IDataUrlSerializer serializer,
MimeType mimeType)
|
StringToByteArrayConverter(MimeType mimeType)
Creates a new
StringToByteArrayConverter with the default
IDataUrlSerializer and automatic MimeType guessing. |
Modifier and Type | Method and Description |
---|---|
byte[] |
convertToModel(String value,
Class<? extends byte[]> targetType,
Locale locale) |
String |
convertToPresentation(byte[] value,
Class<? extends String> targetType,
Locale locale) |
Class<byte[]> |
getModelType() |
Class<String> |
getPresentationType() |
protected MimeType |
guessMimeType(byte[] data)
Guesses the
MimeType of the given byte[] contents. |
protected boolean |
matchMimeType(eu.maxschuster.dataurl.DataUrl dataUrl,
MimeType mimeType)
Matches the MIME-Type of the given
DataUrl with the given
MimeType . |
public StringToByteArrayConverter(eu.maxschuster.dataurl.IDataUrlSerializer serializer, MimeType mimeType) throws NullPointerException
serializer
- IDataUrlSerializer
used to extract the binary contents of the
RFC 2397 data url String
. Must not be null
!mimeType
- MimeType
that is used while converting. Must not
be null
!NullPointerException
- If serializer
or mimeType
is
null
public StringToByteArrayConverter(eu.maxschuster.dataurl.IDataUrlSerializer serializer) throws NullPointerException
StringToByteArrayConverter
with the given
IDataUrlSerializer
and automatic MimeType
guessing.serializer
- IDataUrlSerializer
used to extract the binary contents of the
RFC 2397 data url String
. Must not be null
!NullPointerException
- If serializer
is null
public StringToByteArrayConverter(MimeType mimeType) throws NullPointerException
StringToByteArrayConverter
with the default
IDataUrlSerializer
and automatic MimeType
guessing.mimeType
- MimeType
that is used while converting. Must not
be null
!NullPointerException
- If mimeType
is null
public StringToByteArrayConverter()
StringToByteArrayConverter
with the default
IDataUrlSerializer
and automatic MimeType
guessing.public byte[] convertToModel(String value, Class<? extends byte[]> targetType, Locale locale) throws com.vaadin.v7.data.util.converter.Converter.ConversionException
convertToModel
in interface com.vaadin.v7.data.util.converter.Converter<String,byte[]>
com.vaadin.v7.data.util.converter.Converter.ConversionException
public String convertToPresentation(byte[] value, Class<? extends String> targetType, Locale locale) throws com.vaadin.v7.data.util.converter.Converter.ConversionException
convertToPresentation
in interface com.vaadin.v7.data.util.converter.Converter<String,byte[]>
com.vaadin.v7.data.util.converter.Converter.ConversionException
public Class<byte[]> getModelType()
getModelType
in interface com.vaadin.v7.data.util.converter.Converter<String,byte[]>
public Class<String> getPresentationType()
getPresentationType
in interface com.vaadin.v7.data.util.converter.Converter<String,byte[]>
protected MimeType guessMimeType(byte[] data) throws IOException, IllegalArgumentException, NullPointerException
MimeType
of the given byte[]
contents.data
- The image data.MimeType
.IOException
- If something goes wrong with the data stream.IllegalArgumentException
- If the guessing resulted in an
unsupported MIME-Type.NullPointerException
- If the guessing did not find any matching
MIME-Type.URLConnection.guessContentTypeFromStream(InputStream)
Copyright © 2017 Max Schuster. All Rights Reserved.