| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Flanderra
Revision: 14
Author: pcherkas
Date: 14 Jul 2008 21:58:43
Changes:initial implementation of swf parser
Files:| ... | ...@@ -41,12 +41,16 @@ | |
| 41 | 41 | |
| 42 | 42 | import java.io.ByteArrayInputStream; |
| 43 | 43 | import java.io.ByteArrayOutputStream; |
| 44 | import java.io.FileOutputStream; | |
| 44 | 45 | import java.io.IOException; |
| 45 | 46 | import java.io.InputStream; |
| 47 | import java.io.OutputStream; | |
| 46 | 48 | import java.text.MessageFormat; |
| 47 | 49 | import java.util.ArrayList; |
| 48 | 50 | import java.util.BitSet; |
| 49 | 51 | import java.util.HashMap; |
| 52 | import java.util.LinkedHashMap; | |
| 53 | import java.util.LinkedList; | |
| 50 | 54 | import java.util.List; |
| 51 | 55 | import java.util.Map; |
| 52 | 56 | import java.util.zip.InflaterInputStream; |
| ... | ...@@ -56,6 +60,7 @@ | |
| 56 | 60 | |
| 57 | 61 | import com.flanderra.commons.el.ExpressionEvaluator; |
| 58 | 62 | import com.flanderra.commons.utils.BitInputStream; |
| 63 | import com.flanderra.commons.utils.BitUtils; | |
| 59 | 64 | import com.flanderra.commons.utils.TypeUtils; |
| 60 | 65 | |
| 61 | 66 | /** |
| ... | ...@@ -167,14 +172,15 @@ | |
| 167 | 172 | result = concat(result, bsTags, offset, lenTags * 8); |
| 168 | 173 | offset += lenTags * 8; |
| 169 | 174 | logger.debug("finished generating SWF..."); |
| 170 | return bitsToBytes(result, offset); | |
| 175 | return bitsToBytes(result, offset); | |
| 171 | 176 | } |
| 172 | 177 | |
| 173 | 178 | public static Map<String, Object> parseSWF(InputStream is) { |
| 174 | 179 | try { |
| 175 | Map<String, Object> result = new HashMap<String, Object>(); | |
| 180 | Map<String, Object> result = new LinkedHashMap<String, Object>(); | |
| 176 | 181 | byte[] head = new byte[4]; |
| 177 | 182 | is.read(head); |
| 183 | ||
| 178 | 184 | boolean zipContent = head[0] == 67; |
| 179 | 185 | result.put("zipContent", head[0] == 67); |
| 180 | 186 | result.put("version", head[3]); |
| ... | ...@@ -188,10 +194,69 @@ | |
| 188 | 194 | while (!((i = is.read()) < 0)) { |
| 189 | 195 | baos.write(i); |
| 190 | 196 | } |
| 197 | ||
| 191 | 198 | new InflaterInputStream(new ByteArrayInputStream(baos.toByteArray())).read(restFileData); |
| 192 | 199 | } else { |
| 193 | 200 | is.read(restFileData); |
| 194 | 201 | } |
| 202 | ||
| 203 | InputStream bais = new ByteArrayInputStream(restFileData); | |
| 204 | BitInputStream bis = new BitInputStream(bais); | |
| 205 | ||
| 206 | Map sizeRect = parseCompoundType("RECT", "sizes", new LinkedHashMap(), bis); | |
| 207 | result.put("sizes", sizeRect); | |
| 208 | byte[] frameDelay = new byte[] { bis.read(), bis.read() }; | |
| 209 | result.put("frameRate", BitUtils.parseFixed88(frameDelay)); | |
| 210 | byte[] frameCount = new byte[] { bis.read(), bis.read() }; | |
| 211 | result.put("frameCount", BitUtils.parseUI16(frameCount)); | |
| 212 | boolean finished = false; | |
| 213 | List tags = new ArrayList(); | |
| 214 | while (!finished) { | |
| 215 | try { | |
| 216 | Map tagContents = new LinkedHashMap(); | |
| 217 | byte[] tagHeaderBytes = new byte[] { bis.read(), bis.read() }; | |
| 218 | if (tagHeaderBytes[0] == -1 && tagHeaderBytes[1] == -1) { | |
| 219 | break; | |
| 220 | } | |
| 221 | // if (tagHeaderBytes[0] == 0 && tagHeaderBytes[1] == 0) { | |
| 222 | // break; | |
| 223 | // } | |
| 224 | BitSet tagHeaderBits = BitUtils.bytesToBits(tagHeaderBytes); | |
| 225 | tagHeaderBits = BitUtils.flipBytes(tagHeaderBits, 2); | |
| 226 | long tagCode = BitUtils.parseUBArray(BitUtils.sub(tagHeaderBits, 0, 9), 10); | |
| 227 | long tagLength = BitUtils.parseUBArray(BitUtils.sub(tagHeaderBits, 10, 15), 6); | |
| 228 | if (tagLength == 0x3f) { | |
| 229 | tagLength = BitUtils.parseSI32(new byte[] { bis.read(), bis.read(), bis.read(), bis.read() }); | |
| 230 | } | |
| 231 | String tagName = StructureFormatUtils.tagNameForCode((int) tagCode); | |
| 232 | ByteArrayOutputStream tagContentBaos = new ByteArrayOutputStream((int) (tagLength + 2)); | |
| 233 | tagContentBaos.write(tagHeaderBytes); | |
| 234 | for (int i = 0; i < tagLength; i++) { | |
| 235 | tagContentBaos.write(bis.read()); | |
| 236 | } | |
| 237 | boolean supported = StructureFormatUtils.isSupportedStructure(tagName); | |
| 238 | // tagContents.put("tagCode", new Long(tagCode)); | |
| 239 | tagContents.put("tagName", tagName); | |
| 240 | // tagContents.put("isSupported", supported); | |
| 241 | tagContents.put("tagLength", new Long(tagLength)); | |
| 242 | tagContents.put("tagData", hex(tagContentBaos.toByteArray())); | |
| 243 | if (supported) { | |
| 244 | tagContents.putAll(parseCompoundType(tagName, "tag".concat(tagName), result, bis)); | |
| 245 | } | |
| 246 | if ((tags.size() > 2)) { | |
| 247 | String prevTagName = (String) ((Map) tags.get(tags.size() - 1)).get("tagName"); | |
| 248 | String prevPrevTagName = (String) ((Map) tags.get(tags.size() - 2)).get("tagName"); | |
| 249 | if (prevTagName != null && prevPrevTagName != null && prevTagName.equals("End") && prevPrevTagName.equals("End")) { | |
| 250 | finished = true; | |
| 251 | } | |
| 252 | } | |
| 253 | tags.add(tagContents); | |
| 254 | } catch (Throwable e) { | |
| 255 | logger.error("exception while parsing swf", e); | |
| 256 | finished = true; | |
| 257 | } | |
| 258 | } | |
| 259 | result.put("tags", tags); | |
| 195 | 260 | return result; |
| 196 | 261 | } catch (IOException e) { |
| 197 | 262 | logger.error(e); |
| ... | ...@@ -210,14 +275,12 @@ | |
| 210 | 275 | for (String key : field.getTransmitFields()) { |
| 211 | 276 | if (context.containsKey(key)) { |
| 212 | 277 | contextEx.put(key, context.get(key)); |
| 213 | logger | |
| 214 | .debug(MessageFormat.format("transmitting value of field {0} to the context of field {1}", key, field | |
| 215 | .getName())); | |
| 278 | logger.debug(MessageFormat.format("transmitting value of field {0} to the context of field {1}", key, field | |
| 279 | .getName())); | |
| 216 | 280 | } else if (result.containsKey(key)) { |
| 217 | 281 | contextEx.put(key, result.get(key)); |
| 218 | logger | |
| 219 | .debug(MessageFormat.format("transmitting value of field {0} to the context of field {1}", key, field | |
| 220 | .getName())); | |
| 282 | logger.debug(MessageFormat.format("transmitting value of field {0} to the context of field {1}", key, field | |
| 283 | .getName())); | |
| 221 | 284 | } else { |
| 222 | 285 | throw new IllegalStateException(MessageFormat.format( |
| 223 | 286 | "type \"{0}\" can not transmit value of field \"{1}\" to field \"{2}\", it was not set before", typeInfo |
| ... | ...@@ -1,113 +1,145 @@ | |
| 1 | 1 | package com.flanderra.commons.xmlstub; |
| 2 | 2 | |
| 3 | import java.io.IOException; | |
| 3 | 4 | import java.io.InputStream; |
| 4 | 5 | import java.io.OutputStream; |
| 6 | import java.io.PrintWriter; | |
| 5 | 7 | import java.util.ArrayList; |
| 6 | 8 | import java.util.HashMap; |
| 9 | import java.util.Iterator; | |
| 7 | 10 | import java.util.List; |
| 8 | 11 | import java.util.Map; |
| 9 | 12 | import java.util.Properties; |
| 13 | import java.util.Set; | |
| 10 | 14 | |
| 11 | 15 | import org.apache.commons.beanutils.PropertyUtils; |
| 12 | 16 | import org.junit.Assert; |
| 13 | 17 | |
| 14 | 18 | public class PropertiesStubUtil implements IStubUtil { |
| 15 | 19 | private static PropertiesStubUtil instance; |
| 16 | private PropertiesStubUtil(){ | |
| 17 | ||
| 20 | ||
| 21 | private PropertiesStubUtil() { | |
| 22 | ||
| 18 | 23 | } |
| 19 | ||
| 20 | public static PropertiesStubUtil getInstance(){ | |
| 21 | if(instance==null){ | |
| 24 | ||
| 25 | public static PropertiesStubUtil getInstance() { | |
| 26 | if (instance == null) { | |
| 22 | 27 | instance = new PropertiesStubUtil(); |
| 23 | 28 | } |
| 24 | 29 | return instance; |
| 25 | 30 | } |
| 26 | 31 | |
| 27 | 32 | public Map<String, Object> read(InputStream input) { |
| 28 | try { | |
| 29 | Properties props = new Properties(); | |
| 30 | props.load(input); | |
| 31 | Map<String, Object> result = new HashMap<String, Object>(); | |
| 32 | List<String> collectionKeys = new ArrayList<String>(); | |
| 33 | for (Object objkey : props.keySet()) { | |
| 34 | String key = (String) objkey; | |
| 35 | String[] parts; | |
| 36 | if (key.contains(".")) { | |
| 37 | parts = key.split("[.]"); | |
| 38 | } else { | |
| 39 | parts = new String[]{key}; | |
| 40 | } | |
| 41 | for (int i = 0; i < parts.length; i++) { | |
| 42 | StringBuffer fullpath = new StringBuffer(""); | |
| 43 | for (int ind = 0; ind <= i; ind++) { | |
| 44 | if (!fullpath.toString().equals("")) { | |
| 45 | fullpath.append("."); | |
| 46 | } | |
| 47 | fullpath.append(parts[ind]); | |
| 48 | } | |
| 49 | String mapKey = fullpath.toString(); | |
| 50 | try { | |
| 51 | Long.parseLong(parts[i]); | |
| 52 | String collectionKey = mapKey.substring(0, mapKey.lastIndexOf('.')); | |
| 53 | if (!collectionKeys.contains(collectionKey)) { | |
| 54 | collectionKeys.add(collectionKey); | |
| 55 | } | |
| 56 | } catch (NumberFormatException e) { | |
| 57 | } | |
| 58 | ||
| 59 | if (i == parts.length - 1) { | |
| 60 | PropertyUtils.setProperty(result, mapKey, props.getProperty(key)); | |
| 61 | } else { | |
| 62 | if (PropertyUtils.getProperty(result, mapKey) == null) { | |
| 63 | PropertyUtils.setProperty(result, mapKey, new HashMap<String, Object>()); | |
| 64 | } | |
| 65 | } | |
| 66 | } | |
| 67 | } | |
| 68 | for (int i = collectionKeys.size() - 1; i >= 0; i--) { | |
| 69 | String collectionKey = collectionKeys.get(i); | |
| 70 | Map<String, Object> tmp = (Map<String, Object>) PropertyUtils.getProperty(result, collectionKey); | |
| 71 | List tmp2 = new ArrayList(); | |
| 72 | for(int j = 0; j < tmp.keySet().size(); j++){ | |
| 73 | tmp2.add(tmp.get(""+j)); | |
| 74 | } | |
| 75 | PropertyUtils.setProperty(result, collectionKey, tmp2); | |
| 76 | } | |
| 77 | return result; | |
| 78 | } catch (Exception e) { | |
| 79 | throw new RuntimeException(); | |
| 80 | } | |
| 33 | try { | |
| 34 | Properties props = new Properties(); | |
| 35 | props.load(input); | |
| 36 | Map<String, Object> result = new HashMap<String, Object>(); | |
| 37 | List<String> collectionKeys = new ArrayList<String>(); | |
| 38 | for (Object objkey : props.keySet()) { | |
| 39 | String key = (String) objkey; | |
| 40 | String[] parts; | |
| 41 | if (key.contains(".")) { | |
| 42 | parts = key.split("[.]"); | |
| 43 | } else { | |
| 44 | parts = new String[] { key }; | |
| 45 | } | |
| 46 | for (int i = 0; i < parts.length; i++) { | |
| 47 | StringBuffer fullpath = new StringBuffer(""); | |
| 48 | for (int ind = 0; ind <= i; ind++) { | |
| 49 | if (!fullpath.toString().equals("")) { | |
| 50 | fullpath.append("."); | |
| 51 | } | |
| 52 | fullpath.append(parts[ind]); | |
| 53 | } | |
| 54 | String mapKey = fullpath.toString(); | |
| 55 | try { | |
| 56 | Long.parseLong(parts[i]); | |
| 57 | String collectionKey = mapKey.substring(0, mapKey.lastIndexOf('.')); | |
| 58 | if (!collectionKeys.contains(collectionKey)) { | |
| 59 | collectionKeys.add(collectionKey); | |
| 60 | } | |
| 61 | } catch (NumberFormatException e) { | |
| 62 | } | |
| 63 | ||
| 64 | if (i == parts.length - 1) { | |
| 65 | PropertyUtils.setProperty(result, mapKey, props.getProperty(key)); | |
| 66 | } else { | |
| 67 | if (PropertyUtils.getProperty(result, mapKey) == null) { | |
| 68 | PropertyUtils.setProperty(result, mapKey, new HashMap<String, Object>()); | |
| 69 | } | |
| 70 | } | |
| 71 | } | |
| 72 | } | |
| 73 | for (int i = collectionKeys.size() - 1; i >= 0; i--) { | |
| 74 | String collectionKey = collectionKeys.get(i); | |
| 75 | Map<String, Object> tmp = (Map<String, Object>) PropertyUtils.getProperty(result, collectionKey); | |
| 76 | List tmp2 = new ArrayList(); | |
| 77 | for (int j = 0; j < tmp.keySet().size(); j++) { | |
| 78 | tmp2.add(tmp.get("" + j)); | |
| 79 | } | |
| 80 | PropertyUtils.setProperty(result, collectionKey, tmp2); | |
| 81 | } | |
| 82 | return result; | |
| 83 | } catch (Exception e) { | |
| 84 | throw new RuntimeException(); | |
| 85 | } | |
| 81 | 86 | } |
| 82 | 87 | |
| 83 | 88 | public void write(Map<String, Object> input, OutputStream output) { |
| 84 | // TODO implement the storing properties in the same manner | |
| 85 | // if (obj1 instanceof Map) { | |
| 86 | // for (Object key : ((Map<? extends String, ? extends Object>) obj1).keySet()) { | |
| 87 | // if (!ignore.contains(key)) { | |
| 88 | // assertEquals(key.toString(), ((Map<String, Object>) obj1).get(key), ((Map<String, Object>) obj2).get(key), ignore); | |
| 89 | // } | |
| 90 | // } | |
| 91 | // } else if (obj1 instanceof List) { | |
| 92 | // List list1 = (List) obj1; | |
| 93 | // List list2 = (List) obj2; | |
| 94 | // for (int i = 0; i < list2.size(); i++) { | |
| 95 | // if (!ignore.contains(name)) { | |
| 96 | // Object el1 = list1.get(i); | |
| 97 | // Object el2 = list2.get(i); | |
| 98 | // assertEquals(name + "[" + i + "]", el1, el2, ignore); | |
| 99 | // } | |
| 100 | // } | |
| 101 | // } else { | |
| 102 | // if(!ignore.contains(name)){ | |
| 103 | // if(obj1 instanceof Double || obj2 instanceof Double){ | |
| 104 | // Assert.assertEquals(name + " are not equal", Double.parseDouble(String.valueOf(obj1)), Double.parseDouble(String.valueOf(obj2))); | |
| 105 | // } else { | |
| 106 | // Assert.assertEquals(name + " are not equal", String.valueOf(obj1), String.valueOf(obj2)); | |
| 107 | // } | |
| 108 | // | |
| 109 | // } | |
| 110 | // } | |
| 89 | try { | |
| 90 | write("swf", input, output); | |
| 91 | } catch (IOException e) { | |
| 92 | e.printStackTrace(); | |
| 93 | } | |
| 94 | } | |
| 95 | ||
| 96 | public void write(String prefix, Object obj1, OutputStream output) throws IOException { | |
| 97 | if (obj1 instanceof Map) { | |
| 98 | for (Iterator iterator1 = ((Map) obj1).keySet().iterator(); iterator1.hasNext();) { | |
| 99 | String key = (String) iterator1.next(); | |
| 100 | Object obj2 = ((Map) obj1).get(key); | |
| 101 | write(prefix + "." + key, obj2, output); | |
| 102 | } | |
| 103 | } else if (obj1 instanceof List) { | |
| 104 | int i = 0; | |
| 105 | for (Iterator iterator2 = ((List) obj1).iterator(); iterator2.hasNext(); i++) { | |
| 106 | Object obj2 = (Object) iterator2.next(); | |
| 107 | write(prefix + "." + i, obj2, output); | |
| 108 | } | |
| 109 | } else { | |
| 110 | output.write((prefix + "=" + obj1 + "\n").getBytes()); | |
| 111 | } | |
| 112 | // if (obj1 instanceof Map) { | |
| 113 | // for (Object key : ((Map<? extends String, ? extends Object>) | |
| 114 | // obj1).keySet()) { | |
| 115 | // if (!ignore.contains(key)) { | |
| 116 | // assertEquals(key.toString(), ((Map<String, Object>) obj1).get(key), | |
| 117 | // ((Map<String, Object>) obj2).get(key), ignore); | |
| 118 | // } | |
| 119 | // } | |
| 120 | // } else if (obj1 instanceof List) { | |
| 121 | // List list1 = (List) obj1; | |
| 122 | // List list2 = (List) obj2; | |
| 123 | // for (int i = 0; i < list2.size(); i++) { | |
| 124 | // if (!ignore.contains(name)) { | |
| 125 | // Object el1 = list1.get(i); | |
| 126 | // Object el2 = list2.get(i); | |
| 127 | // assertEquals(name + "[" + i + "]", el1, el2, ignore); | |
| 128 | // } | |
| 129 | // } | |
| 130 | // } else { | |
| 131 | // if(!ignore.contains(name)){ | |
| 132 | // if(obj1 instanceof Double || obj2 instanceof Double){ | |
| 133 | // Assert.assertEquals(name + " are not equal", | |
| 134 | // Double.parseDouble(String.valueOf(obj1)), | |
| 135 | // Double.parseDouble(String.valueOf(obj2))); | |
| 136 | // } else { | |
| 137 | // Assert.assertEquals(name + " are not equal", String.valueOf(obj1), | |
| 138 | // String.valueOf(obj2)); | |
| 139 | // } | |
| 140 | // | |
| 141 | // } | |
| 142 | // } | |
| 111 | 143 | |
| 112 | 144 | } |
| 113 | 145 |
| ... | ...@@ -2,7 +2,7 @@ | |
| 2 | 2 | <type name="SetBackgroundColor"> |
| 3 | 3 | <field type="RGB" name="backgroundColor"/> |
| 4 | 4 | </type> |
| 5 | ||
| 5 | <!-- | |
| 6 | 6 | <type name="DefineShape"> |
| 7 | 7 | <field type="NONE" autocalculated="true" name="defineShapeVersion" value="1"/> |
| 8 | 8 | <field type="UI16" name="shapeId"/> |
| ... | ...@@ -21,7 +21,7 @@ | |
| 21 | 21 | <field type="RECT" name="shapeBounds"/> |
| 22 | 22 | <field type="SHAPEWITHSTYLE" name="shapes"/> |
| 23 | 23 | </type> |
| 24 | <!-- TODO DefineShape4 --> | |
| 24 | --> | |
| 25 | 25 | <type name="PlaceObject"> |
| 26 | 26 | <field type="NONE" autocalculated="true" name="placeObjectVersion" value="1"/> |
| 27 | 27 | <field type="UI16" name="shapeId"/> |
| ... | ...@@ -29,6 +29,7 @@ | |
| 29 | 29 | <field type="MATRIX" name="placeMatrix"/> |
| 30 | 30 | <field type="CXFORM" name="placeColorTransform"/> |
| 31 | 31 | </type> |
| 32 | ||
| 32 | 33 | <!-- TODO PlaceObject2, PlaceObject3 --> |
| 33 | 34 | <type name="End"> |
| 34 | 35 | </type> |
| ... | ...@@ -135,5 +135,9 @@ | |
| 135 | 135 | throw new IllegalStateException(MessageFormat.format("type \"{0}\" is unknown", name)); |
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | ||
| 139 | public static boolean isSupportedStructure(String name) { | |
| 140 | return StructureEnv.getInstance().getTypes().containsKey(name); | |
| 141 | } | |
| 138 | 142 | |
| 139 | 143 | } |
| ... | ...@@ -0,0 +1,82 @@ | |
| 1 | package com.flanderra.commons.swfio.impl; | |
| 2 | ||
| 3 | import java.io.IOException; | |
| 4 | import java.io.InputStream; | |
| 5 | import java.io.OutputStream; | |
| 6 | import java.util.Map; | |
| 7 | ||
| 8 | import org.apache.commons.logging.Log; | |
| 9 | import org.apache.commons.logging.LogFactory; | |
| 10 | ||
| 11 | import com.flanderra.commons.struct.StructureFormatIOUtils; | |
| 12 | import com.flanderra.commons.swfio.SWFIO; | |
| 13 | import com.flanderra.commons.swfio.SWFIOException; | |
| 14 | import com.flanderra.commons.xmlstub.IStubUtil; | |
| 15 | import com.flanderra.commons.xmlstub.PropertiesStubUtil; | |
| 16 | import com.flanderra.commons.xmlstub.XMLStubUtil; | |
| 17 | ||
| 18 | /** | |
| 19 | * {@inheritDoc} | |
| 20 | */ | |
| 21 | public class SWFIOImpl implements SWFIO { | |
| 22 | private static final IStubUtil stubUtil = PropertiesStubUtil.getInstance(); | |
| 23 | private static final Log logger = LogFactory.getLog(SWFIOImpl.class); | |
| 24 | ||
| 25 | /** | |
| 26 | * {@inheritDoc} | |
| 27 | */ | |
| 28 | public void compileSWF(InputStream input, OutputStream output) throws SWFIOException { | |
| 29 | try { | |
| 30 | logger.debug("about to read the SWF structure from input stream..."); | |
| 31 | Map<String, Object> parsedSWF = stubUtil.read(input); | |
| 32 | logger.debug("the SWF structure successfully read from input stream"); | |
| 33 | logger.debug("starting compilation..."); | |
| 34 | byte[] bytes = StructureFormatIOUtils.formatSWF(parsedSWF); | |
| 35 | logger.debug("compilation successfully done"); | |
| 36 | logger.debug("starting outing bytes to output..."); | |
| 37 | output.write(bytes); | |
| 38 | logger.debug("all compilled bytes were sent to output"); | |
| 39 | } catch (Throwable e) { | |
| 40 | throw new SWFIOException("compilation failed", e); | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * {@inheritDoc} | |
| 46 | */ | |
| 47 | public void compileSWF(Map<String, Object> input, OutputStream output) throws SWFIOException { | |
| 48 | try { | |
| 49 | logger.debug("starting compilation..."); | |
| 50 | byte[] bytes = StructureFormatIOUtils.formatSWF(input); | |
| 51 | logger.debug("compilation successfully done"); | |
| 52 | logger.debug("starting outing bytes to output..."); | |
| 53 | output.write(bytes); | |
| 54 | logger.debug("all compilled bytes were sent to output"); | |
| 55 | } catch (Throwable e) { | |
| 56 | throw new SWFIOException("compilation failed", e); | |
| 57 | } | |
| 58 | } | |
| 59 | ||
| 60 | /** | |
| 61 | * {@inheritDoc} | |
| 62 | */ | |
| 63 | public Map<String, Object> parseSWF(InputStream input) throws SWFIOException { | |
| 64 | logger.debug("starting parsing binary SWF..."); | |
| 65 | Map<String, Object> result = StructureFormatIOUtils.parseSWF(input); | |
| 66 | logger.debug("parsing binary SWF done succesfully"); | |
| 67 | return result; | |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * {@inheritDoc} | |
| 72 | */ | |
| 73 | public void parseSWF(InputStream input, OutputStream output) throws SWFIOException { | |
| 74 | logger.debug("starting parsing binary SWF..."); | |
| 75 | Map<String, Object> result = StructureFormatIOUtils.parseSWF(input); | |
| 76 | logger.debug("parsing binary SWF done succesfully"); | |
| 77 | logger.debug("starting generation of XML stub..."); | |
| 78 | stubUtil.write(result, output); | |
| 79 | logger.debug("generation of XML stub done succesfully"); | |
| 80 | } | |
| 81 | ||
| 82 | } |
| ... | ...@@ -1,81 +0,0 @@ | |
| 1 | package com.flanderra.commons.swfio.impl; | |
| 2 | ||
| 3 | import java.io.IOException; | |
| 4 | import java.io.InputStream; | |
| 5 | import java.io.OutputStream; | |
| 6 | import java.util.Map; | |
| 7 | ||
| 8 | import org.apache.commons.logging.Log; | |
| 9 | import org.apache.commons.logging.LogFactory; | |
| 10 | ||
| 11 | import com.flanderra.commons.struct.StructureFormatIOUtils; | |
| 12 | import com.flanderra.commons.swfio.SWFIO; | |
| 13 | import com.flanderra.commons.swfio.SWFIOException; | |
| 14 | import com.flanderra.commons.xmlstub.IStubUtil; | |
| 15 | import com.flanderra.commons.xmlstub.XMLStubUtil; | |
| 16 | ||
| 17 | /** | |
| 18 | * {@inheritDoc} | |
| 19 | */ | |
| 20 | public class SWIFOImpl implements SWFIO { | |
| 21 | private static final IStubUtil stubUtil = XMLStubUtil.getInstance(); | |
| 22 | private static final Log logger = LogFactory.getLog(SWIFOImpl.class); | |
| 23 | ||
| 24 | /** | |
| 25 | * {@inheritDoc} | |
| 26 | */ | |
| 27 | public void compileSWF(InputStream input, OutputStream output) throws SWFIOException { | |
| 28 | try { | |
| 29 | logger.debug("about to read the SWF structure from input stream..."); | |
| 30 | Map<String, Object> parsedSWF = stubUtil.read(input); | |
| 31 | logger.debug("the SWF structure successfully read from input stream"); | |
| 32 | logger.debug("starting compilation..."); | |
| 33 | byte[] bytes = StructureFormatIOUtils.formatSWF(parsedSWF); | |
| 34 | logger.debug("compilation successfully done"); | |
| 35 | logger.debug("starting outing bytes to output..."); | |
| 36 | output.write(bytes); | |
| 37 | logger.debug("all compilled bytes were sent to output"); | |
| 38 | } catch (Throwable e) { | |
| 39 | throw new SWFIOException("compilation failed", e); | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * {@inheritDoc} | |
| 45 | */ | |
| 46 | public void compileSWF(Map<String, Object> input, OutputStream output) throws SWFIOException { | |
| 47 | try { | |
| 48 | logger.debug("starting compilation..."); | |
| 49 | byte[] bytes = StructureFormatIOUtils.formatSWF(input); | |
| 50 | logger.debug("compilation successfully done"); | |
| 51 | logger.debug("starting outing bytes to output..."); | |
| 52 | output.write(bytes); | |
| 53 | logger.debug("all compilled bytes were sent to output"); | |
| 54 | } catch (Throwable e) { | |
| 55 | throw new SWFIOException("compilation failed", e); | |
| 56 | } | |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * {@inheritDoc} | |
| 61 | */ | |
| 62 | public Map<String, Object> parseSWF(InputStream input) throws SWFIOException { | |
| 63 | logger.debug("starting parsing binary SWF..."); | |
| 64 | Map<String, Object> result = StructureFormatIOUtils.parseSWF(input); | |
| 65 | logger.debug("parsing binary SWF done succesfully"); | |
| 66 | return result; | |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * {@inheritDoc} | |
| 71 | */ | |
| 72 | public void parseSWF(InputStream input, OutputStream output) throws SWFIOException { | |
| 73 | logger.debug("starting parsing binary SWF..."); | |
| 74 | Map<String, Object> result = StructureFormatIOUtils.parseSWF(input); | |
| 75 | logger.debug("parsing binary SWF done succesfully"); | |
| 76 | logger.debug("starting generation of XML stub..."); | |
| 77 | stubUtil.write(result, output); | |
| 78 | logger.debug("generation of XML stub done succesfully"); | |
| 79 | } | |
| 80 | ||
| 81 | } |
| ... | ...@@ -1,5 +1,7 @@ | |
| 1 | 1 | package com.flanderra.commons.test.swfinfo; |
| 2 | 2 | |
| 3 | import com.flanderra.commons.swfio.SWFIO; | |
| 4 | import com.flanderra.commons.swfio.impl.SWFIOImpl; | |
| 3 | 5 | import com.flanderra.commons.utils.SWFInfo; |
| 4 | 6 | |
| 5 | 7 | import java.io.File; |
| ... | ...@@ -16,7 +18,7 @@ | |
| 16 | 18 | try { |
| 17 | 19 | File srcFile = new File("com/flanderra/commons/test/test1.swf"); |
| 18 | 20 | InputStream is = new FileInputStream(srcFile); |
| 19 | SWFInfo.outputInfo(is, System.out); | |
| 21 | new SWFIOImpl().parseSWF(is, System.out); | |
| 20 | 22 | |
| 21 | 23 | } catch (Exception e) { |
| 22 | 24 | e.printStackTrace(); |