ContentName extends GenericXMLEncodable implements XMLEncodable, Comparable<ContentName>, Serializable, ContentNameProvider, Iterable<byte []> { public static ContentName fromURI(String name) throws MalformedContentNameStringException { ContentName result; if ((name == null) || (name.length() == 0)) { return ROOT; } try { if (!name.startsWith(SEPARATOR)){ if ((!name.startsWith(SCHEME + SEPARATOR)) && (!name.startsWith(ORIGINAL_SCHEME + SEPARATOR))) { throw new MalformedContentNameStringException("ContentName strings must begin with " + SEPARATOR + " or " + SCHEME + SEPARATOR); } if (name.startsWith(SCHEME)) { name = name.substring(SCHEME.length()); } else if (name.startsWith(ORIGINAL_SCHEME)) { name = name.substring(ORIGINAL_SCHEME.length()); } } String[] parts = name.split(SEPARATOR); if (parts.length == 0) { return ROOT; } ArrayList<byte []> comps = new ArrayList<byte []>(parts.length -1); for (int i=1; i < parts.length; ++i) { try { byte[] component = Component.parseURI(parts[i]); if (null != component) { comps.add(component); } } catch (Component.DotDot c) { if (comps.isEmpty()) { throw new MalformedContentNameStringException("ContentName string contains too many .. components: " + name); } else { comps.remove(comps.size()-1); } } } result = new ContentName(); result._components = comps.toArray(new byte[comps.size()][]); return result; } catch (URISyntaxException e) { throw new MalformedContentNameStringException(e.getMessage()); } } ContentName(); @Deprecated protected  ContentName(ArrayList<byte[]> components);  ContentName(byte[] component);  ContentName(Object... args);  ContentName(ContentName parent, byte[] component);  ContentName(ContentName parent, ContentNameProvider cnp);  ContentName(ContentName parent, String component);  ContentName(ContentName parent, ComponentProvider cprov);  ContentName(byte components[][]); @Deprecated  ContentName(ContentName parent, byte [][] childComponents); @Deprecated  ContentName(ContentName parent, ArrayList<byte []> childComponents); @Deprecated  ContentName(ContentName parent, int start, ArrayList<byte []> childComponents); @Deprecated  ContentName(int count, byte components[][]); @Deprecated  ContentName(int count, ArrayList<byte []>components); @Deprecated  ContentName(int start, int count, ArrayList<byte []>components);  ContentName(ContentName otherName); final ContentName getContentName(); static ContentName fromURI(String name); @Deprecated static ContentName fromURI(String parts[]); @Deprecated static ContentName fromURI(ContentName parent, String name); static ContentName fromNative(String name); @Deprecated static ContentName fromNative(ContentName parent, String name); @Deprecated static ContentName fromNative(ContentName parent, byte [] name); @Deprecated static ContentName fromNative(ContentName parent, String name1, String name2); @Deprecated static ContentName fromNative(String [] parts); @Deprecated static ContentName fromNative(ContentName parent, String [] parts); ContentName parent(); @Override String toString(); String toURIString(); @Deprecated static String componentPrintURI(byte[] bs, int offset, int length); @Deprecated static String componentPrintURI(byte [] bs); @Deprecated static String componentPrintNative(byte[] bs); @Deprecated static String hexPrint(byte [] bs); @Deprecated static byte[] componentParseURI(String name); @Deprecated static byte[] componentParseNative(String name); @Deprecated ArrayList<byte[]> components(); int count(); ContentName append(ContentName other); ContentName append(String postfix); final byte[] component(int i); final byte [] lastComponent(); String stringComponent(int i); @Override void decode(XMLDecoder decoder); boolean isPrefixOf(ContentName name); boolean isPrefixOf(ContentName name, int count); boolean isPrefixOf(ContentObject other); boolean isPrefixOf(ContentObject other, int count); @Override boolean equals(Object obj); @Override int hashCode(); @Deprecated static ContentName parse(String str); @Deprecated boolean contains(String str); boolean contains(byte [] component); boolean contains(ComponentProvider cp); int containsWhere(String str); int containsWhere(ComponentProvider cp); int whereLast(String str); int containsWhere(byte [] component); int whereLast(byte [] component); int whereLast(ComponentProvider cp); @Deprecated boolean startsWith(byte [] value); @Deprecated int startsWithWhere(byte [] value); boolean componentStartsWith(byte [] value); int componentStartsWithWhere(byte [] value); ContentName cut(int componentCount); ContentName right(int position); ContentName cut(byte [] component); @Deprecated ContentName cut(String component); ContentName subname(int start, int end); int matchLength(ContentName name); ContentName postfix(ContentName prefix); @Override void encode(XMLEncoder encoder); @Override boolean validate(); @Override long getElementLabel(); @Deprecated ContentName copy(int nameComponentCount); int compareTo(ContentName o); Iterator<byte[]> iterator(); static final String SCHEME; static final String ORIGINAL_SCHEME; static final String SEPARATOR; static final ContentName ROOT; }
@Test public void testEncoding() { Log.info(Log.FAC_TEST, "Starting testEncoding"); String name1 = ContentName.SEPARATOR + subName1; String name2 = ContentName.SEPARATOR + escapedSubName1; System.out.println("ContentName: comparing parsed \"" + name1 + "\" and \"" + name2 + "\""); try { assertEquals(ContentName.fromURI(name1), ContentName.fromURI(name2)); } catch (MalformedContentNameStringException e) { fail("Unexpected exception MalformedContentNameStringException during ContentName parsing"); } Log.info(Log.FAC_TEST, "Completed testEncoding"); }
@Test public void testContentNameParsePerformance() { Log.info(Log.FAC_TEST, "Starting testContentNameParsePerformance"); ContentName name = null; long loops = 0; long elapsed = 0; int i; while (elapsed < 1000) try { long time = System.currentTimeMillis(); for (i = 0; i < 10000; i++) { name = ContentName.fromURI(veryEscapedName); } elapsed += System.currentTimeMillis() - time; loops += i; }catch (MalformedContentNameStringException e) { name = null; } System.out.println("Executed "+ loops + " ContentName.fromURI in " + elapsed + " ms; " + ((loops * 1000) / elapsed) + "/s"); assertNotNull(name); Log.info(Log.FAC_TEST, "Completed testContentNameParsePerformance"); }