Changeset 17984
- Timestamp:
- 2008-11-29T21:56:11+13:00 (15 years ago)
- Location:
- release-kits/shared/ant-installer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
release-kits/shared/ant-installer/src/org/tp23/antinstaller/selfextract/SelfExtractor.java
r17897 r17984 25 25 import java.io.IOException; 26 26 import java.net.URL; 27 import java.net.URLDecoder; 27 28 import java.util.ArrayList; 28 29 import java.util.jar.JarEntry; … … 73 74 //String fileForm = jarUrl.getFile(); 74 75 75 76 /*77 File file = new File( fileForm );78 if ( !file.exists() ) {79 throw new RuntimeException( "Failed expanding Jar.\n File: '" + file.getAbsolutePath() + "'\nString: '" + stringForm + "'" );80 }81 return file;82 */83 84 76 File file = null; 85 77 int endIdx = stringForm.indexOf("!/"); 86 if( endIdx == -1 ) { 87 throw new RuntimeException("Failed expanding Jar."); 88 } 89 String unescaped = null; 90 String fileNamePart = stringForm.substring("jar:file:".length(), endIdx); 91 file = new File(fileNamePart); 92 file = new File( file.getName() ); 93 94 /* 95 if ( !file.exists()) { 96 // try to unescape encase the URL Handler has escaped the " " to %20 97 unescaped = unescape(fileNamePart); 98 file = new File(unescaped); 99 } 100 */ 101 return file; 102 78 if(endIdx != -1){ 79 String unescaped = null; 80 String fileNamePart = stringForm.substring("jar:file:".length(), endIdx); 81 file = new File(fileNamePart); 82 if ( ! file.exists()) { 83 // try to unescape encase the URL Handler has escaped the " " to %20 84 unescaped = unescape(fileNamePart); 85 file = new File(unescaped); 86 } 87 return file; 88 } 89 throw new RuntimeException("Failed expanding Jar."); 103 90 } 104 91 … … 465 452 */ 466 453 private static String unescape(final String s) { 467 StringBuffer sb = new StringBuffer(s.length()); 468 469 for (int i = 0; i < s.length(); i++) { 470 char c = s.charAt(i); 471 switch (c) { 472 case '%': { 473 try { 474 sb.append( (char) Integer.parseInt(s.substring(i + 1, i + 3), 16)); 475 i += 2; 476 break; 477 } 478 catch (NumberFormatException nfe) { 479 throw new IllegalArgumentException(); 480 } 481 catch (StringIndexOutOfBoundsException siob) { 482 String end = s.substring(i); 483 sb.append(end); 484 if (end.length() == 2) i++; 485 } 486 break; 487 } 488 default: { 489 sb.append(c); 490 break; 491 } 492 } 493 } 494 return sb.toString(); 454 455 URLDecoder ud = new URLDecoder(); 456 457 String decoded = null; 458 459 try { 460 decoded = ud.decode( s, "UTF-8" ); 461 } catch ( java.io.UnsupportedEncodingException uee ) { 462 System.err.println( "unsupported encoding" ); 463 return s; 464 } 465 return decoded; 495 466 } 496 467
Note:
See TracChangeset
for help on using the changeset viewer.