| 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"); |
|---|