Program: 62117
Project: 62117
Buggy source:
public static String convertLibrary(SWF swf,Map<Integer,String> characterVariables,Map<Integer,String> characterClasses,List<Integer> oneInstanceShapes,String backgroundColor,List<Tag> tags,HashMap<Integer,CharacterTag> characters,HashMap<String,byte[]> files){
  String ret="String_Node_Str";
  List<String> media=new ArrayList<>();
  List<String> symbols=new ArrayList<>();
  for (  int ch : characters.keySet()) {
    CharacterTag symbol=characters.get(ch);
    if ((symbol instanceof ShapeTag) && oneInstanceShapes.contains(symbol.getCharacterID())) {
      continue;
    }
    if ((symbol instanceof ShapeTag) || (symbol instanceof DefineSpriteTag) || (symbol instanceof ButtonTag)) {
      String symbolStr="String_Node_Str";
      symbolStr+="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str"+ getTimestamp()+ "String_Node_Str";
      if (symbol instanceof ShapeTag) {
        symbolStr+="String_Node_Str";
      }
 else       if (symbol instanceof ButtonTag) {
        symbolStr+="String_Node_Str";
        if (((ButtonTag)symbol).trackAsMenu()) {
          symbolStr+="String_Node_Str";
        }
      }
      boolean linkageExportForAS=false;
      if (characterClasses.containsKey(symbol.getCharacterID())) {
        linkageExportForAS=true;
        symbolStr+="String_Node_Str" + xmlString(characterClasses.get(symbol.getCharacterID())) + "String_Node_Str";
      }
      if (characterVariables.containsKey(symbol.getCharacterID())) {
        linkageExportForAS=true;
        symbolStr+="String_Node_Str" + xmlString(characterVariables.get(symbol.getCharacterID())) + "String_Node_Str";
      }
      if (linkageExportForAS) {
        symbolStr+="String_Node_Str";
      }
      symbolStr+="String_Node_Str";
      symbolStr+="String_Node_Str";
      String itemIcon=null;
      if (symbol instanceof ButtonTag) {
        itemIcon="String_Node_Str";
        symbolStr+="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str";
        symbolStr+="String_Node_Str";
        ButtonTag button=(ButtonTag)symbol;
        List<BUTTONRECORD> records=button.getRecords();
        String frames[]={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
        int maxDepth=0;
        for (        BUTTONRECORD rec : records) {
          if (rec.placeDepth > maxDepth) {
            maxDepth=rec.placeDepth;
          }
        }
        for (int i=maxDepth; i >= 1; i--) {
          symbolStr+="String_Node_Str" + (maxDepth - i + 1) + "String_Node_Str";
          if (i == 1) {
            symbolStr+="String_Node_Str";
          }
          symbolStr+="String_Node_Str";
          symbolStr+="String_Node_Str";
          int lastFrame=0;
          loopframes:           for (int frame=1; frame <= 4; frame++) {
            for (            BUTTONRECORD rec : records) {
              if (rec.placeDepth == i) {
                boolean ok=false;
switch (frame) {
case 1:
                  ok=rec.buttonStateUp;
                break;
case 2:
              ok=rec.buttonStateOver;
            break;
case 3:
          ok=rec.buttonStateDown;
        break;
case 4:
      ok=rec.buttonStateHitTest;
    break;
}
if (!ok) {
  continue;
}
CXFORMWITHALPHA colorTransformAlpha=null;
int blendMode=0;
List<FILTER> filters=new ArrayList<>();
if (button instanceof DefineButton2Tag) {
  colorTransformAlpha=rec.colorTransform;
  if (rec.buttonHasBlendMode) {
    blendMode=rec.blendMode;
  }
  if (rec.buttonHasFilterList) {
    filters=rec.filterList;
  }
}
CharacterTag character=characters.get(rec.characterId);
MATRIX matrix=rec.placeMatrix;
String recCharStr="String_Node_Str";
if (character instanceof TextTag) {
  recCharStr=convertText(tags,(TextTag)character,matrix,filters);
}
 else if (character instanceof DefineVideoStreamTag) {
  recCharStr=convertVideoInstance(matrix,(DefineVideoStreamTag)character);
}
 else {
  recCharStr=convertSymbolInstance(null,matrix,null,colorTransformAlpha,false,blendMode,filters,true,null,characters.get(rec.characterId),characters,tags);
}
int duration=frame - lastFrame;
lastFrame=frame;
if (duration > 0) {
  if (duration > 1) {
    symbolStr+="String_Node_Str";
    symbolStr+=(frame - duration);
    symbolStr+="String_Node_Str";
    symbolStr+="String_Node_Str" + (duration - 1) + "String_Node_Str";
    symbolStr+="String_Node_Str" + KEY_MODE_NORMAL + "String_Node_Str";
    symbolStr+="String_Node_Str";
    symbolStr+="String_Node_Str";
    symbolStr+="String_Node_Str";
  }
  symbolStr+="String_Node_Str";
  symbolStr+=(frame - 1);
  symbolStr+="String_Node_Str";
  symbolStr+="String_Node_Str" + KEY_MODE_NORMAL + "String_Node_Str";
  symbolStr+="String_Node_Str";
  symbolStr+=recCharStr;
  symbolStr+="String_Node_Str";
  symbolStr+="String_Node_Str";
}
}
}
}
symbolStr+="String_Node_Str";
symbolStr+="String_Node_Str";
}
symbolStr+="String_Node_Str";
symbolStr+="String_Node_Str";
}
 else if (symbol instanceof DefineSpriteTag) {
DefineSpriteTag sprite=(DefineSpriteTag)symbol;
if (sprite.subTags.isEmpty()) {
continue;
}
symbolStr+=convertTimeline(sprite.spriteId,oneInstanceShapes,backgroundColor,tags,sprite.getSubTags(),characters,"String_Node_Str" + symbol.getCharacterID());
}
 else if (symbol instanceof ShapeTag) {
itemIcon="String_Node_Str";
ShapeTag shape=(ShapeTag)symbol;
symbolStr+="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str";
symbolStr+="String_Node_Str";
symbolStr+=convertShape(characters,null,shape);
symbolStr+="String_Node_Str";
symbolStr+="String_Node_Str";
}
symbolStr+="String_Node_Str";
symbolStr+="String_Node_Str";
symbolStr=prettyFormatXML(symbolStr);
String symbolFile="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str";
try {
files.put(symbolFile,symbolStr.getBytes("String_Node_Str"));
}
 catch (UnsupportedEncodingException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
String symbLinkStr="String_Node_Str";
symbLinkStr+="String_Node_Str" + symbolFile + "String_Node_Str";
if (itemIcon != null) {
symbLinkStr+="String_Node_Str" + itemIcon + "String_Node_Str";
}
symbLinkStr+="String_Node_Str" + getTimestamp() + "String_Node_Str";
symbols.add(symbLinkStr);
}
 else if (symbol instanceof ImageTag) {
ImageTag imageTag=(ImageTag)symbol;
ByteArrayOutputStream baos=new ByteArrayOutputStream();
BufferedImage image=imageTag.getImage(tags);
String format=imageTag.getImageFormat();
try {
ImageIO.write(image,format.toUpperCase(),baos);
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
String symbolFile="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str"+ imageTag.getImageFormat();
files.put(symbolFile,baos.toByteArray());
String mediaLinkStr="String_Node_Str" + symbolFile + "String_Node_Str"+ getTimestamp()+ "String_Node_Str"+ baos.toByteArray().length+ "String_Node_Str";
if (format.equals("String_Node_Str") || format.equals("String_Node_Str")) {
mediaLinkStr+="String_Node_Str";
}
 else if (format.equals("String_Node_Str")) {
mediaLinkStr+="String_Node_Str";
}
if (characterClasses.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + characterClasses.get(symbol.getCharacterID()) + "String_Node_Str";
}
mediaLinkStr+="String_Node_Str" + symbolFile + "String_Node_Str"+ (media.size() + 1)+ "String_Node_Str"+ getTimestamp()+ "String_Node_Str"+ image.getWidth()+ "String_Node_Str"+ image.getHeight()+ "String_Node_Str";
media.add(mediaLinkStr);
}
 else if ((symbol instanceof SoundStreamHeadTypeTag) || (symbol instanceof DefineSoundTag)) {
int soundFormat=0;
int soundRate=0;
int soundType=0;
int soundSize=0;
long soundSampleCount=0;
byte soundData[]=new byte[0];
int rateMap[]={5,11,22,44};
String exportFormat="String_Node_Str";
if (symbol instanceof SoundStreamHeadTypeTag) {
SoundStreamHeadTypeTag sstream=(SoundStreamHeadTypeTag)symbol;
soundFormat=sstream.getSoundFormat();
soundRate=sstream.getSoundRate();
soundType=sstream.getSoundType();
soundSize=sstream.getSoundSize();
soundSampleCount=sstream.getSoundSampleCount();
boolean found=false;
for (Tag t : tags) {
if (found && (t instanceof SoundStreamBlockTag)) {
SoundStreamBlockTag bl=(SoundStreamBlockTag)t;
soundData=bl.getData(SWF.DEFAULT_VERSION);
break;
}
if (t == symbol) {
found=true;
}
}
}
 else if (symbol instanceof DefineSoundTag) {
DefineSoundTag sound=(DefineSoundTag)symbol;
soundFormat=sound.soundFormat;
soundRate=sound.soundRate;
soundType=sound.soundType;
soundData=sound.soundData;
soundSize=sound.soundSize;
soundSampleCount=sound.soundSampleCount;
}
int format=0;
int bits=0;
if ((soundFormat == DefineSoundTag.FORMAT_ADPCM) || (soundFormat == DefineSoundTag.FORMAT_UNCOMPRESSED_LITTLE_ENDIAN) || (soundFormat == DefineSoundTag.FORMAT_UNCOMPRESSED_NATIVE_ENDIAN)) {
if (soundType == 1) {
format+=1;
}
switch (soundRate) {
case 0:
format+=2;
break;
case 1:
format+=6;
break;
case 2:
format+=10;
break;
case 3:
format+=14;
break;
}
}
if (soundFormat == DefineSoundTag.FORMAT_SPEEX) {
bits=18;
}
if (soundFormat == DefineSoundTag.FORMAT_ADPCM) {
SWFInputStream sis=new SWFInputStream(new ByteArrayInputStream(soundData),SWF.DEFAULT_VERSION);
exportFormat="String_Node_Str";
try {
int adpcmCodeSize=(int)sis.readUB(2);
bits=2 + adpcmCodeSize;
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
}
if (soundFormat == DefineSoundTag.FORMAT_MP3) {
exportFormat="String_Node_Str";
if (soundType == 0) {
format+=1;
}
format+=4;
SWFInputStream sis=new SWFInputStream(new ByteArrayInputStream(soundData),SWF.DEFAULT_VERSION);
try {
sis.readSI16();
MP3FRAME frame=new MP3FRAME(sis);
int bitRate=frame.getBitrate();
switch (bitRate) {
case 8:
bits=6;
break;
case 16:
bits=7;
break;
case 20:
bits=8;
break;
case 24:
bits=9;
break;
case 32:
bits=10;
break;
case 48:
bits=11;
break;
case 56:
bits=12;
break;
case 64:
bits=13;
break;
case 80:
bits=14;
break;
case 112:
bits=15;
break;
case 128:
bits=16;
break;
case 160:
bits=17;
break;
}
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
}
byte data[]=new byte[0];
try {
data=swf.exportSound(symbol);
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
if (!exportFormat.equals("String_Node_Str")) {
String symbolFile="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str"+ exportFormat;
files.put(symbolFile,data);
String mediaLinkStr="String_Node_Str" + symbolFile + "String_Node_Str"+ getTimestamp()+ "String_Node_Str"+ data.length+ "String_Node_Str";
mediaLinkStr+="String_Node_Str" + symbolFile + "String_Node_Str";
mediaLinkStr+="String_Node_Str";
mediaLinkStr+=rateMap[soundRate] + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + (soundSize == 1 ? "String_Node_Str" : "String_Node_Str");
mediaLinkStr+="String_Node_Str" + (soundType == 1 ? "String_Node_Str" : "String_Node_Str");
mediaLinkStr+="String_Node_Str";
mediaLinkStr+="String_Node_Str" + format + "String_Node_Str"+ bits+ "String_Node_Str"+ soundSampleCount+ "String_Node_Str";
if (characterClasses.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + characterClasses.get(symbol.getCharacterID()) + "String_Node_Str";
}
if (characterVariables.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + xmlString(characterVariables.get(symbol.getCharacterID())) + "String_Node_Str";
}
mediaLinkStr+="String_Node_Str";
media.add(mediaLinkStr);
}
}
 else if (symbol instanceof DefineVideoStreamTag) {
DefineVideoStreamTag video=(DefineVideoStreamTag)symbol;
String videoType="String_Node_Str";
switch (video.codecID) {
case 2:
videoType="String_Node_Str";
break;
case 3:
videoType="String_Node_Str";
break;
case 4:
videoType="String_Node_Str";
break;
case 5:
videoType="String_Node_Str";
break;
}
byte data[]=new byte[0];
try {
data=swf.exportMovie(video);
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
String symbolFile="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str"+ "String_Node_Str";
files.put(symbolFile,data);
String mediaLinkStr="String_Node_Str" + symbolFile + "String_Node_Str"+ getTimestamp()+ "String_Node_Str"+ data.length+ "String_Node_Str";
mediaLinkStr+="String_Node_Str" + symbolFile + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + videoType + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + swf.frameRate + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + video.width + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + video.height + "String_Node_Str";
double len=((double)video.numFrames) / ((double)swf.frameRate);
mediaLinkStr+="String_Node_Str" + len + "String_Node_Str";
if (characterClasses.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + characterClasses.get(symbol.getCharacterID()) + "String_Node_Str";
}
if (characterVariables.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + xmlString(characterVariables.get(symbol.getCharacterID())) + "String_Node_Str";
}
mediaLinkStr+="String_Node_Str";
media.add(mediaLinkStr);
}
}
if (!media.isEmpty()) {
ret+="String_Node_Str";
for (String m : media) {
ret+=m;
}
ret+="String_Node_Str";
}
if (!symbols.isEmpty()) {
ret+="String_Node_Str";
for (String s : symbols) {
ret+=s;
}
ret+="String_Node_Str";
}
return ret;
}

Fixed version (ground truth):
public static String convertLibrary(SWF swf,Map<Integer,String> characterVariables,Map<Integer,String> characterClasses,List<Integer> oneInstanceShapes,String backgroundColor,List<Tag> tags,HashMap<Integer,CharacterTag> characters,HashMap<String,byte[]> files,HashMap<String,byte[]> datfiles){
  String ret="String_Node_Str";
  List<String> media=new ArrayList<>();
  List<String> symbols=new ArrayList<>();
  for (  int ch : characters.keySet()) {
    CharacterTag symbol=characters.get(ch);
    if ((symbol instanceof ShapeTag) && oneInstanceShapes.contains(symbol.getCharacterID())) {
      continue;
    }
    if ((symbol instanceof ShapeTag) || (symbol instanceof DefineSpriteTag) || (symbol instanceof ButtonTag)) {
      String symbolStr="String_Node_Str";
      symbolStr+="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str"+ getTimestamp()+ "String_Node_Str";
      if (symbol instanceof ShapeTag) {
        symbolStr+="String_Node_Str";
      }
 else       if (symbol instanceof ButtonTag) {
        symbolStr+="String_Node_Str";
        if (((ButtonTag)symbol).trackAsMenu()) {
          symbolStr+="String_Node_Str";
        }
      }
      boolean linkageExportForAS=false;
      if (characterClasses.containsKey(symbol.getCharacterID())) {
        linkageExportForAS=true;
        symbolStr+="String_Node_Str" + xmlString(characterClasses.get(symbol.getCharacterID())) + "String_Node_Str";
      }
      if (characterVariables.containsKey(symbol.getCharacterID())) {
        linkageExportForAS=true;
        symbolStr+="String_Node_Str" + xmlString(characterVariables.get(symbol.getCharacterID())) + "String_Node_Str";
      }
      if (linkageExportForAS) {
        symbolStr+="String_Node_Str";
      }
      symbolStr+="String_Node_Str";
      symbolStr+="String_Node_Str";
      String itemIcon=null;
      if (symbol instanceof ButtonTag) {
        itemIcon="String_Node_Str";
        symbolStr+="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str";
        symbolStr+="String_Node_Str";
        ButtonTag button=(ButtonTag)symbol;
        List<BUTTONRECORD> records=button.getRecords();
        String frames[]={"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"};
        int maxDepth=0;
        for (        BUTTONRECORD rec : records) {
          if (rec.placeDepth > maxDepth) {
            maxDepth=rec.placeDepth;
          }
        }
        for (int i=maxDepth; i >= 1; i--) {
          symbolStr+="String_Node_Str" + (maxDepth - i + 1) + "String_Node_Str";
          if (i == 1) {
            symbolStr+="String_Node_Str";
          }
          symbolStr+="String_Node_Str" + randomOutlineColor() + "String_Node_Str";
          symbolStr+="String_Node_Str";
          int lastFrame=0;
          loopframes:           for (int frame=1; frame <= 4; frame++) {
            for (            BUTTONRECORD rec : records) {
              if (rec.placeDepth == i) {
                boolean ok=false;
switch (frame) {
case 1:
                  ok=rec.buttonStateUp;
                break;
case 2:
              ok=rec.buttonStateOver;
            break;
case 3:
          ok=rec.buttonStateDown;
        break;
case 4:
      ok=rec.buttonStateHitTest;
    break;
}
if (!ok) {
  continue;
}
CXFORMWITHALPHA colorTransformAlpha=null;
int blendMode=0;
List<FILTER> filters=new ArrayList<>();
if (button instanceof DefineButton2Tag) {
  colorTransformAlpha=rec.colorTransform;
  if (rec.buttonHasBlendMode) {
    blendMode=rec.blendMode;
  }
  if (rec.buttonHasFilterList) {
    filters=rec.filterList;
  }
}
CharacterTag character=characters.get(rec.characterId);
MATRIX matrix=rec.placeMatrix;
String recCharStr="String_Node_Str";
if (character instanceof TextTag) {
  recCharStr=convertText(null,tags,(TextTag)character,matrix,filters);
}
 else if (character instanceof DefineVideoStreamTag) {
  recCharStr=convertVideoInstance(null,matrix,(DefineVideoStreamTag)character);
}
 else {
  recCharStr=convertSymbolInstance(null,matrix,null,colorTransformAlpha,false,blendMode,filters,true,null,characters.get(rec.characterId),characters,tags);
}
int duration=frame - lastFrame;
lastFrame=frame;
if (duration > 0) {
  if (duration > 1) {
    symbolStr+="String_Node_Str";
    symbolStr+=(frame - duration);
    symbolStr+="String_Node_Str";
    symbolStr+="String_Node_Str" + (duration - 1) + "String_Node_Str";
    symbolStr+="String_Node_Str" + KEY_MODE_NORMAL + "String_Node_Str";
    symbolStr+="String_Node_Str";
    symbolStr+="String_Node_Str";
    symbolStr+="String_Node_Str";
  }
  symbolStr+="String_Node_Str";
  symbolStr+=(frame - 1);
  symbolStr+="String_Node_Str";
  symbolStr+="String_Node_Str" + KEY_MODE_NORMAL + "String_Node_Str";
  symbolStr+="String_Node_Str";
  symbolStr+=recCharStr;
  symbolStr+="String_Node_Str";
  symbolStr+="String_Node_Str";
}
}
}
}
symbolStr+="String_Node_Str";
symbolStr+="String_Node_Str";
}
symbolStr+="String_Node_Str";
symbolStr+="String_Node_Str";
}
 else if (symbol instanceof DefineSpriteTag) {
DefineSpriteTag sprite=(DefineSpriteTag)symbol;
if (sprite.subTags.isEmpty()) {
continue;
}
symbolStr+=convertTimeline(sprite.spriteId,oneInstanceShapes,backgroundColor,tags,sprite.getSubTags(),characters,"String_Node_Str" + symbol.getCharacterID());
}
 else if (symbol instanceof ShapeTag) {
itemIcon="String_Node_Str";
ShapeTag shape=(ShapeTag)symbol;
symbolStr+="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str";
symbolStr+="String_Node_Str";
symbolStr+=convertShape(characters,null,shape);
symbolStr+="String_Node_Str";
symbolStr+="String_Node_Str";
}
symbolStr+="String_Node_Str";
symbolStr+="String_Node_Str";
symbolStr=prettyFormatXML(symbolStr);
String symbolFile="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str";
try {
files.put(symbolFile,symbolStr.getBytes("String_Node_Str"));
}
 catch (UnsupportedEncodingException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
String symbLinkStr="String_Node_Str";
symbLinkStr+="String_Node_Str" + symbolFile + "String_Node_Str";
if (itemIcon != null) {
symbLinkStr+="String_Node_Str" + itemIcon + "String_Node_Str";
}
symbLinkStr+="String_Node_Str" + getTimestamp() + "String_Node_Str";
symbols.add(symbLinkStr);
}
 else if (symbol instanceof ImageTag) {
ImageTag imageTag=(ImageTag)symbol;
ByteArrayOutputStream baos=new ByteArrayOutputStream();
BufferedImage image=imageTag.getImage(tags);
String format=imageTag.getImageFormat();
try {
ImageIO.write(image,format.toUpperCase(),baos);
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
String symbolFile="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str"+ imageTag.getImageFormat();
files.put(symbolFile,baos.toByteArray());
String mediaLinkStr="String_Node_Str" + symbolFile + "String_Node_Str"+ getTimestamp()+ "String_Node_Str"+ baos.toByteArray().length+ "String_Node_Str";
if (format.equals("String_Node_Str") || format.equals("String_Node_Str")) {
mediaLinkStr+="String_Node_Str";
}
 else if (format.equals("String_Node_Str")) {
mediaLinkStr+="String_Node_Str";
}
if (characterClasses.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + characterClasses.get(symbol.getCharacterID()) + "String_Node_Str";
}
mediaLinkStr+="String_Node_Str" + symbolFile + "String_Node_Str"+ (media.size() + 1)+ "String_Node_Str"+ getTimestamp()+ "String_Node_Str"+ image.getWidth()+ "String_Node_Str"+ image.getHeight()+ "String_Node_Str";
media.add(mediaLinkStr);
}
 else if ((symbol instanceof SoundStreamHeadTypeTag) || (symbol instanceof DefineSoundTag)) {
int soundFormat=0;
int soundRate=0;
int soundType=0;
int soundSize=0;
long soundSampleCount=0;
byte soundData[]=new byte[0];
int rateMap[]={5,11,22,44};
String exportFormat="String_Node_Str";
if (symbol instanceof SoundStreamHeadTypeTag) {
SoundStreamHeadTypeTag sstream=(SoundStreamHeadTypeTag)symbol;
soundFormat=sstream.getSoundFormat();
soundRate=sstream.getSoundRate();
soundType=sstream.getSoundType();
soundSize=sstream.getSoundSize();
soundSampleCount=sstream.getSoundSampleCount();
boolean found=false;
for (Tag t : tags) {
if (found && (t instanceof SoundStreamBlockTag)) {
SoundStreamBlockTag bl=(SoundStreamBlockTag)t;
soundData=bl.getData(SWF.DEFAULT_VERSION);
break;
}
if (t == symbol) {
found=true;
}
}
}
 else if (symbol instanceof DefineSoundTag) {
DefineSoundTag sound=(DefineSoundTag)symbol;
soundFormat=sound.soundFormat;
soundRate=sound.soundRate;
soundType=sound.soundType;
soundData=sound.soundData;
soundSize=sound.soundSize;
soundSampleCount=sound.soundSampleCount;
}
int format=0;
int bits=0;
if ((soundFormat == DefineSoundTag.FORMAT_ADPCM) || (soundFormat == DefineSoundTag.FORMAT_UNCOMPRESSED_LITTLE_ENDIAN) || (soundFormat == DefineSoundTag.FORMAT_UNCOMPRESSED_NATIVE_ENDIAN)) {
if (soundType == 1) {
format+=1;
}
switch (soundRate) {
case 0:
format+=2;
break;
case 1:
format+=6;
break;
case 2:
format+=10;
break;
case 3:
format+=14;
break;
}
}
if (soundFormat == DefineSoundTag.FORMAT_SPEEX) {
bits=18;
}
if (soundFormat == DefineSoundTag.FORMAT_ADPCM) {
SWFInputStream sis=new SWFInputStream(new ByteArrayInputStream(soundData),SWF.DEFAULT_VERSION);
exportFormat="String_Node_Str";
try {
int adpcmCodeSize=(int)sis.readUB(2);
bits=2 + adpcmCodeSize;
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
}
if (soundFormat == DefineSoundTag.FORMAT_MP3) {
exportFormat="String_Node_Str";
if (soundType == 0) {
format+=1;
}
format+=4;
SWFInputStream sis=new SWFInputStream(new ByteArrayInputStream(soundData),SWF.DEFAULT_VERSION);
try {
sis.readSI16();
MP3FRAME frame=new MP3FRAME(sis);
int bitRate=frame.getBitrate();
switch (bitRate) {
case 8:
bits=6;
break;
case 16:
bits=7;
break;
case 20:
bits=8;
break;
case 24:
bits=9;
break;
case 32:
bits=10;
break;
case 48:
bits=11;
break;
case 56:
bits=12;
break;
case 64:
bits=13;
break;
case 80:
bits=14;
break;
case 112:
bits=15;
break;
case 128:
bits=16;
break;
case 160:
bits=17;
break;
}
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
}
byte data[]=new byte[0];
try {
data=swf.exportSound(symbol);
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
if (!exportFormat.equals("String_Node_Str")) {
String symbolFile="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str"+ exportFormat;
files.put(symbolFile,data);
String mediaLinkStr="String_Node_Str" + symbolFile + "String_Node_Str"+ getTimestamp()+ "String_Node_Str"+ data.length+ "String_Node_Str";
mediaLinkStr+="String_Node_Str" + symbolFile + "String_Node_Str";
mediaLinkStr+="String_Node_Str";
mediaLinkStr+=rateMap[soundRate] + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + (soundSize == 1 ? "String_Node_Str" : "String_Node_Str");
mediaLinkStr+="String_Node_Str" + (soundType == 1 ? "String_Node_Str" : "String_Node_Str");
mediaLinkStr+="String_Node_Str";
mediaLinkStr+="String_Node_Str" + format + "String_Node_Str"+ bits+ "String_Node_Str"+ soundSampleCount+ "String_Node_Str";
if (characterClasses.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + characterClasses.get(symbol.getCharacterID()) + "String_Node_Str";
}
if (characterVariables.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + xmlString(characterVariables.get(symbol.getCharacterID())) + "String_Node_Str";
}
mediaLinkStr+="String_Node_Str";
media.add(mediaLinkStr);
}
}
 else if (symbol instanceof DefineVideoStreamTag) {
DefineVideoStreamTag video=(DefineVideoStreamTag)symbol;
String videoType="String_Node_Str";
switch (video.codecID) {
case 2:
videoType="String_Node_Str";
break;
case 3:
videoType="String_Node_Str";
break;
case 4:
videoType="String_Node_Str";
break;
case 5:
videoType="String_Node_Str";
break;
}
byte data[]=new byte[0];
try {
data=swf.exportMovie(video);
}
 catch (IOException ex) {
Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE,null,ex);
}
String symbolFile="String_Node_Str" + symbol.getCharacterID() + "String_Node_Str"+ "String_Node_Str";
String mediaLinkStr="String_Node_Str";
if (data.length == 0) {
long ts=getTimestamp();
String datFileName="String_Node_Str" + (datfiles.size() + 1) + "String_Node_Str"+ ts+ "String_Node_Str";
mediaLinkStr="String_Node_Str" + symbolFile + "String_Node_Str"+ symbolFile+ "String_Node_Str"+ ts+ "String_Node_Str"+ datFileName+ "String_Node_Str";
datfiles.put(datFileName,new byte[]{(byte)0x03,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0xA0,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x78,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,(byte)0x01,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x59,(byte)0x40,(byte)0x18,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0xFF,(byte)0xFE,(byte)0xFF,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00});
}
 else {
files.put(symbolFile,data);
mediaLinkStr="String_Node_Str" + symbolFile + "String_Node_Str"+ getTimestamp()+ "String_Node_Str"+ data.length+ "String_Node_Str";
mediaLinkStr+="String_Node_Str" + symbolFile + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + videoType + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + swf.frameRate + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + video.width + "String_Node_Str";
mediaLinkStr+="String_Node_Str" + video.height + "String_Node_Str";
double len=((double)video.numFrames) / ((double)swf.frameRate);
mediaLinkStr+="String_Node_Str" + len + "String_Node_Str";
if (characterClasses.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + characterClasses.get(symbol.getCharacterID()) + "String_Node_Str";
}
if (characterVariables.containsKey(symbol.getCharacterID())) {
mediaLinkStr+="String_Node_Str" + xmlString(characterVariables.get(symbol.getCharacterID())) + "String_Node_Str";
}
mediaLinkStr+="String_Node_Str";
}
media.add(mediaLinkStr);
}
}
if (!media.isEmpty()) {
ret+="String_Node_Str";
for (String m : media) {
ret+=m;
}
ret+="String_Node_Str";
}
if (!symbols.isEmpty()) {
ret+="String_Node_Str";
for (String s : symbols) {
ret+=s;
}
ret+="String_Node_Str";
}
return ret;
}