IdUtil { public static void validateContentId(String contentID) throws InvalidIdException { if (contentID == null) { String err = "Content ID must be at least 1 character long"; throw new InvalidIdException(err); } if (contentID.contains("?")) { String err = "Content ID may not include the '?' character"; throw new InvalidIdException(err); } if (contentID.contains("\\")) { String err = "Content ID may not include the '\\' character"; throw new InvalidIdException(err); } int utfLength; int urlLength; try { utfLength = contentID.getBytes("UTF-8").length; String urlEncoded = URLEncoder.encode(contentID, "UTF-8"); urlLength = urlEncoded.getBytes("UTF-8").length; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } if (utfLength > 1024 || urlLength > 1024) { String err = "Content ID must <= 1024 bytes after URL and UTF-8 encoding"; throw new InvalidIdException(err); } } private  IdUtil(); static void validateSpaceId(String spaceID); static void validateContentId(String contentID); static void validateStoreId(String storeId);  }
@Test public void testContentIds() throws Exception { String id = "test?content"; checkInvalidContentId(id); id = "test\\content"; checkInvalidContentId(id); id = "test-content"; while (id.getBytes().length <= 1024) { id += "test-content"; } checkInvalidContentId(id); id = "test-content-~!@#$%^&*()_+=-`;':/.,<>\"[]{}| "; IdUtil.validateContentId(id); }