@Test public void shouldHash255ASCIICharsWithShiftedExtension() { final String ext2 = ".gz"; final String ext1 = ".cpp"; char[] chars = new char[255 - ext1.length() - ext2.length()]; Arrays.fill(chars, 'B'); String filename = new String(chars) + ext1; String newName = TandemFilename.join(filename, ext2); final String expected = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" + "GfYhMFaQvXK2dbJeO9SXYHzWC2UFhNyDYXzWDP2a_5E=.cpp.gz"; assertEquals("255 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);  }