KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > sc > CompressFlashFile


1 /* *****************************************************************************
2  * CompressFlashFile.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.sc;
11
12 import org.openlaszlo.utils.FileUtils;
13 import org.openlaszlo.utils.StringUtils;
14 import org.openlaszlo.compiler.FontInfo;
15 import org.openlaszlo.iv.flash.api.*;
16 import org.openlaszlo.iv.flash.api.action.*;
17 import org.openlaszlo.iv.flash.api.image.*;
18 import org.openlaszlo.iv.flash.api.sound.*;
19 import org.openlaszlo.iv.flash.api.text.*;
20 import org.openlaszlo.iv.flash.util.*;
21 import org.openlaszlo.iv.flash.cache.*;
22 import org.apache.log4j.*;
23
24 import java.io.*;
25 import java.util.*;
26
27 /** Parse a flash 6 file and re-output it with flash 6 zip compression enabled
28  *
29  */

30
31 public class CompressFlashFile {
32     private static Logger mLogger = Logger.getLogger(CompressFlashFile.class);
33
34     static public void main (String JavaDoc args[]) {
35         if (args.length != 2) {
36             System.out.println("usage: compressFlashFile infile outfile");
37             System.exit(1);
38         }
39         compressFile(args[0], args[1]);
40     }
41
42     static public void compressFile (String JavaDoc infile, String JavaDoc outfile) {
43         try {
44             FlashFile f = FlashFile.parse(infile);
45             OutputStream out = new FileOutputStream(outfile);
46             FontsCollector fc = new FontsCollector();
47             HashMap fontsTable = new HashMap();
48
49             java.util.Enumeration JavaDoc defs = f.definitions();
50             while(defs.hasMoreElements()) {
51                 FlashDef def = (FlashDef)defs.nextElement();
52                 if (def instanceof FontDef) {
53                     FontDef fontDef = (FontDef)def;
54                     Font font = fontDef.getFont();
55                     String JavaDoc bold = ((font.BOLD & font.flags) > 0 ? "bold" : "");
56                     String JavaDoc italic = ((font.ITALIC & font.flags) > 0 ?
57                                      "italic" : "");
58                     //System.out.println("Copying font " + font.getFontName()
59
//+ bold + italic);
60
FontDef fdef = fc.addFont(font, null);
61                     fdef.setWriteAllChars(true);
62                     fdef.setWriteLayout(true);
63                     fontsTable.put(font.getFontName() + "::"+bold+italic, font);
64                 }
65             }
66             // Set flash 6 compression
67
f.setCompressed(true);
68             writeFlashFile(f, fc, out);
69         } catch (Exception JavaDoc e) {
70             mLogger.error("exception in CompressFlashFile.compressFile", e);
71         }
72     }
73
74     static void writeFlashFile(FlashFile f, FontsCollector fc, OutputStream out) {
75         try {
76             InputStream input;
77             input = f.generate(fc, null, false).getInputStream();
78             FileUtils.send(input, out);
79             input.close();
80             out.close();
81         } catch (Exception JavaDoc e) {
82             mLogger.error("exception in CompressFlashFile.writeFlashFile", e);
83         }
84     }
85
86 }
87
Popular Tags