@Test public void testInjectAtTheEnd() throws Exception { assertEquals( "<html><head><title>Title</title></head><body>Hello, World!<injected/></body></html>", injectAtTheEnd( "<html><head><title>Title</title></head><body>Hello, World!</body></html>" )); assertEquals( "<html><head><title>Title</title></head><body>Hello, World!<injected/></html>", injectAtTheEnd( "<html><head><title>Title</title></head><body>Hello, World!</html>" )); assertEquals( "<html><head><title>Title</title></head><body>Hello, World!<injected/>", injectAtTheEnd( "<html><head><title>Title</title></head><body>Hello, World!" )); }
public void injectAtTheEnd(String content) throws IOException { String str = new String(buffer.trailingBytes(16 * 1024), characterEncoding).toLowerCase(); StringBuilder sb = new StringBuilder(str); int htmlLIOf = sb.lastIndexOf("</html"); int bodyLIOf = sb.lastIndexOf("</body"); int i; if (-1 != bodyLIOf && (-1 == htmlLIOf || bodyLIOf < htmlLIOf)) { i = bodyLIOf; } else if (-1 != htmlLIOf) { i = htmlLIOf; } else { i = -1; } if (i == -1) { buffer.write(content.getBytes(characterEncoding)); } else { int offset = str.substring(i).getBytes(characterEncoding).length; buffer.insertAt(buffer.size() - offset, content.getBytes(characterEncoding)); } }
HtmlInjector { public void injectAtTheEnd(String content) throws IOException { String str = new String(buffer.trailingBytes(16 * 1024), characterEncoding).toLowerCase(); StringBuilder sb = new StringBuilder(str); int htmlLIOf = sb.lastIndexOf("</html"); int bodyLIOf = sb.lastIndexOf("</body"); int i; if (-1 != bodyLIOf && (-1 == htmlLIOf || bodyLIOf < htmlLIOf)) { i = bodyLIOf; } else if (-1 != htmlLIOf) { i = htmlLIOf; } else { i = -1; } if (i == -1) { buffer.write(content.getBytes(characterEncoding)); } else { int offset = str.substring(i).getBytes(characterEncoding).length; buffer.insertAt(buffer.size() - offset, content.getBytes(characterEncoding)); } } }
HtmlInjector { public void injectAtTheEnd(String content) throws IOException { String str = new String(buffer.trailingBytes(16 * 1024), characterEncoding).toLowerCase(); StringBuilder sb = new StringBuilder(str); int htmlLIOf = sb.lastIndexOf("</html"); int bodyLIOf = sb.lastIndexOf("</body"); int i; if (-1 != bodyLIOf && (-1 == htmlLIOf || bodyLIOf < htmlLIOf)) { i = bodyLIOf; } else if (-1 != htmlLIOf) { i = htmlLIOf; } else { i = -1; } if (i == -1) { buffer.write(content.getBytes(characterEncoding)); } else { int offset = str.substring(i).getBytes(characterEncoding).length; buffer.insertAt(buffer.size() - offset, content.getBytes(characterEncoding)); } } HtmlInjector(Buffer buffer);  HtmlInjector(Buffer buffer, String characterEncoding); }
HtmlInjector { public void injectAtTheEnd(String content) throws IOException { String str = new String(buffer.trailingBytes(16 * 1024), characterEncoding).toLowerCase(); StringBuilder sb = new StringBuilder(str); int htmlLIOf = sb.lastIndexOf("</html"); int bodyLIOf = sb.lastIndexOf("</body"); int i; if (-1 != bodyLIOf && (-1 == htmlLIOf || bodyLIOf < htmlLIOf)) { i = bodyLIOf; } else if (-1 != htmlLIOf) { i = htmlLIOf; } else { i = -1; } if (i == -1) { buffer.write(content.getBytes(characterEncoding)); } else { int offset = str.substring(i).getBytes(characterEncoding).length; buffer.insertAt(buffer.size() - offset, content.getBytes(characterEncoding)); } } HtmlInjector(Buffer buffer);  HtmlInjector(Buffer buffer, String characterEncoding); void injectAtTheEnd(String content); void injectAtTheBeginning(String content); }
HtmlInjector { public void injectAtTheEnd(String content) throws IOException { String str = new String(buffer.trailingBytes(16 * 1024), characterEncoding).toLowerCase(); StringBuilder sb = new StringBuilder(str); int htmlLIOf = sb.lastIndexOf("</html"); int bodyLIOf = sb.lastIndexOf("</body"); int i; if (-1 != bodyLIOf && (-1 == htmlLIOf || bodyLIOf < htmlLIOf)) { i = bodyLIOf; } else if (-1 != htmlLIOf) { i = htmlLIOf; } else { i = -1; } if (i == -1) { buffer.write(content.getBytes(characterEncoding)); } else { int offset = str.substring(i).getBytes(characterEncoding).length; buffer.insertAt(buffer.size() - offset, content.getBytes(characterEncoding)); } } HtmlInjector(Buffer buffer);  HtmlInjector(Buffer buffer, String characterEncoding); void injectAtTheEnd(String content); void injectAtTheBeginning(String content);  }