예제 #1
0
 private void processHeader(SWFHeader header) {
   document.setFrameRate(header.getFrameRate());
   document.setFrameSize(header.getFrameSize());
   document.setVersion(header.getVersion());
   document.setFileLength(header.getFileLength());
   document.setFrameCount(header.getFrameCount());
   document.setCompressed(header.isCompressed());
   for (SWFListener l : listeners) {
     l.processHeader(header);
   }
 }
예제 #2
0
 /**
  * Reads the SWF content from the stream passed to the constructor, and invokes the methods of the
  * registered listeners. Finally, the stream is closed.
  *
  * <p>Returns the SWF document created during parsing.
  *
  * <p>Read errors while processing a tag will cause an exception to be thrown, this behaviour can
  * changed to instead create a MalformedTag (and thus allowing the code to continue albeit with
  * corrupt data) by using {@link SWFListener}. See {@link
  * SWFListener#processTagReadError(TagHeader, byte[], Exception)}.
  *
  * @see SWFListener
  * @return the parsed <code>SWFDocument</code> instance
  * @throws IOException if an error occured while reading
  */
 public SWFDocument read() throws IOException {
   preProcess();
   SWFHeader header;
   try {
     header = new SWFHeader(bitStream);
   } catch (Exception e) {
     // invoke error processing, without header we cannot do anything...
     processHeaderReadError(e);
     IOException ioe = new IOException("Error while reading SWF header");
     ioe.initCause(e);
     throw ioe;
   }
   processHeader(header);
   do {
     // we check this because of an OpenOffice export bug
     // (END tag written as a UI8 (00)instead of an UI16 (00 00))
     if ((header.getFileLength() - bitStream.getOffset()) < 2) {
       break;
     }
     TagHeader tagHeader = null;
     try {
       tagHeader = TagReader.readTagHeader(bitStream);
     } catch (Exception e) {
       // cannot continue without tag header
       processTagHeaderReadError(e);
       IOException ioe = new IOException("Error while reading Tag header");
       ioe.initCause(e);
       throw ioe;
     }
     processTagHeader(tagHeader);
     Tag tag = null;
     byte[] tagData = null;
     try {
       tagData = TagReader.readTagData(bitStream, tagHeader);
       tag = TagReader.readTag(tagHeader, tagData, header.getVersion(), japanese);
       if (TagType.END.equals(tag.tagType())) {
         break;
       }
     } catch (Exception e) {
       // invoke error processing
       if (processTagReadError(tagHeader, tagData, e)) {
         TagType tt = null;
         try {
           tt = TagType.lookup(tagHeader.getCode());
         } catch (InvalidCodeException ive) {
         }
         IOException ioe =
             new IOException(
                 "Error while reading Tag ("
                     + (tt != null ? tt.getNiceName() : "UNKOWN")
                     + ", code:"
                     + tagHeader.getCode()
                     + ", length:"
                     + tagHeader.getLength()
                     + ")");
         ioe.initCause(e);
         throw ioe;
       }
       tag = new MalformedTag(tagHeader, tagData, e);
     }
     processTag(tag, bitStream.getOffset());
   } while (true);
   postProcess();
   try {
     bitStream.close();
   } catch (Exception e) {
     // empty on purpose - don't need to propagate errors which occur while closing
   }
   return document;
 }