Changeset 186

Show
Ignore:
Timestamp:
03/09/08 16:31:32 (10 months ago)
Author:
Stuart Thiel
Message:

-Fixed #155

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • MediAnnotate/trunk/src/org/mediannotate/dom/QTMovie.java

    r177 r186  
    1010import java.net.URL; 
    1111import java.net.URLDecoder; 
     12import java.util.HashMap; 
    1213 
    1314import org.mediannotate.app.MAController; 
     
    3031        private long outTime; 
    3132        private boolean startedPlayingAfterOutTime; 
     33        private static HashMap<String, File> knownFiles = new HashMap<String, File>(); 
    3234         
    3335        public QTMovie(String url) { 
     
    3537                 
    3638                try { 
     39                        String original_url = url; 
    3740                         
    3841                        File f = null; 
    3942 
    40  
    41                         f = new File(URLDecoder.decode(url, "UTF-8").replaceAll("file:\\\\*(.*)", "$1")); 
    42  
    43                         if(!f.exists()) { 
    44                                 url = new URL(url).toExternalForm(); 
    45                  
    46                                 URL myURL = new URL(url); 
    47                                 f = File.createTempFile("VA_", url.replaceFirst("^(.*)(\\..*)$", "$2")); 
    48                                 f.deleteOnExit(); 
    49                                 MediAnnotater.tempFiles.add(f); 
    50                                  
    51                                 BufferedInputStream bis = new BufferedInputStream(myURL.openStream()); 
    52                                 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f)); 
    53                                 byte[] myBytes = new byte[1024*1024]; 
    54                                 int myByteCount = bis.read(myBytes); 
    55                                 int totalCount = myByteCount; 
    56                                 while(myByteCount != -1) { 
    57                                         System.out.println("We've read: " + totalCount); 
    58                                         bos.write(myBytes, 0, myByteCount); 
    59                                         myByteCount = bis.read(myBytes); 
    60                                         totalCount += myByteCount; 
     43                        if(knownFiles.containsKey(original_url)) { 
     44                                f = knownFiles.get(original_url); 
     45                        } else { 
     46                         
     47                                f = new File(URLDecoder.decode(url, "UTF-8").replaceAll("file:\\\\*(.*)", "$1")); 
     48         
     49                                if(!f.exists()) { 
     50                                        url = new URL(url).toExternalForm(); 
     51                         
     52                                        URL myURL = new URL(url); 
     53                                        f = File.createTempFile("vertov_", url.replaceFirst("^(.*)(\\..*)$", "$2")); 
     54                                        f.deleteOnExit(); 
     55                                        MediAnnotater.tempFiles.add(f); 
     56                                         
     57                                        BufferedInputStream bis = new BufferedInputStream(myURL.openStream()); 
     58                                        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f)); 
     59                                        byte[] myBytes = new byte[1024*1024]; 
     60                                        int myByteCount = bis.read(myBytes); 
     61                                        int totalCount = myByteCount; 
     62                                        while(myByteCount != -1) { 
     63                                                System.out.println("We've read: " + totalCount); 
     64                                                bos.write(myBytes, 0, myByteCount); 
     65                                                myByteCount = bis.read(myBytes); 
     66                                                totalCount += myByteCount; 
     67                                        } 
     68                                        System.out.println("We've finished loading the file"); 
     69                         
     70                                        bos.flush(); 
     71                                        bos.close(); 
     72                                        bis.close(); 
     73                                        url = f.getAbsolutePath().replaceFirst("^file:/([^/])", "file://$1"); 
    6174                                } 
    62                                 System.out.println("We've finished loading the file"); 
    63                  
    64                                 bos.flush(); 
    65                                 bos.close(); 
    66                                 bis.close(); 
    67                                 url = f.getAbsolutePath().replaceFirst("^file:/([^/])", "file://$1"); 
     75                                knownFiles.put(original_url, f); 
    6876                        } 
    6977                        innerMovie = quicktime.std.movies.Movie.fromFile(