• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

embedding a flash file in JSP page


I’m embedding a flash file in JSP page and the file is coming from database and every time this is a different file.
Some flash files are of different size. As flash file is not taking default dimension (like an image) in the Browser so I need to specify the dimension (width, height).

How can I fetch the Attributes (width, height) of a flash file so that I can put the dimension dynamically?
  • 3
  • 2
1 Solution
According to this:


you should be able to read the first few bytes of the swf file, and find out the width and height:

SWF File Header      
     Field                Type*      Comment    
     Signature        byte              Signature byte always ‘F’    
     Signature        byte              Signature byte always ‘W’    
     Signature        byte              Signature byte always ‘S’    
     Version           byte         Single byte file version (e.g. 0x04F for SWF 4)    
     FileLength       int            Length of entire file in bytes    
     FrameSize      RECT      Frame size in twips    

where "RECT" is of the format:

     Field        Type                 Comment    
     Nbits       nBits = UB[5]     Bits used for each subsequent field    
     Xmin       SB[nBits]            X minimum position for rectangle in twips    
     Xmax      SB[nBits]            X maximum position for rectangle in twips    
     Ymin            SB[nBits]            Y minimum position for rectangle in twips    
     Ymax      SB[nBits]           Y maximum position for rectangle in twips  
Any use?


kamarrizwanAuthor Commented:
Hi TimYates,
thanks for workout.
As i'm new to jsp, still trying to got the solution. can you please help me out to understand the code in better way.
Basically, you'll need to open a DataInputStream that points to the file:

    DataInputStream dis = new DataInputStream( new FileInputStream( "flashfile.swf" ) ) ;

then, skip the first 8 bytes (up to and including filesize according to the header)

    dis.skip( 8 ) ;

then, read 5 bytes in.  These will represent the number of bits used for each of x, y, w, h

    byte[] nBits = new byte[ 5 ] ;
    dis.readFully( nBits, 0, 5 ) ;

then, convert this to a long (THIS WILL DEPEND WHICH WAY ROUND THE NUMBERS ARE ENCODED IN THE FILE) :-(  Have a look with a hex editor...  I'm assuming they're little-endian

    long n = ( nBits[ 0 ] & 0xff ) |
                  ( ( nBits[ 1 ] & 0xFF ) << 8 ) |
                  ( ( nBits[ 2 ] & 0xFF ) << 16 ) |
                  ( ( nBits[ 3 ] & 0xFF ) << 24 ) |
                  ( ( nBits[ 4 ] & 0xFF ) << 32 ) |
    out.println( "Apparently, there are " + n + " bits per field" ) ;

then, read the xmin, xmax, ymin, ymax values:

    byte[] xmin = new byte[ n ] ;
    byte[] xmax = new byte[ n ] ;
    byte[] ymin = new byte[ n ] ;
    byte[] ymax = new byte[ n ] ;
    dis.readFully( xmin, 0, n ) ;
    dis.readFully( xmax, 0, n ) ;
    dis.readFully( ymin, 0, n ) ;
    dis.readFully( ymax, 0, n ) ;

then...convert these byte arrays into integers...(as we did with the nBits array)

And xmax - xmin SHOULD be equal to the width of the SWF...


I'd check all this with a hex editor and a pen and paper first though, before you go through the pain of bitwise arithmetic for nothing ;-)

kamarrizwanAuthor Commented:
Hi Tim,

Thanks for your workout and i hope this should be good answer as i am seeing the confidence in writing the solution.

Sorry for delayed reply, actually i have not got chance to test your code as we are feeding the flash dimension into the database.

Thank you very much.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now