类 ByteArrayResource
java.lang.Object
cn.taketoday.core.io.AbstractResource
cn.taketoday.core.io.ByteArrayResource
- 所有已实现的接口:
InputStreamSource,Resource
Resource implementation for a given byte array.
Creates a ByteArrayInputStream for the given byte array.
Useful for loading content from any given byte array,
without having to resort to a single-use InputStreamResource.
Particularly useful for creating mail attachments from local content,
where JavaMail needs to be able to read the stream multiple times.
- 从以下版本开始:
- 3.0
- 作者:
- Juergen Hoeller, Sam Brannen, TODAY 2021/3/7 11:16
- 另请参阅:
-
字段概要
字段从接口继承的字段 cn.taketoday.core.io.Resource
EMPTY_ARRAY -
构造器概要
构造器构造器说明ByteArrayResource(byte[] byteArray) Create a newByteArrayResource.ByteArrayResource(byte[] byteArray, String description) Create a newByteArrayResourcewith a description. -
方法概要
修饰符和类型方法说明longThis implementation returns the length of the underlying byte array.booleanThis implementation compares the underlying byte array.booleanexists()This implementation always returnstrue.final byte[]Return the underlying byte array.byte[]Return the contents of this resource as a byte array.getContentAsString(Charset charset) Returns the contents of this resource as a string, using the specified charset.This implementation returns a ByteArrayInputStream for the underlying byte array.inthashCode()This implementation returns the hash code based on the underlying byte array.booleanThis implementation always returnstruefor a resource thatexists(revised as of 5.1).toString()This implementation returns a description that includes the passed-indescription, if any.从类继承的方法 cn.taketoday.core.io.AbstractResource
createRelative, customizeConnection, customizeConnection, getFile, getFileForLastModifiedCheck, getName, getURI, getURL, isDirectory, isFile, isOpen, lastModified, list, list从接口继承的方法 cn.taketoday.core.io.InputStreamSource
getReader, getReader, readableChannel
-
字段详细资料
-
byteArray
private final byte[] byteArray -
description
-
-
构造器详细资料
-
ByteArrayResource
public ByteArrayResource(byte[] byteArray) Create a newByteArrayResource.- 参数:
byteArray- the byte array to wrap
-
ByteArrayResource
Create a newByteArrayResourcewith a description.- 参数:
byteArray- the byte array to wrapdescription- where the byte array comes from
-
-
方法详细资料
-
getByteArray
public final byte[] getByteArray()Return the underlying byte array. -
isReadable
public boolean isReadable()从类复制的说明:AbstractResourceThis implementation always returnstruefor a resource thatexists(revised as of 5.1).- 指定者:
isReadable在接口中Resource- 覆盖:
isReadable在类中AbstractResource- 另请参阅:
-
exists
public boolean exists()This implementation always returnstrue.- 指定者:
exists在接口中Resource- 覆盖:
exists在类中AbstractResource
-
contentLength
public long contentLength()This implementation returns the length of the underlying byte array.- 指定者:
contentLength在接口中Resource- 覆盖:
contentLength在类中AbstractResource- 另请参阅:
-
getInputStream
This implementation returns a ByteArrayInputStream for the underlying byte array.- 返回:
- the input stream for the underlying resource (must not be
null) - 抛出:
FileNotFoundException- if the underlying resource does not existIOException- if the content stream could not be opened- 另请参阅:
-
getContentAsByteArray
从接口复制的说明:ResourceReturn the contents of this resource as a byte array.- 返回:
- the contents of this resource as byte array
- 抛出:
FileNotFoundException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file systemIOException- in case of general resolution/reading failures
-
getContentAsString
从接口复制的说明:ResourceReturns the contents of this resource as a string, using the specified charset.- 参数:
charset- the charset to use for decoding- 返回:
- the contents of this resource as a
String - 抛出:
FileNotFoundException- if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file systemIOException- in case of general resolution/reading failures
-
toString
This implementation returns a description that includes the passed-indescription, if any.- 指定者:
toString在接口中Resource- 覆盖:
toString在类中AbstractResource- 另请参阅:
-
equals
This implementation compares the underlying byte array.- 覆盖:
equals在类中AbstractResource- 另请参阅:
-
hashCode
public int hashCode()This implementation returns the hash code based on the underlying byte array.- 覆盖:
hashCode在类中AbstractResource
-