Changeset 1488cd0
- Timestamp:
- Dec 17, 2011 1:52:32 PM (9 years ago)
- Branches:
- master
- Children:
- bf45e31
- Parents:
- 5b05d86
- Location:
- apps/i2psnark/java/src/org/klomp/snark
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/i2psnark/java/src/org/klomp/snark/Storage.java
r5b05d86 r1488cd0 24 24 import java.io.IOException; 25 25 import java.io.RandomAccessFile; 26 import java.nio.charset.Charset; 27 import java.nio.charset.CharsetEncoder; 26 28 import java.security.MessageDigest; 27 29 import java.util.ArrayList; 28 30 import java.util.Iterator; 29 31 import java.util.List; 32 import java.util.Map; 30 33 import java.util.StringTokenizer; 34 import java.util.concurrent.ConcurrentHashMap; 31 35 32 36 import net.i2p.crypto.SHA1; … … 67 71 public static final int MAX_PIECES = 10*1024; 68 72 public static final long MAX_TOTAL_SIZE = MAX_PIECE_SIZE * (long) MAX_PIECES; 73 74 private static final Map<String, String> _filterNameCache = new ConcurrentHashMap(); 69 75 70 76 /** … … 569 575 * Removes 'suspicious' characters from the given file name. 570 576 * http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx 577 * Then replace chars not supported in the charset. 578 * 579 * This is called frequently and it can be pretty slow so cache the result. 580 * 581 * TODO: If multiple files in the same torrent map to the same filter name, 582 * the whole torrent will blow up. Check at torrent creation? 571 583 */ 572 584 public static String filterName(String name) 573 585 { 574 if (name.equals(".") || name.equals(" ")) 575 return "_"; 576 String rv = name; 577 if (rv.startsWith(".")) 578 rv = '_' + rv.substring(1); 579 if (rv.endsWith(".") || rv.endsWith(" ")) 580 rv = rv.substring(0, rv.length() - 1) + '_'; 581 for (int i = 0; i < ILLEGAL.length; i++) { 582 if (rv.indexOf(ILLEGAL[i]) >= 0) 583 rv = rv.replace(ILLEGAL[i], '_'); 584 } 586 String rv = _filterNameCache.get(name); 587 if (rv != null) 588 return rv; 589 if (name.equals(".") || name.equals(" ")) { 590 rv = "_"; 591 } else { 592 rv = name; 593 if (rv.startsWith(".")) 594 rv = '_' + rv.substring(1); 595 if (rv.endsWith(".") || rv.endsWith(" ")) 596 rv = rv.substring(0, rv.length() - 1) + '_'; 597 for (int i = 0; i < ILLEGAL.length; i++) { 598 if (rv.indexOf(ILLEGAL[i]) >= 0) 599 rv = rv.replace(ILLEGAL[i], '_'); 600 } 601 // Replace characters not supported in the charset 602 if (!Charset.defaultCharset().name().equals("UTF-8")) { 603 try { 604 CharsetEncoder enc = Charset.defaultCharset().newEncoder(); 605 if (!enc.canEncode(rv)) { 606 String repl = rv; 607 for (int i = 0; i < rv.length(); i++) { 608 char c = rv.charAt(i); 609 if (!enc.canEncode(c)) 610 repl = repl.replace(c, '_'); 611 } 612 rv = repl; 613 } 614 } catch (Exception ex) { 615 ex.printStackTrace(); 616 } 617 } } 618 _filterNameCache.put(name, rv); 585 619 return rv; 586 620 } -
apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java
r5b05d86 r1488cd0 1760 1760 //buf.append("<br>").append(_("Maggot link")).append(": <a href=\"").append(MAGGOT).append(hex).append(':').append(hex).append("\">") 1761 1761 // .append(MAGGOT).append(hex).append(':').append(hex).append("</a>"); 1762 buf.append("<br>").append(_("Torrent file")).append(": ").append(snark.getName()); 1762 1763 buf.append("</div></th></tr>"); 1763 1764 }
Note: See TracChangeset
for help on using the changeset viewer.