Author: dda
Date: 2008-01-07 11:11:26 -0800 (Mon, 07 Jan 2008)
New Revision: 7758

Modified:
   
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
Log:
Change 20080107-dda-e by [EMAIL PROTECTED] on 2008-01-07 14:03:26 EST
    in /Users/dda/laszlo/src/svn/openlaszlo/branches/devildog
    for http://svn.openlaszlo.org/openlaszlo/branches/devildog

Summary: SWF9: Fix binary file reading code so that .swc file is copied 
correctly.

New Features:

Bugs Fixed: LPP-5234

Technical Reviewer: ptw (pending)
QA Reviewer: hminsky (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
  Initial code to create an internal array from a produced .SWC or .SWF file 
was wrong
  and besides, needlessly complicated.  This version is easier and appears to 
work.
    

Tests:
  Run ./buildlfc and the produced .SWC file in the temporary compilation 
staging directory
  is identical to the .LZL file created by the script.



Modified: 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
===================================================================
--- 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
    2008-01-07 19:11:03 UTC (rev 7757)
+++ 
openlaszlo/branches/devildog/WEB-INF/lps/server/src/org/openlaszlo/sc/SWF9Generator.java
    2008-01-07 19:11:26 UTC (rev 7758)
@@ -230,42 +230,38 @@
   public byte[] getBytes(String filename)
     throws IOException
   {
+    File f = new File(filename);
+    long len = f.length();
+
+    // Passing around byte arrays has limitations.
+    if (len > Integer.MAX_VALUE)
+      throw new IOException(filename + ": output too large");
+
+    byte[] result = new byte[(int)len];
+    int pos = 0;
+
     FileInputStream fis = null;
     try {
       fis = new FileInputStream(filename);
-      return getBytes(fis);
+      while (pos < len) {
+        int nbytes = fis.read(result, pos, (int)len - pos);
+        if (nbytes < 0) {
+          // premature end of file.  File.length() lied or the
+          // length of the file changed out from under us.
+          // Either way, we cannot trust it.
+          throw new IOException(filename + ": file size discrepency byte " +
+                                pos + "/" + len);
+        }
+        pos += nbytes;
+      }
+      // Sanity check, make sure file hasn't been appended to
+      if (fis.read() != -1)
+        throw new IOException(filename + ": file growing during read at byte " 
+
+                              pos);
     }
     finally {
       closeit(fis);
     }
-  }
-
-  public byte[] getBytes(InputStream is)
-    throws IOException
-  {
-    ArrayList chunks = new ArrayList();
-    int chunksize = 1000;
-    int total = 0;
-    byte[] chunk = new byte[chunksize];
-    int rdval;
-    while ((rdval = is.read(chunk)) > 0) {
-      if (rdval < chunksize) {
-        byte[] smaller = new byte[rdval];
-        System.arraycopy(chunk, 0, smaller, 0, rdval);
-        chunks.add(smaller);
-      }
-      else {
-        chunks.add(chunk);
-      }
-      total += rdval;
-    }
-    byte[] result = new byte[total];
-    int pos = 0;
-    for (Iterator iter = chunks.iterator(); iter.hasNext(); ) {
-      chunk = (byte[])iter.next();
-      System.arraycopy(chunk, 0, result, pos, chunk.length);
-      pos += chunk.length;
-    }
     return result;
   }
 


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to