Results 1 to 3 of 3

Thread: Load a byte array property from a file

  1. #1
    Join Date
    Apr 2006
    Posts
    5

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    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

  3. #3
    Join Date
    Dec 2005
    Posts
    269

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •