@Test public void shouldHashUnicodeOf255UTF8Bytes() { final String extension = ".zip"; String filename = "Лоремипсумдолорситаметаппетерепатриояуеелояуентиа" + "меуяуиетомнисанималсцрипторемсеаутвидитсолутаусуЯуиеусусцип" + "итеррорибусприер.cs"; byte[] uFilename = filename.getBytes(StandardCharsets.UTF_8); assertEquals(filename + " as UTF-8, length", 251, uFilename.length); String newName = TandemFilename.join(filename, extension); String expected = "Лоремипсумдолорситаметаппетерепатриояуеелояуентиа" + "меуяуиетомнисанималсцрипторемсеаутвидитсолутаусуЯуиеу" + "8Veko6G0h8wci2kX60EisTi4ReksNP1wdTLhbuB-5Vw=.cs.zip"; assertEquals("Unicode + new extension", expected, newName); byte[] newBytes = newName.getBytes(StandardCharsets.UTF_8); assertEquals("Should use all 255 bytes", 255, newBytes.length); }
public static String join(String filename, String asciiExtension) { File file = new File(filename); if (file.getParent() != null) { throw new IllegalArgumentException("filename can't have parent"); } if (filename.length() * 4 + asciiExtension.length() <= MAX_CAT_BYTES) { return filename + asciiExtension; } return maybePackSha(filename, asciiExtension); }
TandemFilename { public static String join(String filename, String asciiExtension) { File file = new File(filename); if (file.getParent() != null) { throw new IllegalArgumentException("filename can't have parent"); } if (filename.length() * 4 + asciiExtension.length() <= MAX_CAT_BYTES) { return filename + asciiExtension; } return maybePackSha(filename, asciiExtension); } }
TandemFilename { public static String join(String filename, String asciiExtension) { File file = new File(filename); if (file.getParent() != null) { throw new IllegalArgumentException("filename can't have parent"); } if (filename.length() * 4 + asciiExtension.length() <= MAX_CAT_BYTES) { return filename + asciiExtension; } return maybePackSha(filename, asciiExtension); } private  TandemFilename(); }
TandemFilename { public static String join(String filename, String asciiExtension) { File file = new File(filename); if (file.getParent() != null) { throw new IllegalArgumentException("filename can't have parent"); } if (filename.length() * 4 + asciiExtension.length() <= MAX_CAT_BYTES) { return filename + asciiExtension; } return maybePackSha(filename, asciiExtension); } private  TandemFilename(); static String join(String filename, String asciiExtension); }
TandemFilename { public static String join(String filename, String asciiExtension) { File file = new File(filename); if (file.getParent() != null) { throw new IllegalArgumentException("filename can't have parent"); } if (filename.length() * 4 + asciiExtension.length() <= MAX_CAT_BYTES) { return filename + asciiExtension; } return maybePackSha(filename, asciiExtension); } private  TandemFilename(); static String join(String filename, String asciiExtension);  }