public class BinaryContentImpl extends Object implements BinaryContent
BinaryContent
interface.Constructor and Description |
---|
BinaryContentImpl(InputStream inputStream)
Instantiates a new product resource.
|
BinaryContentImpl(InputStream inputStream,
MimeType mimeType)
Instantiates a new product resource.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
getByteArray()
Convenience method to attempt to read the contents of the
InputStream into a
byte array. |
InputStream |
getInputStream()
Gets the input stream.
|
MimeType |
getMimeType() |
String |
getMimeTypeValue()
|
long |
getSize()
Get the size if known.
|
void |
setSize(long size)
Sets the size in bytes of the binary content.
|
String |
toString()
String representation of this
BinaryContentImpl . |
public BinaryContentImpl(InputStream inputStream, MimeType mimeType)
inputStream
- the input streammimeType
- the mime type for the resourcepublic BinaryContentImpl(InputStream inputStream)
inputStream
- the input streampublic InputStream getInputStream()
BinaryContent
Note that the binary from the InputStream
can only be accessed once. Thus, when
you call BinaryContent.getInputStream()
and retrieve the InputStream
object, it can
only be used once to extract the content. If it is necessary that the bytes of the
InputStream
object are needed again, use the BinaryContent.getByteArray()
method instead.
getInputStream
in interface BinaryContent
public MimeType getMimeType()
getMimeType
in interface BinaryContent
InputStream
public String getMimeTypeValue()
BinaryContent
getMimeTypeValue
in interface BinaryContent
String
public String toString()
BinaryContentImpl
.public long getSize()
BinaryContent
getSize
in interface BinaryContent
long
, -1 if unknownpublic void setSize(long size)
size
- public byte[] getByteArray() throws IOException
BinaryContent
InputStream
into a
byte
array.
Note that BinaryContent.getByteArray()
should be idempotent if BinaryContent.getInputStream()
has not
been initially invoked.
getByteArray
in interface BinaryContent
IOException
- if the stream can not be read into the arrayThis work is licensed under a Creative Commons Attribution 4.0 International License.