Announcement Announcement Module
Collapse
No announcement yet.
Load a byte array property from a file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Load a byte array property from a file

    I'm trying to filgure out how to take a simple bean that contains a byte[] property and load it using an image file.

    Here's my bean:

    Code:
    public class BulletinImageImpl implements BulletinImage
    {
        private byte[] image;
    
        public byte[] getImage(String bulletinNumber, String page)
        {
            return image;
        }
    
        public void setImage(byte[] image)
        {
            this.image = image;
        }
    }
    and my xml file:
    Code:
      <bean id="bulletinImageBusiness" class="BulletinImageImpl">
        <property name="image" value="file:i/inyourfacemace.jpg"/>
      </bean>
    My image is in the "i" folder, not in WEB-INF. It doesn't load the file, just plugs in the bytes from the string.

    Anybody know how I can make it pull the bytes out of the file?

  • #2
    I dont think there is a byte factory, so you might need to write one yourself (check out http://www.springframework.org/docs/...toryBean.html).

    Another option would be to modify your code so it expects a Resource as Spring knows how to convert the file:// reference into a Resource.

    Check out http://www.springframework.org/docs/.../Resource.html

    Comment


    • #3
      Another option would be if you change the sig of setImage() so, it accepts an InputStream. Then the resource in your file system will be found automatically by Spring (if it exists, o'course), and to get bytes[] from an InputStream is 1 line of code

      Comment

      Working...
      X