mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-05 16:05:09 +00:00
always use buffered output streams when writing to a file, faster swf xml export by caching the fields
This commit is contained in:
@@ -106,10 +106,12 @@ import com.jpexs.decompiler.graph.model.TernarOpItem;
|
||||
import com.jpexs.decompiler.graph.model.UnboundedTypeItem;
|
||||
import com.jpexs.decompiler.graph.model.WhileItem;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -2429,7 +2431,7 @@ public class ActionScriptParser {
|
||||
ABC abc = new ABC(null);
|
||||
ActionScriptParser parser = new ActionScriptParser(abc, playerABCs);
|
||||
parser.addScript(new String(Helper.readFile(src), "UTF-8"), true, src, classPos);
|
||||
try (FileOutputStream fos = new FileOutputStream(new File(dst))) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(dst)))) {
|
||||
abc.saveToStream(fos);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -24,9 +24,11 @@ import com.jpexs.decompiler.flash.exporters.settings.BinaryDataExportSettings;
|
||||
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.helpers.Path;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -69,7 +71,7 @@ public class BinaryDataExporter {
|
||||
new RetryTask(new RunnableIOEx() {
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
fos.write(((DefineBinaryDataTag) t).binaryData.getRangeData());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,12 @@ import com.jpexs.helpers.Path;
|
||||
import fontastic.FGlyph;
|
||||
import fontastic.FPoint;
|
||||
import fontastic.Fontastic;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -279,7 +281,7 @@ public class FontExporter {
|
||||
|
||||
Font font = fontArray[0];
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
WoffWriter w = new WoffWriter();
|
||||
WritableFontData woffData = w.convert(font);
|
||||
woffData.copyTo(fos);
|
||||
|
||||
@@ -61,10 +61,12 @@ import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.print.PageFormat;
|
||||
import java.awt.print.Paper;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -160,7 +162,7 @@ public class FrameExporter {
|
||||
public void run() throws IOException {
|
||||
int frame = fframes.get(fi);
|
||||
File f = new File(foutdir + File.separator + frame + ".svg");
|
||||
try (FileOutputStream fos = new FileOutputStream(f)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(f))) {
|
||||
ExportRectangle rect = new ExportRectangle(tim.displayRect);
|
||||
rect.xMax *= settings.zoom;
|
||||
rect.yMax *= settings.zoom;
|
||||
@@ -204,7 +206,7 @@ public class FrameExporter {
|
||||
File fmin = new File(foutdir + File.separator + "frames.min.js");
|
||||
int width = (int) (ftim.displayRect.getWidth() * settings.zoom / SWF.unitDivisor);
|
||||
int height = (int) (ftim.displayRect.getHeight() * settings.zoom / SWF.unitDivisor);
|
||||
try (FileOutputStream fos = new FileOutputStream(f)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(f))) {
|
||||
fos.write(Utf8Helper.getBytes("\r\n"));
|
||||
Set<Integer> library = new HashSet<>();
|
||||
ftim.getNeededCharacters(fframes, library);
|
||||
@@ -274,7 +276,7 @@ public class FrameExporter {
|
||||
}
|
||||
|
||||
File fh = new File(foutdir + File.separator + "frames.html");
|
||||
try (FileOutputStream fos = new FileOutputStream(fh); FileInputStream fis = new FileInputStream(fmin)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(fh)); FileInputStream fis = new FileInputStream(fmin)) {
|
||||
fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getHtmlPrefix(width, height)));
|
||||
fos.write(Utf8Helper.getBytes(CanvasShapeExporter.getJsPrefix()));
|
||||
byte[] buf = new byte[1000];
|
||||
@@ -380,7 +382,7 @@ public class FrameExporter {
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
File f = new File(foutdir + File.separator + "frames.pdf");
|
||||
PDFJob job = new PDFJob(new FileOutputStream(f));
|
||||
PDFJob job = new PDFJob(new BufferedOutputStream(new FileOutputStream(f)));
|
||||
PageFormat pf = new PageFormat();
|
||||
pf.setOrientation(PageFormat.PORTRAIT);
|
||||
Paper p = new Paper();
|
||||
|
||||
@@ -34,10 +34,12 @@ import com.jpexs.decompiler.flash.types.CXFORMWITHALPHA;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.Path;
|
||||
import com.jpexs.helpers.utf8.Utf8Helper;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -90,7 +92,7 @@ public class MorphShapeExporter {
|
||||
MorphShapeTag mst = (MorphShapeTag) t;
|
||||
switch (settings.mode) {
|
||||
case SVG:
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
ExportRectangle rect = new ExportRectangle(mst.getRect());
|
||||
rect.xMax *= settings.zoom;
|
||||
rect.yMax *= settings.zoom;
|
||||
@@ -102,7 +104,7 @@ public class MorphShapeExporter {
|
||||
}
|
||||
break;
|
||||
case CANVAS:
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
int deltaX = -Math.min(mst.getStartBounds().Xmin, mst.getEndBounds().Xmin);
|
||||
int deltaY = -Math.min(mst.getStartBounds().Ymin, mst.getEndBounds().Ymin);
|
||||
CanvasMorphShapeExporter cse = new CanvasMorphShapeExporter(((Tag) mst).getSwf(), mst.getShapeAtRatio(0), mst.getShapeAtRatio(DefineMorphShapeTag.MAX_RATIO), new CXFORMWITHALPHA(), SWF.unitDivisor, deltaX, deltaY);
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.VideoFrameTag;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.Path;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -80,7 +81,7 @@ public class MovieExporter {
|
||||
new RetryTask(new RunnableIOEx() {
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
fos.write(exportMovie(videoStream, settings.mode));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,10 +40,12 @@ import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.Path;
|
||||
import com.jpexs.helpers.SerializableImage;
|
||||
import com.jpexs.helpers.utf8.Utf8Helper;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -104,7 +106,7 @@ public class ShapeExporter {
|
||||
ShapeTag st = (ShapeTag) t;
|
||||
switch (settings.mode) {
|
||||
case SVG:
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
ExportRectangle rect = new ExportRectangle(st.getRect());
|
||||
rect.xMax *= settings.zoom;
|
||||
rect.yMax *= settings.zoom;
|
||||
@@ -133,7 +135,7 @@ public class ShapeExporter {
|
||||
}
|
||||
break;
|
||||
case CANVAS:
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
SHAPE shp = st.getShapes();
|
||||
int deltaX = -shp.getBounds().Xmin;
|
||||
int deltaY = -shp.getBounds().Ymin;
|
||||
|
||||
@@ -31,9 +31,11 @@ import com.jpexs.decompiler.flash.types.CXFORMWITHALPHA;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.Path;
|
||||
import com.jpexs.helpers.utf8.Utf8Helper;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -80,7 +82,7 @@ public class TextExporter {
|
||||
new RetryTask(new RunnableIOEx() {
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
ExportRectangle rect = new ExportRectangle(textTag.getRect());
|
||||
SVGExporter exporter = new SVGExporter(rect);
|
||||
textTag.toSVG(exporter, -2, new CXFORMWITHALPHA(), 0, settings.zoom);
|
||||
@@ -109,7 +111,7 @@ public class TextExporter {
|
||||
fileName = settings.mode == TextExportMode.FORMATTED ? TEXT_EXPORT_FILENAME_FORMATTED : TEXT_EXPORT_FILENAME_PLAIN;
|
||||
}
|
||||
final File file = new File(outdir + File.separator + fileName);
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
for (final Tag t : tags) {
|
||||
if (t instanceof TextTag) {
|
||||
final TextTag textTag = (TextTag) t;
|
||||
@@ -144,7 +146,7 @@ public class TextExporter {
|
||||
new RetryTask(new RunnableIOEx() {
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
if (settings.mode == TextExportMode.FORMATTED) {
|
||||
fos.write(Utf8Helper.getBytes(textTag.getFormattedText().text));
|
||||
} else {
|
||||
|
||||
@@ -24,8 +24,9 @@ import com.jpexs.decompiler.flash.types.annotations.Internal;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.ReflectionTools;
|
||||
import com.jpexs.helpers.Stopwatch;
|
||||
import com.jpexs.helpers.utf8.Utf8OutputStreamWriter;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -35,7 +36,9 @@ import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
@@ -57,15 +60,21 @@ import org.w3c.dom.Node;
|
||||
*/
|
||||
public class SwfXmlExporter {
|
||||
|
||||
private Map<Class, List<Field>> cachedFields = new HashMap<>();
|
||||
|
||||
public List<File> exportXml(SWF swf, File outFile) throws IOException {
|
||||
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||
try {
|
||||
Stopwatch sw = Stopwatch.startNew();
|
||||
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||
Document xmlDoc = docBuilder.newDocument();
|
||||
exportXml(swf, xmlDoc, xmlDoc);
|
||||
try (Writer writer = new BufferedWriter(new Utf8OutputStreamWriter(new FileOutputStream(outFile)))) {
|
||||
System.out.println(sw.getElapsedMilliseconds());
|
||||
try (Writer writer = new Utf8OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outFile)))) {
|
||||
writer.append(getXml(xmlDoc));
|
||||
}
|
||||
sw.stop();
|
||||
System.out.println(sw.getElapsedMilliseconds());
|
||||
} catch (ParserConfigurationException ex) {
|
||||
Logger.getLogger(SwfXmlExporter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
@@ -104,7 +113,17 @@ public class SwfXmlExporter {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void generateXml(Document doc, Node node, String name, Object obj, boolean isListItem, int level) {
|
||||
public List<Field> getSwfFieldsCached(Class cls) {
|
||||
List<Field> result = cachedFields.get(cls);
|
||||
if (result == null) {
|
||||
result = ReflectionTools.getSwfFields(cls);
|
||||
cachedFields.put(cls, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void generateXml(Document doc, Node node, String name, Object obj, boolean isListItem, int level) {
|
||||
Class cls = obj != null ? obj.getClass() : null;
|
||||
|
||||
if (cls == Byte.class || cls == byte.class
|
||||
@@ -163,7 +182,7 @@ public class SwfXmlExporter {
|
||||
}
|
||||
|
||||
String className = clazz.getSimpleName();
|
||||
List<Field> fields = ReflectionTools.getSwfFields(obj.getClass());
|
||||
List<Field> fields = getSwfFieldsCached(obj.getClass());
|
||||
Element objNode = doc.createElement(name);
|
||||
objNode.setAttribute("type", className);
|
||||
node.appendChild(objNode);
|
||||
|
||||
@@ -19,9 +19,11 @@ package com.jpexs.decompiler.flash.helpers;
|
||||
import java.awt.Component;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.PixelGrabber;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Adapted from
|
||||
@@ -77,7 +79,7 @@ public class BMPFile extends Component {
|
||||
private int[] bitmap;
|
||||
|
||||
//--- File section
|
||||
private FileOutputStream fo;
|
||||
private OutputStream fo;
|
||||
|
||||
//--- Private constructor
|
||||
private BMPFile() {
|
||||
@@ -85,7 +87,7 @@ public class BMPFile extends Component {
|
||||
|
||||
public static void saveBitmap(Image image, File file) throws IOException {
|
||||
BMPFile b = new BMPFile();
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
b.fo = fos;
|
||||
b.save(image, image.getWidth(null), image.getHeight(null));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package com.jpexs.decompiler.flash.helpers;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
|
||||
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
|
||||
import com.jpexs.helpers.utf8.Utf8OutputStreamWriter;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
@@ -43,7 +43,7 @@ public class FileTextWriter extends GraphTextWriter implements AutoCloseable {
|
||||
|
||||
public FileTextWriter(CodeFormatting formatting, FileOutputStream fos) {
|
||||
super(formatting);
|
||||
this.writer = new BufferedWriter(new Utf8OutputStreamWriter(fos));
|
||||
this.writer = new Utf8OutputStreamWriter(new BufferedOutputStream(fos));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.awt.Shape;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -843,9 +844,9 @@ public class Helper {
|
||||
}
|
||||
|
||||
public static void saveStream(InputStream is, File output) throws IOException {
|
||||
byte[] buf = new byte[1024];
|
||||
byte[] buf = new byte[4096];
|
||||
int cnt;
|
||||
try (FileOutputStream fos = new FileOutputStream(output)) {
|
||||
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(output))) {
|
||||
while ((cnt = is.read(buf)) > 0) {
|
||||
fos.write(buf, 0, cnt);
|
||||
fos.flush();
|
||||
|
||||
Reference in New Issue
Block a user