站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.0.5 API 文档英文版

ByteArrayResource (Spring Framework API 2.0) - Spring Framework 2.0.5 API 文档英文版

The Spring Framework

org.springframework.core.io
Class ByteArrayResource

java.lang.Object
  extended by org.springframework.core.io.AbstractResource
      extended by org.springframework.core.io.ByteArrayResource
All Implemented Interfaces:
InputStreamSource, Resource

public class ByteArrayResource
extends AbstractResource

Resource implementation for a given byte array. Creates a ByteArrayInputStreams 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.

Since:
1.2.3
Author:
Juergen Hoeller
See Also:
ByteArrayInputStream, InputStreamResource, MimeMessageHelper.addAttachment(String, InputStreamSource)

Constructor Summary
ByteArrayResource(byte[] byteArray)
          Create a new ByteArrayResource.
ByteArrayResource(byte[] byteArray, String description)
          Create a new ByteArrayResource.
 
Method Summary
 boolean equals(Object obj)
          This implementation compares the underlying byte array.
 boolean exists()
          This implementation always returns true.
 byte[] getByteArray()
          Return the underlying byte array.
 String getDescription()
          This implementation returns the passed-in description, if any.
 InputStream getInputStream()
          This implementation returns a ByteArrayInputStream for the underlying byte array.
 int hashCode()
          This implementation returns the hash code based on the underlying byte array.
 
Methods inherited from class org.springframework.core.io.AbstractResource
createRelative, getFile, getFilename, getURL, isOpen, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteArrayResource

public ByteArrayResource(byte[] byteArray)
Create a new ByteArrayResource.

Parameters:
byteArray - the byte array to wrap

ByteArrayResource

public ByteArrayResource(byte[] byteArray,
                         String description)
Create a new ByteArrayResource.

Parameters:
byteArray - the byte array to wrap
description - where the byte array comes from
Method Detail

getByteArray

public final byte[] getByteArray()
Return the underlying byte array.


exists

public boolean exists()
This implementation always returns true.

Specified by:
exists in interface Resource
Overrides:
exists in class AbstractResource

getInputStream

public InputStream getInputStream()
                           throws IOException
This implementation returns a ByteArrayInputStream for the underlying byte array.

Throws:
IOException - if the stream could not be opened
See Also:
ByteArrayInputStream

getDescription

public String getDescription()
This implementation returns the passed-in description, if any.

Specified by:
getDescription in interface Resource
Specified by:
getDescription in class AbstractResource
See Also:
Resource.getDescription(), AbstractResource.toString(), AbstractResource.equals(Object), AbstractResource.hashCode()

equals

public boolean equals(Object obj)
This implementation compares the underlying byte array.

Overrides:
equals in class AbstractResource
See Also:
Arrays.equals(byte[], byte[])

hashCode

public int hashCode()
This implementation returns the hash code based on the underlying byte array.

Overrides:
hashCode in class AbstractResource
See Also:
AbstractResource.getDescription()

The Spring Framework

Copyright © 2002-2007 The Spring Framework.