@Test public void shouldHash255ASCIICharsWithLongOriginalExtension() { final String extension = ".gz"; char[] chars = new char[255 - extension.length()]; Arrays.fill(chars, 'B'); chars[32] = '.'; String filename = new String(chars); String newName = TandemFilename.join(filename, extension); final String expected = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB.BBBBBBBBBB" + "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + "pVBqc9SOArO6qf3shKWndZ05harxS-tqnmQkev_mxmY=.gz"; assertEquals("256 ASCII characters + 2 extensions", 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);  }