src_fm_fc_ms_ff
stringlengths 43
86.8k
| target
stringlengths 20
276k
|
|---|---|
CCJSqlParserUtil { public static Expression parseExpression(String expression) throws JSQLParserException { CCJSqlParser parser = new CCJSqlParser(new StringReader(expression)); try { return parser.SimpleExpression(); } catch (Exception ex) { throw new JSQLParserException(ex); } } private CCJSqlParserUtil(); static Statement parse(Reader statementReader); static Statement parse(String sql); static Node parseAST(String sql); static Statement parse(InputStream is); static Statement parse(InputStream is, String encoding); static Expression parseExpression(String expression); static Expression parseCondExpression(String condExpr); static Statements parseStatements(String sqls); }
|
@Test public void testParseExpression() throws Exception { Expression result = CCJSqlParserUtil.parseExpression("a+b"); assertEquals("a + b", result.toString()); assertTrue(result instanceof Addition); Addition add = (Addition)result; assertTrue(add.getLeftExpression() instanceof Column); assertTrue(add.getRightExpression() instanceof Column); }
@Test public void testParseExpression2() throws Exception { Expression result = CCJSqlParserUtil.parseExpression("2*(a+6.0)"); assertEquals("2 * (a + 6.0)", result.toString()); assertTrue(result instanceof Multiplication); Multiplication mult = (Multiplication)result; assertTrue(mult.getLeftExpression() instanceof LongValue); assertTrue(mult.getRightExpression() instanceof Parenthesis); }
|
CCJSqlParserUtil { public static Expression parseCondExpression(String condExpr) throws JSQLParserException { CCJSqlParser parser = new CCJSqlParser(new StringReader(condExpr)); try { return parser.Expression(); } catch (Exception ex) { throw new JSQLParserException(ex); } } private CCJSqlParserUtil(); static Statement parse(Reader statementReader); static Statement parse(String sql); static Node parseAST(String sql); static Statement parse(InputStream is); static Statement parse(InputStream is, String encoding); static Expression parseExpression(String expression); static Expression parseCondExpression(String condExpr); static Statements parseStatements(String sqls); }
|
@Test public void testParseCondExpression() throws Exception { Expression result = CCJSqlParserUtil.parseCondExpression("a+b>5 and c<3"); assertEquals("a + b > 5 AND c < 3", result.toString()); }
|
Column extends ASTNodeAccessImpl implements Expression, MultiPartName { @Override public String toString() { return getName(true); } Column(); Column(Table table, String columnName); Column(String columnName); Table getTable(); void setTable(Table table); String getColumnName(); void setColumnName(String string); @Override String getFullyQualifiedName(); String getName(boolean aliases); @Override void accept(ExpressionVisitor expressionVisitor); @Override String toString(); }
|
@Test public void testMissingTableAlias() { Table myTable = new Table("myTable"); myTable.setAlias(new Alias("tb")); Column myColumn = new Column(myTable, "myColumn"); assertEquals("tb.myColumn", myColumn.toString()); }
|
StringValue implements Expression { public String getValue() { return value; } StringValue(String escapedValue); String getValue(); String getNotExcapedValue(); void setValue(String string); @Override void accept(ExpressionVisitor expressionVisitor); @Override String toString(); }
|
@Test public void testGetValue() { StringValue instance = new StringValue("'*'"); String expResult = "*"; String result = instance.getValue(); assertEquals(expResult, result); }
@Test public void testGetValue2_issue329() { StringValue instance = new StringValue("*"); String expResult = "*"; String result = instance.getValue(); assertEquals(expResult, result); }
|
StringValue implements Expression { public String getNotExcapedValue() { StringBuilder buffer = new StringBuilder(value); int index = 0; int deletesNum = 0; while ((index = value.indexOf("''", index)) != -1) { buffer.deleteCharAt(index - deletesNum); index += 2; deletesNum++; } return buffer.toString(); } StringValue(String escapedValue); String getValue(); String getNotExcapedValue(); void setValue(String string); @Override void accept(ExpressionVisitor expressionVisitor); @Override String toString(); }
|
@Test public void testGetNotExcapedValue() { StringValue instance = new StringValue("'*''*'"); String expResult = "*'*"; String result = instance.getNotExcapedValue(); assertEquals(expResult, result); }
|
ExpressionVisitorAdapter implements ExpressionVisitor, ItemsListVisitor, PivotVisitor, SelectItemVisitor { @Override public void visit(NullValue value) { } SelectVisitor getSelectVisitor(); void setSelectVisitor(SelectVisitor selectVisitor); @Override void visit(NullValue value); @Override void visit(Function function); @Override void visit(SignedExpression expr); @Override void visit(JdbcParameter parameter); @Override void visit(JdbcNamedParameter parameter); @Override void visit(DoubleValue value); @Override void visit(LongValue value); @Override void visit(DateValue value); @Override void visit(TimeValue value); @Override void visit(TimestampValue value); @Override void visit(Parenthesis parenthesis); @Override void visit(StringValue value); @Override void visit(Addition expr); @Override void visit(Division expr); @Override void visit(Multiplication expr); @Override void visit(Subtraction expr); @Override void visit(AndExpression expr); @Override void visit(OrExpression expr); @Override void visit(Between expr); @Override void visit(EqualsTo expr); @Override void visit(GreaterThan expr); @Override void visit(GreaterThanEquals expr); @Override void visit(InExpression expr); @Override void visit(IsNullExpression expr); @Override void visit(LikeExpression expr); @Override void visit(MinorThan expr); @Override void visit(MinorThanEquals expr); @Override void visit(NotEqualsTo expr); @Override void visit(Column column); @Override void visit(SubSelect subSelect); @Override void visit(CaseExpression expr); @Override void visit(WhenClause expr); @Override void visit(ExistsExpression expr); @Override void visit(AllComparisonExpression expr); @Override void visit(AnyComparisonExpression expr); @Override void visit(Concat expr); @Override void visit(Matches expr); @Override void visit(BitwiseAnd expr); @Override void visit(BitwiseOr expr); @Override void visit(BitwiseXor expr); @Override void visit(CastExpression expr); @Override void visit(Modulo expr); @Override void visit(AnalyticExpression expr); @Override void visit(ExtractExpression expr); @Override void visit(IntervalExpression expr); @Override void visit(OracleHierarchicalExpression expr); @Override void visit(RegExpMatchOperator expr); @Override void visit(ExpressionList expressionList); @Override void visit(MultiExpressionList multiExprList); @Override void visit(JsonExpression jsonExpr); @Override void visit(JsonOperator expr); @Override void visit(RegExpMySQLOperator expr); @Override void visit(WithinGroupExpression wgexpr); @Override void visit(UserVariable var); @Override void visit(NumericBind bind); @Override void visit(KeepExpression expr); @Override void visit(MySQLGroupConcat groupConcat); @Override void visit(Pivot pivot); @Override void visit(PivotXml pivot); @Override void visit(AllColumns allColumns); @Override void visit(AllTableColumns allTableColumns); @Override void visit(SelectExpressionItem selectExpressionItem); @Override void visit(RowConstructor rowConstructor); @Override void visit(HexValue hexValue); @Override void visit(OracleHint hint); @Override void visit(TimeKeyExpression timeKeyExpression); @Override void visit(DateTimeLiteralExpression literal); }
|
@Test public void testInExpressionProblem() throws JSQLParserException { final List exprList = new ArrayList(); Select select = (Select) CCJSqlParserUtil.parse( "select * from foo where x in (?,?,?)" ); PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); Expression where = plainSelect.getWhere(); where.accept( new ExpressionVisitorAdapter() { @Override public void visit(InExpression expr) { super.visit(expr); exprList.add(expr.getLeftExpression()); exprList.add(expr.getLeftItemsList()); exprList.add(expr.getRightItemsList()); } }); assertTrue(exprList.get(0) instanceof Expression); assertNull(exprList.get(1)); assertTrue(exprList.get(2) instanceof ItemsList); }
@Test public void testInExpression() throws JSQLParserException { final List exprList = new ArrayList(); Select select = (Select) CCJSqlParserUtil.parse( "select * from foo where (a,b) in (select a,b from foo2)" ); PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); Expression where = plainSelect.getWhere(); where.accept(new ExpressionVisitorAdapter() { @Override public void visit(InExpression expr) { super.visit(expr); exprList.add(expr.getLeftExpression()); exprList.add(expr.getLeftItemsList()); exprList.add(expr.getRightItemsList()); } }); assertNull(exprList.get(0)); assertTrue(exprList.get(1) instanceof ItemsList); assertTrue(exprList.get(2) instanceof ItemsList); }
@Test public void testCurrentTimestampExpression() throws JSQLParserException{ final List<String> columnList = new ArrayList<String>(); Select select = (Select) CCJSqlParserUtil.parse( "select * from foo where bar < CURRENT_TIMESTAMP" ); PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); Expression where = plainSelect.getWhere(); where.accept(new ExpressionVisitorAdapter() { @Override public void visit(Column column) { super.visit(column); columnList.add(column.getColumnName()); } }); assertEquals(1, columnList.size()); assertEquals("bar", columnList.get(0)); }
@Test public void testCurrentDateExpression() throws JSQLParserException{ final List<String> columnList = new ArrayList<String>(); Select select = (Select) CCJSqlParserUtil.parse( "select * from foo where bar < CURRENT_DATE" ); PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); Expression where = plainSelect.getWhere(); where.accept(new ExpressionVisitorAdapter() { @Override public void visit(Column column) { super.visit(column); columnList.add(column.getColumnName()); } }); assertEquals(1, columnList.size()); assertEquals("bar", columnList.get(0)); }
|
Elements extends ArrayList<Element> { public Elements remove() { for (Element element : this) { element.remove(); } return this; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void remove() { Document doc = Jsoup.parse("<div><p>Hello <b>there</b></p> jsoup <p>now!</p></div>"); doc.outputSettings().prettyPrint(false); doc.select("p").remove(); assertEquals("<div> jsoup </div>", doc.body().html()); }
|
SignedExpression implements Expression { public char getSign() { return sign; } SignedExpression(char sign, Expression expression); char getSign(); final void setSign(char sign); Expression getExpression(); final void setExpression(Expression expression); @Override void accept(ExpressionVisitor expressionVisitor); @Override String toString(); }
|
@Test(expected = IllegalArgumentException.class) public void testGetSign() throws JSQLParserException { new SignedExpression('*', CCJSqlParserUtil.parseExpression("a")); fail("must not work"); }
|
Java7Support { public static boolean isSymLink(File file) { try { Object path = toPath.invoke(file); Boolean result = (Boolean) isSymbolicLink.invoke(null, path); return result.booleanValue(); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } static boolean isSymLink(File file); static File readSymbolicLink(File symlink); static File createSymbolicLink(File symlink, File target); static void delete(File file); static boolean isAtLeastJava7(); }
|
@Test public void testIsSymLink() throws Exception { File file = new File("."); if (Java7Support.isAtLeastJava7()) { assertFalse(Java7Support.isSymLink(file)); } }
|
EndianUtils { public static double readSwappedDouble(final byte[] data, final int offset) { return Double.longBitsToDouble( readSwappedLong( data, offset ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testEOFException() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream(new byte[] {}); try { EndianUtils.readSwappedDouble(input); fail("Expected EOFException"); } catch (final EOFException e) { } }
@Test public void testReadSwappedDouble() throws IOException { final byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; final double d1 = Double.longBitsToDouble( 0x0102030405060708L ); final double d2 = EndianUtils.readSwappedDouble( bytes, 0 ); assertEquals( d1, d2, 0.0 ); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); assertEquals( d1, EndianUtils.readSwappedDouble( input ), 0.0 ); }
|
EndianUtils { public static short swapShort(final short value) { return (short) ( ( ( ( value >> 0 ) & 0xff ) << 8 ) + ( ( ( value >> 8 ) & 0xff ) << 0 ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testSwapShort() { assertEquals( (short) 0, EndianUtils.swapShort( (short) 0 ) ); assertEquals( (short) 0x0201, EndianUtils.swapShort( (short) 0x0102 ) ); assertEquals( (short) 0xffff, EndianUtils.swapShort( (short) 0xffff ) ); assertEquals( (short) 0x0102, EndianUtils.swapShort( (short) 0x0201 ) ); }
|
EndianUtils { public static int swapInteger(final int value) { return ( ( ( value >> 0 ) & 0xff ) << 24 ) + ( ( ( value >> 8 ) & 0xff ) << 16 ) + ( ( ( value >> 16 ) & 0xff ) << 8 ) + ( ( ( value >> 24 ) & 0xff ) << 0 ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testSwapInteger() { assertEquals( 0, EndianUtils.swapInteger( 0 ) ); assertEquals( 0x04030201, EndianUtils.swapInteger( 0x01020304 ) ); assertEquals( 0x01000000, EndianUtils.swapInteger( 0x00000001 ) ); assertEquals( 0x00000001, EndianUtils.swapInteger( 0x01000000 ) ); assertEquals( 0x11111111, EndianUtils.swapInteger( 0x11111111 ) ); assertEquals( 0xabcdef10, EndianUtils.swapInteger( 0x10efcdab ) ); assertEquals( 0xab, EndianUtils.swapInteger( 0xab000000 ) ); }
|
EndianUtils { public static long swapLong(final long value) { return ( ( ( value >> 0 ) & 0xff ) << 56 ) + ( ( ( value >> 8 ) & 0xff ) << 48 ) + ( ( ( value >> 16 ) & 0xff ) << 40 ) + ( ( ( value >> 24 ) & 0xff ) << 32 ) + ( ( ( value >> 32 ) & 0xff ) << 24 ) + ( ( ( value >> 40 ) & 0xff ) << 16 ) + ( ( ( value >> 48 ) & 0xff ) << 8 ) + ( ( ( value >> 56 ) & 0xff ) << 0 ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testSwapLong() { assertEquals( 0, EndianUtils.swapLong( 0 ) ); assertEquals( 0x0807060504030201L, EndianUtils.swapLong( 0x0102030405060708L ) ); assertEquals( 0xffffffffffffffffL, EndianUtils.swapLong( 0xffffffffffffffffL ) ); assertEquals( 0xab, EndianUtils.swapLong( 0xab00000000000000L ) ); }
|
EndianUtils { public static float swapFloat(final float value) { return Float.intBitsToFloat( swapInteger( Float.floatToIntBits( value ) ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testSwapFloat() { assertEquals( 0.0f, EndianUtils.swapFloat( 0.0f ), 0.0 ); final float f1 = Float.intBitsToFloat( 0x01020304 ); final float f2 = Float.intBitsToFloat( 0x04030201 ); assertEquals( f2, EndianUtils.swapFloat( f1 ), 0.0 ); }
|
EndianUtils { public static double swapDouble(final double value) { return Double.longBitsToDouble( swapLong( Double.doubleToLongBits( value ) ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testSwapDouble() { assertEquals( 0.0, EndianUtils.swapDouble( 0.0 ), 0.0 ); final double d1 = Double.longBitsToDouble( 0x0102030405060708L ); final double d2 = Double.longBitsToDouble( 0x0807060504030201L ); assertEquals( d2, EndianUtils.swapDouble( d1 ), 0.0 ); }
|
Elements extends ArrayList<Element> { public Elements eq(int index) { return size() > index ? new Elements(get(index)) : new Elements(); } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void eq() { String h = "<p>Hello<p>there<p>world"; Document doc = Jsoup.parse(h); assertEquals("there", doc.select("p").eq(1).text()); assertEquals("there", doc.select("p").get(1).text()); }
|
EndianUtils { public static short readSwappedShort(final byte[] data, final int offset) { return (short)( ( ( data[ offset + 0 ] & 0xff ) << 0 ) + ( ( data[ offset + 1 ] & 0xff ) << 8 ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testReadSwappedShort() throws IOException { final byte[] bytes = new byte[] { 0x02, 0x01 }; assertEquals( 0x0102, EndianUtils.readSwappedShort( bytes, 0 ) ); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); assertEquals( 0x0102, EndianUtils.readSwappedShort( input ) ); }
|
EndianUtils { public static void writeSwappedShort(final byte[] data, final int offset, final short value) { data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff ); data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testWriteSwappedShort() throws IOException { byte[] bytes = new byte[2]; EndianUtils.writeSwappedShort( bytes, 0, (short) 0x0102 ); assertEquals( 0x02, bytes[0] ); assertEquals( 0x01, bytes[1] ); final ByteArrayOutputStream baos = new ByteArrayOutputStream(2); EndianUtils.writeSwappedShort( baos, (short) 0x0102 ); bytes = baos.toByteArray(); assertEquals( 0x02, bytes[0] ); assertEquals( 0x01, bytes[1] ); }
|
EndianUtils { public static int readSwappedUnsignedShort(final byte[] data, final int offset) { return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) + ( ( data[ offset + 1 ] & 0xff ) << 8 ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testReadSwappedUnsignedShort() throws IOException { final byte[] bytes = new byte[] { 0x02, 0x01 }; assertEquals( 0x00000102, EndianUtils.readSwappedUnsignedShort( bytes, 0 ) ); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); assertEquals( 0x00000102, EndianUtils.readSwappedUnsignedShort( input ) ); }
|
EndianUtils { public static int readSwappedInteger(final byte[] data, final int offset) { return ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) + ( ( data[ offset + 1 ] & 0xff ) << 8 ) + ( ( data[ offset + 2 ] & 0xff ) << 16 ) + ( ( data[ offset + 3 ] & 0xff ) << 24 ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testReadSwappedInteger() throws IOException { final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 }; assertEquals( 0x01020304, EndianUtils.readSwappedInteger( bytes, 0 ) ); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); assertEquals( 0x01020304, EndianUtils.readSwappedInteger( input ) ); }
|
EndianUtils { public static void writeSwappedInteger(final byte[] data, final int offset, final int value) { data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff ); data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff ); data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff ); data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testWriteSwappedInteger() throws IOException { byte[] bytes = new byte[4]; EndianUtils.writeSwappedInteger( bytes, 0, 0x01020304 ); assertEquals( 0x04, bytes[0] ); assertEquals( 0x03, bytes[1] ); assertEquals( 0x02, bytes[2] ); assertEquals( 0x01, bytes[3] ); final ByteArrayOutputStream baos = new ByteArrayOutputStream(4); EndianUtils.writeSwappedInteger( baos, 0x01020304 ); bytes = baos.toByteArray(); assertEquals( 0x04, bytes[0] ); assertEquals( 0x03, bytes[1] ); assertEquals( 0x02, bytes[2] ); assertEquals( 0x01, bytes[3] ); }
|
EndianUtils { public static long readSwappedUnsignedInteger(final byte[] data, final int offset) { final long low = ( ( ( data[ offset + 0 ] & 0xff ) << 0 ) + ( ( data[ offset + 1 ] & 0xff ) << 8 ) + ( ( data[ offset + 2 ] & 0xff ) << 16 ) ); final long high = data[ offset + 3 ] & 0xff; return (high << 24) + (0xffffffffL & low); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testReadSwappedUnsignedInteger() throws IOException { final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 }; assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( bytes, 0 ) ); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); assertEquals( 0x0000000001020304L, EndianUtils.readSwappedUnsignedInteger( input ) ); }
@Test public void testUnsignedOverrun() throws Exception { final byte[] target = new byte[] { 0, 0, 0, (byte)0x80 }; final long expected = 0x80000000L; long actual = EndianUtils.readSwappedUnsignedInteger(target, 0); assertEquals("readSwappedUnsignedInteger(byte[], int) was incorrect", expected, actual); final ByteArrayInputStream in = new ByteArrayInputStream(target); actual = EndianUtils.readSwappedUnsignedInteger(in); assertEquals("readSwappedUnsignedInteger(InputStream) was incorrect", expected, actual); }
|
EndianUtils { public static long readSwappedLong(final byte[] data, final int offset) { final long low = readSwappedInteger(data, offset); final long high = readSwappedInteger(data, offset + 4); return (high << 32) + (0xffffffffL & low); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testReadSwappedLong() throws IOException { final byte[] bytes = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( bytes, 0 ) ); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); assertEquals( 0x0102030405060708L, EndianUtils.readSwappedLong( input ) ); }
|
EndianUtils { public static void writeSwappedLong(final byte[] data, final int offset, final long value) { data[ offset + 0 ] = (byte)( ( value >> 0 ) & 0xff ); data[ offset + 1 ] = (byte)( ( value >> 8 ) & 0xff ); data[ offset + 2 ] = (byte)( ( value >> 16 ) & 0xff ); data[ offset + 3 ] = (byte)( ( value >> 24 ) & 0xff ); data[ offset + 4 ] = (byte)( ( value >> 32 ) & 0xff ); data[ offset + 5 ] = (byte)( ( value >> 40 ) & 0xff ); data[ offset + 6 ] = (byte)( ( value >> 48 ) & 0xff ); data[ offset + 7 ] = (byte)( ( value >> 56 ) & 0xff ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testWriteSwappedLong() throws IOException { byte[] bytes = new byte[8]; EndianUtils.writeSwappedLong( bytes, 0, 0x0102030405060708L ); assertEquals( 0x08, bytes[0] ); assertEquals( 0x07, bytes[1] ); assertEquals( 0x06, bytes[2] ); assertEquals( 0x05, bytes[3] ); assertEquals( 0x04, bytes[4] ); assertEquals( 0x03, bytes[5] ); assertEquals( 0x02, bytes[6] ); assertEquals( 0x01, bytes[7] ); final ByteArrayOutputStream baos = new ByteArrayOutputStream(8); EndianUtils.writeSwappedLong( baos, 0x0102030405060708L ); bytes = baos.toByteArray(); assertEquals( 0x08, bytes[0] ); assertEquals( 0x07, bytes[1] ); assertEquals( 0x06, bytes[2] ); assertEquals( 0x05, bytes[3] ); assertEquals( 0x04, bytes[4] ); assertEquals( 0x03, bytes[5] ); assertEquals( 0x02, bytes[6] ); assertEquals( 0x01, bytes[7] ); }
|
EndianUtils { public static float readSwappedFloat(final byte[] data, final int offset) { return Float.intBitsToFloat( readSwappedInteger( data, offset ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testReadSwappedFloat() throws IOException { final byte[] bytes = new byte[] { 0x04, 0x03, 0x02, 0x01 }; final float f1 = Float.intBitsToFloat( 0x01020304 ); final float f2 = EndianUtils.readSwappedFloat( bytes, 0 ); assertEquals( f1, f2, 0.0 ); final ByteArrayInputStream input = new ByteArrayInputStream(bytes); assertEquals( f1, EndianUtils.readSwappedFloat( input ), 0.0 ); }
|
EndianUtils { public static void writeSwappedFloat(final byte[] data, final int offset, final float value) { writeSwappedInteger( data, offset, Float.floatToIntBits( value ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testWriteSwappedFloat() throws IOException { byte[] bytes = new byte[4]; final float f1 = Float.intBitsToFloat( 0x01020304 ); EndianUtils.writeSwappedFloat( bytes, 0, f1 ); assertEquals( 0x04, bytes[0] ); assertEquals( 0x03, bytes[1] ); assertEquals( 0x02, bytes[2] ); assertEquals( 0x01, bytes[3] ); final ByteArrayOutputStream baos = new ByteArrayOutputStream(4); EndianUtils.writeSwappedFloat( baos, f1 ); bytes = baos.toByteArray(); assertEquals( 0x04, bytes[0] ); assertEquals( 0x03, bytes[1] ); assertEquals( 0x02, bytes[2] ); assertEquals( 0x01, bytes[3] ); }
|
Elements extends ArrayList<Element> { public boolean is(String query) { Evaluator eval = QueryParser.parse(query); for (Element e : this) { if (e.is(eval)) return true; } return false; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void is() { String h = "<p>Hello<p title=foo>there<p>world"; Document doc = Jsoup.parse(h); Elements ps = doc.select("p"); assertTrue(ps.is("[title=foo]")); assertFalse(ps.is("[title=bar]")); }
|
EndianUtils { public static void writeSwappedDouble(final byte[] data, final int offset, final double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); } EndianUtils(); static short swapShort(final short value); static int swapInteger(final int value); static long swapLong(final long value); static float swapFloat(final float value); static double swapDouble(final double value); static void writeSwappedShort(final byte[] data, final int offset, final short value); static short readSwappedShort(final byte[] data, final int offset); static int readSwappedUnsignedShort(final byte[] data, final int offset); static void writeSwappedInteger(final byte[] data, final int offset, final int value); static int readSwappedInteger(final byte[] data, final int offset); static long readSwappedUnsignedInteger(final byte[] data, final int offset); static void writeSwappedLong(final byte[] data, final int offset, final long value); static long readSwappedLong(final byte[] data, final int offset); static void writeSwappedFloat(final byte[] data, final int offset, final float value); static float readSwappedFloat(final byte[] data, final int offset); static void writeSwappedDouble(final byte[] data, final int offset, final double value); static double readSwappedDouble(final byte[] data, final int offset); static void writeSwappedShort(final OutputStream output, final short value); static short readSwappedShort(final InputStream input); static int readSwappedUnsignedShort(final InputStream input); static void writeSwappedInteger(final OutputStream output, final int value); static int readSwappedInteger(final InputStream input); static long readSwappedUnsignedInteger(final InputStream input); static void writeSwappedLong(final OutputStream output, final long value); static long readSwappedLong(final InputStream input); static void writeSwappedFloat(final OutputStream output, final float value); static float readSwappedFloat(final InputStream input); static void writeSwappedDouble(final OutputStream output, final double value); static double readSwappedDouble(final InputStream input); }
|
@Test public void testWriteSwappedDouble() throws IOException { byte[] bytes = new byte[8]; final double d1 = Double.longBitsToDouble( 0x0102030405060708L ); EndianUtils.writeSwappedDouble( bytes, 0, d1 ); assertEquals( 0x08, bytes[0] ); assertEquals( 0x07, bytes[1] ); assertEquals( 0x06, bytes[2] ); assertEquals( 0x05, bytes[3] ); assertEquals( 0x04, bytes[4] ); assertEquals( 0x03, bytes[5] ); assertEquals( 0x02, bytes[6] ); assertEquals( 0x01, bytes[7] ); final ByteArrayOutputStream baos = new ByteArrayOutputStream(8); EndianUtils.writeSwappedDouble( baos, d1 ); bytes = baos.toByteArray(); assertEquals( 0x08, bytes[0] ); assertEquals( 0x07, bytes[1] ); assertEquals( 0x06, bytes[2] ); assertEquals( 0x05, bytes[3] ); assertEquals( 0x04, bytes[4] ); assertEquals( 0x03, bytes[5] ); assertEquals( 0x02, bytes[6] ); assertEquals( 0x01, bytes[7] ); }
|
FullClassNameMatcher implements ClassNameMatcher { @Override public boolean matches(String className) { return classesSet.contains(className); } FullClassNameMatcher(String... classes); @Override boolean matches(String className); }
|
@Test public void noNames() throws Exception { final FullClassNameMatcher m = new FullClassNameMatcher(); assertFalse(m.matches(Integer.class.getName())); }
@Test public void withNames() throws Exception { final FullClassNameMatcher m = new FullClassNameMatcher(NAMES_ARRAY); assertTrue(m.matches(Integer.class.getName())); assertFalse(m.matches(String.class.getName())); }
|
WildcardClassNameMatcher implements ClassNameMatcher { @Override public boolean matches(String className) { return FilenameUtils.wildcardMatch(className, pattern); } WildcardClassNameMatcher(String pattern); @Override boolean matches(String className); }
|
@Test public void noPattern() { ClassNameMatcher ca = new WildcardClassNameMatcher("org.foo"); assertTrue(ca.matches("org.foo")); assertFalse(ca.matches("org.foo.and.more")); assertFalse(ca.matches("org_foo")); }
@Test public void star() { ClassNameMatcher ca = new WildcardClassNameMatcher("org*"); assertTrue(ca.matches("org.foo.should.match")); assertFalse(ca.matches("bar.should.not.match")); }
@Test public void starAndQuestionMark() { ClassNameMatcher ca = new WildcardClassNameMatcher("org?apache?something*"); assertTrue(ca.matches("org.apache_something.more")); assertFalse(ca.matches("org..apache_something.more")); }
|
RegexpClassNameMatcher implements ClassNameMatcher { @Override public boolean matches(String className) { return pattern.matcher(className).matches(); } RegexpClassNameMatcher(String regex); RegexpClassNameMatcher(Pattern pattern); @Override boolean matches(String className); }
|
@Test public void testSimplePatternFromString() { ClassNameMatcher ca = new RegexpClassNameMatcher("foo.*"); assertTrue(ca.matches("foo.should.match")); assertFalse(ca.matches("bar.should.not.match")); }
@Test public void testSimplePatternFromPattern() { ClassNameMatcher ca = new RegexpClassNameMatcher(Pattern.compile("foo.*")); assertTrue(ca.matches("foo.should.match")); assertFalse(ca.matches("bar.should.not.match")); }
@Test public void testOrPattern() { ClassNameMatcher ca = new RegexpClassNameMatcher("foo.*|bar.*"); assertTrue(ca.matches("foo.should.match")); assertTrue(ca.matches("bar.should.match")); assertFalse(ca.matches("zoo.should.not.match")); }
|
Elements extends ArrayList<Element> { public Elements parents() { HashSet<Element> combo = new LinkedHashSet<>(); for (Element e: this) { combo.addAll(e.parents()); } return new Elements(combo); } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void parents() { Document doc = Jsoup.parse("<div><p>Hello</p></div><p>There</p>"); Elements parents = doc.select("p").parents(); assertEquals(3, parents.size()); assertEquals("div", parents.get(0).tagName()); assertEquals("body", parents.get(1).tagName()); assertEquals("html", parents.get(2).tagName()); }
|
ValidatingObjectInputStream extends ObjectInputStream { public ValidatingObjectInputStream accept(Class<?>... classes) { for (Class<?> c : classes) { acceptMatchers.add(new FullClassNameMatcher(c.getName())); } return this; } ValidatingObjectInputStream(InputStream input); ValidatingObjectInputStream accept(Class<?>... classes); ValidatingObjectInputStream reject(Class<?>... classes); ValidatingObjectInputStream accept(String... patterns); ValidatingObjectInputStream reject(String... patterns); ValidatingObjectInputStream accept(Pattern pattern); ValidatingObjectInputStream reject(Pattern pattern); ValidatingObjectInputStream accept(ClassNameMatcher m); ValidatingObjectInputStream reject(ClassNameMatcher m); }
|
@Test public void acceptCustomMatcher() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept(ALWAYS_TRUE) ); }
@Test public void acceptPattern() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept(Pattern.compile(".*MockSerializedClass.*")) ); }
@Test public void acceptWildcard() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept("org.apache.commons.io.*") ); }
@Test(expected = InvalidClassException.class) public void ourTestClassNotAccepted() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept(Integer.class) ); }
@Test public void ourTestClassOnlyAccepted() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept(MockSerializedClass.class) ); }
@Test public void ourTestClassAcceptedFirst() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept(MockSerializedClass.class, Integer.class) ); }
@Test public void ourTestClassAcceptedSecond() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept(Integer.class, MockSerializedClass.class) ); }
@Test public void ourTestClassAcceptedFirstWildcard() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept("*MockSerializedClass","*Integer") ); }
@Test public void ourTestClassAcceptedSecondWildcard() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept("*Integer","*MockSerializedClass") ); }
|
Elements extends ArrayList<Element> { public Elements not(String query) { Elements out = Selector.select(query, this); return Selector.filterOut(this, out); } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void not() { Document doc = Jsoup.parse("<div id=1><p>One</p></div> <div id=2><p><span>Two</span></p></div>"); Elements div1 = doc.select("div").not(":has(p > span)"); assertEquals(1, div1.size()); assertEquals("1", div1.first().id()); Elements div2 = doc.select("div").not("#1"); assertEquals(1, div2.size()); assertEquals("2", div2.first().id()); }
|
ValidatingObjectInputStream extends ObjectInputStream { public ValidatingObjectInputStream reject(Class<?>... classes) { for (Class<?> c : classes) { rejectMatchers.add(new FullClassNameMatcher(c.getName())); } return this; } ValidatingObjectInputStream(InputStream input); ValidatingObjectInputStream accept(Class<?>... classes); ValidatingObjectInputStream reject(Class<?>... classes); ValidatingObjectInputStream accept(String... patterns); ValidatingObjectInputStream reject(String... patterns); ValidatingObjectInputStream accept(Pattern pattern); ValidatingObjectInputStream reject(Pattern pattern); ValidatingObjectInputStream accept(ClassNameMatcher m); ValidatingObjectInputStream reject(ClassNameMatcher m); }
|
@Test(expected = InvalidClassException.class) public void reject() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .accept(Long.class) .reject(MockSerializedClass.class, Integer.class) ); }
@Test(expected = InvalidClassException.class) public void rejectOnly() throws Exception { assertSerialization( willClose(new ValidatingObjectInputStream(testStream)) .reject(Integer.class) ); }
@Test(expected = RuntimeException.class) public void customInvalidMethod() throws Exception { class CustomVOIS extends ValidatingObjectInputStream { CustomVOIS(InputStream is) throws IOException { super(is); } @Override protected void invalidClassNameFound(String className) throws InvalidClassException { throw new RuntimeException("Custom exception"); } }; assertSerialization( willClose(new CustomVOIS(testStream)) .reject(Integer.class) ); }
|
PathFileComparator extends AbstractFileComparator implements Serializable { public int compare(final File file1, final File file2) { return caseSensitivity.checkCompareTo(file1.getPath(), file2.getPath()); } PathFileComparator(); PathFileComparator(final IOCase caseSensitivity); int compare(final File file1, final File file2); @Override String toString(); static final Comparator<File> PATH_COMPARATOR; static final Comparator<File> PATH_REVERSE; static final Comparator<File> PATH_INSENSITIVE_COMPARATOR; static final Comparator<File> PATH_INSENSITIVE_REVERSE; static final Comparator<File> PATH_SYSTEM_COMPARATOR; static final Comparator<File> PATH_SYSTEM_REVERSE; }
|
@Test public void testCaseSensitivity() { final File file3 = new File("FOO/file.txt"); final Comparator<File> sensitive = new PathFileComparator(null); assertTrue("sensitive file1 & file2 = 0", sensitive.compare(equalFile1, equalFile2) == 0); assertTrue("sensitive file1 & file3 > 0", sensitive.compare(equalFile1, file3) > 0); assertTrue("sensitive file1 & less > 0", sensitive.compare(equalFile1, lessFile) > 0); final Comparator<File> insensitive = PathFileComparator.PATH_INSENSITIVE_COMPARATOR; assertTrue("insensitive file1 & file2 = 0", insensitive.compare(equalFile1, equalFile2) == 0); assertTrue("insensitive file1 & file3 = 0", insensitive.compare(equalFile1, file3) == 0); assertTrue("insensitive file1 & file4 > 0", insensitive.compare(equalFile1, lessFile) > 0); assertTrue("insensitive file3 & less > 0", insensitive.compare(file3, lessFile) > 0); }
|
NameFileComparator extends AbstractFileComparator implements Serializable { public int compare(final File file1, final File file2) { return caseSensitivity.checkCompareTo(file1.getName(), file2.getName()); } NameFileComparator(); NameFileComparator(final IOCase caseSensitivity); int compare(final File file1, final File file2); @Override String toString(); static final Comparator<File> NAME_COMPARATOR; static final Comparator<File> NAME_REVERSE; static final Comparator<File> NAME_INSENSITIVE_COMPARATOR; static final Comparator<File> NAME_INSENSITIVE_REVERSE; static final Comparator<File> NAME_SYSTEM_COMPARATOR; static final Comparator<File> NAME_SYSTEM_REVERSE; }
|
@Test public void testCaseSensitivity() { final File file3 = new File("a/FOO.txt"); final Comparator<File> sensitive = new NameFileComparator(null); assertTrue("sensitive file1 & file2 = 0", sensitive.compare(equalFile1, equalFile2) == 0); assertTrue("sensitive file1 & file3 > 0", sensitive.compare(equalFile1, file3) > 0); assertTrue("sensitive file1 & less > 0", sensitive.compare(equalFile1, lessFile) > 0); final Comparator<File> insensitive = NameFileComparator.NAME_INSENSITIVE_COMPARATOR; assertTrue("insensitive file1 & file2 = 0", insensitive.compare(equalFile1, equalFile2) == 0); assertTrue("insensitive file1 & file3 = 0", insensitive.compare(equalFile1, file3) == 0); assertTrue("insensitive file1 & file4 > 0", insensitive.compare(equalFile1, lessFile) > 0); assertTrue("insensitive file3 & less > 0", insensitive.compare(file3, lessFile) > 0); }
|
SizeFileComparator extends AbstractFileComparator implements Serializable { public int compare(final File file1, final File file2) { long size1 = 0; if (file1.isDirectory()) { size1 = sumDirectoryContents && file1.exists() ? FileUtils.sizeOfDirectory(file1) : 0; } else { size1 = file1.length(); } long size2 = 0; if (file2.isDirectory()) { size2 = sumDirectoryContents && file2.exists() ? FileUtils.sizeOfDirectory(file2) : 0; } else { size2 = file2.length(); } final long result = size1 - size2; if (result < 0) { return -1; } else if (result > 0) { return 1; } else { return 0; } } SizeFileComparator(); SizeFileComparator(final boolean sumDirectoryContents); int compare(final File file1, final File file2); @Override String toString(); static final Comparator<File> SIZE_COMPARATOR; static final Comparator<File> SIZE_REVERSE; static final Comparator<File> SIZE_SUMDIR_COMPARATOR; static final Comparator<File> SIZE_SUMDIR_REVERSE; }
|
@Test public void testNonexistantFile() { final File nonexistantFile = new File(new File("."), "nonexistant.txt"); assertFalse(nonexistantFile.exists()); assertTrue("less", comparator.compare(nonexistantFile, moreFile) < 0); }
@Test public void testCompareDirectorySizes() { assertEquals("sumDirectoryContents=false", 0, comparator.compare(smallerDir, largerDir)); assertEquals("less", -1, SizeFileComparator.SIZE_SUMDIR_COMPARATOR.compare(smallerDir, largerDir)); assertEquals("less", 1, SizeFileComparator.SIZE_SUMDIR_REVERSE.compare(smallerDir, largerDir)); }
|
ExtensionFileComparator extends AbstractFileComparator implements Serializable { public int compare(final File file1, final File file2) { final String suffix1 = FilenameUtils.getExtension(file1.getName()); final String suffix2 = FilenameUtils.getExtension(file2.getName()); return caseSensitivity.checkCompareTo(suffix1, suffix2); } ExtensionFileComparator(); ExtensionFileComparator(final IOCase caseSensitivity); int compare(final File file1, final File file2); @Override String toString(); static final Comparator<File> EXTENSION_COMPARATOR; static final Comparator<File> EXTENSION_REVERSE; static final Comparator<File> EXTENSION_INSENSITIVE_COMPARATOR; static final Comparator<File> EXTENSION_INSENSITIVE_REVERSE; static final Comparator<File> EXTENSION_SYSTEM_COMPARATOR; static final Comparator<File> EXTENSION_SYSTEM_REVERSE; }
|
@Test public void testCaseSensitivity() { final File file3 = new File("abc.FOO"); final Comparator<File> sensitive = new ExtensionFileComparator(null); assertTrue("sensitive file1 & file2 = 0", sensitive.compare(equalFile1, equalFile2) == 0); assertTrue("sensitive file1 & file3 > 0", sensitive.compare(equalFile1, file3) > 0); assertTrue("sensitive file1 & less > 0", sensitive.compare(equalFile1, lessFile) > 0); final Comparator<File> insensitive = ExtensionFileComparator.EXTENSION_INSENSITIVE_COMPARATOR; assertTrue("insensitive file1 & file2 = 0", insensitive.compare(equalFile1, equalFile2) == 0); assertTrue("insensitive file1 & file3 = 0", insensitive.compare(equalFile1, file3) == 0); assertTrue("insensitive file1 & file4 > 0", insensitive.compare(equalFile1, lessFile) > 0); assertTrue("insensitive file3 & less > 0", insensitive.compare(file3, lessFile) > 0); }
|
CompositeFileComparator extends AbstractFileComparator implements Serializable { public int compare(final File file1, final File file2) { int result = 0; for (final Comparator<File> delegate : delegates) { result = delegate.compare(file1, file2); if (result != 0) { break; } } return result; } @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct CompositeFileComparator(final Comparator<File>... delegates); @SuppressWarnings("unchecked") // casts 1 & 2 must be OK because types are already correct CompositeFileComparator(final Iterable<Comparator<File>> delegates); int compare(final File file1, final File file2); @Override String toString(); }
|
@Test public void constructorIterable_order() { final List<Comparator<File>> list = new ArrayList<Comparator<File>>(); list.add(SizeFileComparator.SIZE_COMPARATOR); list.add(ExtensionFileComparator.EXTENSION_COMPARATOR); final Comparator<File> c = new CompositeFileComparator(list); assertEquals("equal", 0, c.compare(equalFile1, equalFile2)); assertTrue("less", c.compare(lessFile, moreFile) < 0); assertTrue("more", c.compare(moreFile, lessFile) > 0); }
|
ClosedInputStream extends InputStream { @Override public int read() { return EOF; } @Override int read(); static final ClosedInputStream CLOSED_INPUT_STREAM; }
|
@Test public void testRead() throws Exception { final ClosedInputStream cis = new ClosedInputStream(); assertEquals("read()", -1, cis.read()); cis.close(); }
|
Elements extends ArrayList<Element> { public Elements traverse(NodeVisitor nodeVisitor) { Validate.notNull(nodeVisitor); NodeTraversor traversor = new NodeTraversor(nodeVisitor); for (Element el: this) { traversor.traverse(el); } return this; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void traverse() { Document doc = Jsoup.parse("<div><p>Hello</p></div><div>There</div>"); final StringBuilder accum = new StringBuilder(); doc.select("div").traverse(new NodeVisitor() { public void head(Node node, int depth) { accum.append("<" + node.nodeName() + ">"); } public void tail(Node node, int depth) { accum.append("</" + node.nodeName() + ">"); } }); assertEquals("<div><p><#text></#text></p></div><div><#text></#text></div>", accum.toString()); }
|
NullReader extends Reader { @Override public int read() throws IOException { if (eof) { throw new IOException("Read after end of file"); } if (position == size) { return doEndOfFile(); } position++; return processChar(); } NullReader(final long size); NullReader(final long size, final boolean markSupported, final boolean throwEofException); long getPosition(); long getSize(); @Override void close(); @Override synchronized void mark(final int readlimit); @Override boolean markSupported(); @Override int read(); @Override int read(final char[] chars); @Override int read(final char[] chars, final int offset, final int length); @Override synchronized void reset(); @Override long skip(final long numberOfChars); }
|
@Test public void testRead() throws Exception { final int size = 5; final TestNullReader reader = new TestNullReader(size); for (int i = 0; i < size; i++) { assertEquals("Check Value [" + i + "]", i, reader.read()); } assertEquals("End of File", -1, reader.read()); try { final int result = reader.read(); fail("Should have thrown an IOException, value=[" + result + "]"); } catch (final IOException e) { assertEquals("Read after end of file", e.getMessage()); } reader.close(); assertEquals("Available after close", 0, reader.getPosition()); }
|
NullReader extends Reader { @Override public long skip(final long numberOfChars) throws IOException { if (eof) { throw new IOException("Skip after end of file"); } if (position == size) { return doEndOfFile(); } position += numberOfChars; long returnLength = numberOfChars; if (position > size) { returnLength = numberOfChars - (position - size); position = size; } return returnLength; } NullReader(final long size); NullReader(final long size, final boolean markSupported, final boolean throwEofException); long getPosition(); long getSize(); @Override void close(); @Override synchronized void mark(final int readlimit); @Override boolean markSupported(); @Override int read(); @Override int read(final char[] chars); @Override int read(final char[] chars, final int offset, final int length); @Override synchronized void reset(); @Override long skip(final long numberOfChars); }
|
@Test public void testSkip() throws Exception { final Reader reader = new TestNullReader(10, true, false); assertEquals("Read 1", 0, reader.read()); assertEquals("Read 2", 1, reader.read()); assertEquals("Skip 1", 5, reader.skip(5)); assertEquals("Read 3", 7, reader.read()); assertEquals("Skip 2", 2, reader.skip(5)); assertEquals("Skip 3 (EOF)", -1, reader.skip(5)); try { reader.skip(5); fail("Expected IOException for skipping after end of file"); } catch (final IOException e) { assertEquals("Skip after EOF IOException message", "Skip after end of file", e.getMessage()); } reader.close(); }
|
CloseShieldInputStream extends ProxyInputStream { @Override public void close() { in = new ClosedInputStream(); } CloseShieldInputStream(final InputStream in); @Override void close(); }
|
@Test public void testClose() throws IOException { shielded.close(); assertFalse("closed", closed); assertEquals("read()", -1, shielded.read()); assertEquals("read()", data[0], original.read()); }
|
TeeInputStream extends ProxyInputStream { @Override public int read() throws IOException { final int ch = super.read(); if (ch != EOF) { branch.write(ch); } return ch; } TeeInputStream(final InputStream input, final OutputStream branch); TeeInputStream(
final InputStream input, final OutputStream branch, final boolean closeBranch); @Override void close(); @Override int read(); @Override int read(final byte[] bts, final int st, final int end); @Override int read(final byte[] bts); }
|
@Test public void testReadOneByte() throws Exception { assertEquals('a', tee.read()); assertEquals("a", new String(output.toString(ASCII))); }
@Test public void testReadEverything() throws Exception { assertEquals('a', tee.read()); assertEquals('b', tee.read()); assertEquals('c', tee.read()); assertEquals(-1, tee.read()); assertEquals("abc", new String(output.toString(ASCII))); }
@Test public void testReadToArray() throws Exception { final byte[] buffer = new byte[8]; assertEquals(3, tee.read(buffer)); assertEquals('a', buffer[0]); assertEquals('b', buffer[1]); assertEquals('c', buffer[2]); assertEquals(-1, tee.read(buffer)); assertEquals("abc", new String(output.toString(ASCII))); }
@Test public void testReadToArrayWithOffset() throws Exception { final byte[] buffer = new byte[8]; assertEquals(3, tee.read(buffer, 4, 4)); assertEquals('a', buffer[4]); assertEquals('b', buffer[5]); assertEquals('c', buffer[6]); assertEquals(-1, tee.read(buffer, 4, 4)); assertEquals("abc", new String(output.toString(ASCII))); }
@Test public void testSkip() throws Exception { assertEquals('a', tee.read()); assertEquals(1, tee.skip(1)); assertEquals('c', tee.read()); assertEquals(-1, tee.read()); assertEquals("ac", new String(output.toString(ASCII))); }
@Test public void testMarkReset() throws Exception { assertEquals('a', tee.read()); tee.mark(1); assertEquals('b', tee.read()); tee.reset(); assertEquals('b', tee.read()); assertEquals('c', tee.read()); assertEquals(-1, tee.read()); assertEquals("abbc", new String(output.toString(ASCII))); }
|
CharSequenceInputStream extends InputStream { @Override public boolean markSupported() { return true; } CharSequenceInputStream(final CharSequence cs, final Charset charset, final int bufferSize); CharSequenceInputStream(final CharSequence cs, final String charset, final int bufferSize); CharSequenceInputStream(final CharSequence cs, final Charset charset); CharSequenceInputStream(final CharSequence cs, final String charset); @Override int read(final byte[] b, int off, int len); @Override int read(); @Override int read(final byte[] b); @Override long skip(long n); @Override int available(); @Override void close(); @Override synchronized void mark(final int readlimit); @Override synchronized void reset(); @Override boolean markSupported(); }
|
@Test public void testMarkSupported() throws Exception { final InputStream r = new CharSequenceInputStream("test", "UTF-8"); try { assertTrue(r.markSupported()); } finally { r.close(); } }
|
Elements extends ArrayList<Element> { public List<FormElement> forms() { ArrayList<FormElement> forms = new ArrayList<>(); for (Element el: this) if (el instanceof FormElement) forms.add((FormElement) el); return forms; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void forms() { Document doc = Jsoup.parse("<form id=1><input name=q></form><div /><form id=2><input name=f></form>"); Elements els = doc.select("*"); assertEquals(9, els.size()); List<FormElement> forms = els.forms(); assertEquals(2, forms.size()); assertTrue(forms.get(0) != null); assertTrue(forms.get(1) != null); assertEquals("1", forms.get(0).id()); assertEquals("2", forms.get(1).id()); }
|
CharSequenceInputStream extends InputStream { @Override public int available() throws IOException { return this.bbuf.remaining() + this.cbuf.remaining(); } CharSequenceInputStream(final CharSequence cs, final Charset charset, final int bufferSize); CharSequenceInputStream(final CharSequence cs, final String charset, final int bufferSize); CharSequenceInputStream(final CharSequence cs, final Charset charset); CharSequenceInputStream(final CharSequence cs, final String charset); @Override int read(final byte[] b, int off, int len); @Override int read(); @Override int read(final byte[] b); @Override long skip(long n); @Override int available(); @Override void close(); @Override synchronized void mark(final int readlimit); @Override synchronized void reset(); @Override boolean markSupported(); }
|
@Test public void testAvailable() throws Exception { for (final String csName : Charset.availableCharsets().keySet()) { try { if (isAvailabilityTestableForCharset(csName)) { testAvailableSkip(csName); testAvailableRead(csName); } } catch (UnsupportedOperationException e){ fail("Operation not supported for " + csName); } } }
|
BOMInputStream extends ProxyInputStream { @Override public int read() throws IOException { final int b = readFirstBytes(); return b >= 0 ? b : in.read(); } BOMInputStream(final InputStream delegate); BOMInputStream(final InputStream delegate, final boolean include); BOMInputStream(final InputStream delegate, final ByteOrderMark... boms); BOMInputStream(final InputStream delegate, final boolean include, final ByteOrderMark... boms); boolean hasBOM(); boolean hasBOM(final ByteOrderMark bom); ByteOrderMark getBOM(); String getBOMCharsetName(); @Override int read(); @Override int read(final byte[] buf, int off, int len); @Override int read(final byte[] buf); @Override synchronized void mark(final int readlimit); @Override synchronized void reset(); @Override long skip(long n); }
|
@Test public void testEmptyBufferWithBOM() throws Exception { final byte[] data = new byte[] {}; final InputStream in = new BOMInputStream(createUtf8DataStream(data, true)); final byte[] buf = new byte[1024]; assertEquals(-1, in.read(buf)); in.close(); }
@Test public void testEmptyBufferWithoutBOM() throws Exception { final byte[] data = new byte[] {}; final InputStream in = new BOMInputStream(createUtf8DataStream(data, false)); final byte[] buf = new byte[1024]; assertEquals(-1, in.read(buf)); in.close(); }
@Test public void testLargeBufferWithBOM() throws Exception { final byte[] data = new byte[] { 'A', 'B', 'C' }; final InputStream in = new BOMInputStream(createUtf8DataStream(data, true)); final byte[] buf = new byte[1024]; assertData(data, buf, in.read(buf)); in.close(); }
@Test public void testLargeBufferWithoutBOM() throws Exception { final byte[] data = new byte[] { 'A', 'B', 'C' }; final InputStream in = new BOMInputStream(createUtf8DataStream(data, false)); final byte[] buf = new byte[1024]; assertData(data, buf, in.read(buf)); in.close(); }
@Test public void testLeadingNonBOMBufferedRead() throws Exception { final byte[] data = new byte[] { (byte) 0xEF, (byte) 0xAB, (byte) 0xCD }; final InputStream in = new BOMInputStream(createUtf8DataStream(data, false)); final byte[] buf = new byte[1024]; assertData(data, buf, in.read(buf)); in.close(); }
@Test public void testLeadingNonBOMSingleRead() throws Exception { final byte[] data = new byte[] { (byte) 0xEF, (byte) 0xAB, (byte) 0xCD }; final InputStream in = new BOMInputStream(createUtf8DataStream(data, false)); assertEquals(0xEF, in.read()); assertEquals(0xAB, in.read()); assertEquals(0xCD, in.read()); assertEquals(-1, in.read()); in.close(); }
@Test public void testSmallBufferWithBOM() throws Exception { final byte[] data = new byte[] { 'A', 'B', 'C' }; final InputStream in = new BOMInputStream(createUtf8DataStream(data, true)); final byte[] buf = new byte[1024]; assertData(new byte[] { 'A', 'B' }, buf, in.read(buf, 0, 2)); assertData(new byte[] { 'C' }, buf, in.read(buf, 0, 2)); in.close(); }
@Test public void testSmallBufferWithoutBOM() throws Exception { final byte[] data = new byte[] { 'A', 'B', 'C' }; final InputStream in = new BOMInputStream(createUtf8DataStream(data, false)); final byte[] buf = new byte[1024]; assertData(new byte[] { 'A', 'B' }, buf, in.read(buf, 0, 2)); assertData(new byte[] { 'C' }, buf, in.read(buf, 0, 2)); in.close(); }
@Test public void testSupportCode() throws Exception { final InputStream in = createUtf8DataStream(new byte[] { 'A', 'B' }, true); final byte[] buf = new byte[1024]; final int len = in.read(buf); assertEquals(5, len); assertEquals(0xEF, buf[0] & 0xFF); assertEquals(0xBB, buf[1] & 0xFF); assertEquals(0xBF, buf[2] & 0xFF); assertEquals('A', buf[3] & 0xFF); assertEquals('B', buf[4] & 0xFF); assertData( new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF, 'A', 'B' }, buf, len); }
|
NullInputStream extends InputStream { @Override public int read() throws IOException { if (eof) { throw new IOException("Read after end of file"); } if (position == size) { return doEndOfFile(); } position++; return processByte(); } NullInputStream(final long size); NullInputStream(final long size, final boolean markSupported, final boolean throwEofException); long getPosition(); long getSize(); @Override int available(); @Override void close(); @Override synchronized void mark(final int readlimit); @Override boolean markSupported(); @Override int read(); @Override int read(final byte[] bytes); @Override int read(final byte[] bytes, final int offset, final int length); @Override synchronized void reset(); @Override long skip(final long numberOfBytes); }
|
@Test public void testRead() throws Exception { final int size = 5; final InputStream input = new TestNullInputStream(size); for (int i = 0; i < size; i++) { assertEquals("Check Size [" + i + "]", size - i, input.available()); assertEquals("Check Value [" + i + "]", i, input.read()); } assertEquals("Available after contents all read", 0, input.available()); assertEquals("End of File", -1, input.read()); assertEquals("Available after End of File", 0, input.available()); try { final int result = input.read(); fail("Should have thrown an IOException, byte=[" + result + "]"); } catch (final IOException e) { assertEquals("Read after end of file", e.getMessage()); } input.close(); assertEquals("Available after close", size, input.available()); }
|
NullInputStream extends InputStream { @Override public long skip(final long numberOfBytes) throws IOException { if (eof) { throw new IOException("Skip after end of file"); } if (position == size) { return doEndOfFile(); } position += numberOfBytes; long returnLength = numberOfBytes; if (position > size) { returnLength = numberOfBytes - (position - size); position = size; } return returnLength; } NullInputStream(final long size); NullInputStream(final long size, final boolean markSupported, final boolean throwEofException); long getPosition(); long getSize(); @Override int available(); @Override void close(); @Override synchronized void mark(final int readlimit); @Override boolean markSupported(); @Override int read(); @Override int read(final byte[] bytes); @Override int read(final byte[] bytes, final int offset, final int length); @Override synchronized void reset(); @Override long skip(final long numberOfBytes); }
|
@Test public void testSkip() throws Exception { final InputStream input = new TestNullInputStream(10, true, false); assertEquals("Read 1", 0, input.read()); assertEquals("Read 2", 1, input.read()); assertEquals("Skip 1", 5, input.skip(5)); assertEquals("Read 3", 7, input.read()); assertEquals("Skip 2", 2, input.skip(5)); assertEquals("Skip 3 (EOF)", -1, input.skip(5)); try { input.skip(5); fail("Expected IOException for skipping after end of file"); } catch (final IOException e) { assertEquals("Skip after EOF IOException message", "Skip after end of file", e.getMessage()); } input.close(); }
|
CharSequenceReader extends Reader implements Serializable { @Override public void close() { idx = 0; mark = 0; } CharSequenceReader(final CharSequence charSequence); @Override void close(); @Override void mark(final int readAheadLimit); @Override boolean markSupported(); @Override int read(); @Override int read(final char[] array, final int offset, final int length); @Override void reset(); @Override long skip(final long n); @Override String toString(); }
|
@Test public void testClose() throws IOException { final Reader reader = new CharSequenceReader("FooBar"); checkRead(reader, "Foo"); reader.close(); checkRead(reader, "Foo"); }
|
CharSequenceReader extends Reader implements Serializable { @Override public boolean markSupported() { return true; } CharSequenceReader(final CharSequence charSequence); @Override void close(); @Override void mark(final int readAheadLimit); @Override boolean markSupported(); @Override int read(); @Override int read(final char[] array, final int offset, final int length); @Override void reset(); @Override long skip(final long n); @Override String toString(); }
|
@Test public void testMarkSupported() throws Exception { final Reader reader = new CharSequenceReader("FooBar"); assertTrue(reader.markSupported()); reader.close(); }
|
CharSequenceReader extends Reader implements Serializable { @Override public void mark(final int readAheadLimit) { mark = idx; } CharSequenceReader(final CharSequence charSequence); @Override void close(); @Override void mark(final int readAheadLimit); @Override boolean markSupported(); @Override int read(); @Override int read(final char[] array, final int offset, final int length); @Override void reset(); @Override long skip(final long n); @Override String toString(); }
|
@Test public void testMark() throws IOException { final Reader reader = new CharSequenceReader("FooBar"); checkRead(reader, "Foo"); reader.mark(0); checkRead(reader, "Bar"); reader.reset(); checkRead(reader, "Bar"); reader.close(); checkRead(reader, "Foo"); reader.reset(); checkRead(reader, "Foo"); }
|
CharSequenceReader extends Reader implements Serializable { @Override public long skip(final long n) { if (n < 0) { throw new IllegalArgumentException( "Number of characters to skip is less than zero: " + n); } if (idx >= charSequence.length()) { return EOF; } final int dest = (int)Math.min(charSequence.length(), idx + n); final int count = dest - idx; idx = dest; return count; } CharSequenceReader(final CharSequence charSequence); @Override void close(); @Override void mark(final int readAheadLimit); @Override boolean markSupported(); @Override int read(); @Override int read(final char[] array, final int offset, final int length); @Override void reset(); @Override long skip(final long n); @Override String toString(); }
|
@Test public void testSkip() throws IOException { final Reader reader = new CharSequenceReader("FooBar"); assertEquals(3, reader.skip(3)); checkRead(reader, "Bar"); assertEquals(-1, reader.skip(3)); reader.reset(); assertEquals(2, reader.skip(2)); assertEquals(4, reader.skip(10)); assertEquals(-1, reader.skip(1)); reader.close(); assertEquals(6, reader.skip(20)); assertEquals(-1, reader.read()); }
|
CharSequenceReader extends Reader implements Serializable { @Override public int read() { if (idx >= charSequence.length()) { return EOF; } else { return charSequence.charAt(idx++); } } CharSequenceReader(final CharSequence charSequence); @Override void close(); @Override void mark(final int readAheadLimit); @Override boolean markSupported(); @Override int read(); @Override int read(final char[] array, final int offset, final int length); @Override void reset(); @Override long skip(final long n); @Override String toString(); }
|
@Test public void testRead() throws IOException { final Reader reader = new CharSequenceReader("Foo"); assertEquals('F', reader.read()); assertEquals('o', reader.read()); assertEquals('o', reader.read()); assertEquals(-1, reader.read()); assertEquals(-1, reader.read()); reader.close(); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public boolean readBoolean() throws IOException, EOFException { return 0 != readByte(); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadBoolean() throws IOException { bytes = new byte[] { 0x00, 0x01, 0x02, }; final ByteArrayInputStream bais = new ByteArrayInputStream( bytes ); final SwappedDataInputStream sdis = new SwappedDataInputStream( bais ); assertEquals( false, sdis.readBoolean() ); assertEquals( true, sdis.readBoolean() ); assertEquals( true, sdis.readBoolean() ); sdis.close(); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public byte readByte() throws IOException, EOFException { return (byte)in.read(); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadByte() throws IOException { assertEquals( 0x01, this.sdis.readByte() ); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public char readChar() throws IOException, EOFException { return (char)readShort(); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadChar() throws IOException { assertEquals( (char) 0x0201, this.sdis.readChar() ); }
|
Elements extends ArrayList<Element> { private Elements siblings(String query, boolean next, boolean all) { Elements els = new Elements(); Evaluator eval = query != null? QueryParser.parse(query) : null; for (Element e : this) { do { Element sib = next ? e.nextElementSibling() : e.previousElementSibling(); if (sib == null) break; if (eval == null) els.add(sib); else if (sib.is(eval)) els.add(sib); e = sib; } while (all); } return els; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void siblings() { Document doc = Jsoup.parse("<div><p>1<p>2<p>3<p>4<p>5<p>6</div><div><p>7<p>8<p>9<p>10<p>11<p>12</div>"); Elements els = doc.select("p:eq(3)"); assertEquals(2, els.size()); Elements next = els.next(); assertEquals(2, next.size()); assertEquals("5", next.first().text()); assertEquals("11", next.last().text()); assertEquals(0, els.next("p:contains(6)").size()); final Elements nextF = els.next("p:contains(5)"); assertEquals(1, nextF.size()); assertEquals("5", nextF.first().text()); Elements nextA = els.nextAll(); assertEquals(4, nextA.size()); assertEquals("5", nextA.first().text()); assertEquals("12", nextA.last().text()); Elements nextAF = els.nextAll("p:contains(6)"); assertEquals(1, nextAF.size()); assertEquals("6", nextAF.first().text()); Elements prev = els.prev(); assertEquals(2, prev.size()); assertEquals("3", prev.first().text()); assertEquals("9", prev.last().text()); assertEquals(0, els.prev("p:contains(1)").size()); final Elements prevF = els.prev("p:contains(3)"); assertEquals(1, prevF.size()); assertEquals("3", prevF.first().text()); Elements prevA = els.prevAll(); assertEquals(6, prevA.size()); assertEquals("3", prevA.first().text()); assertEquals("7", prevA.last().text()); Elements prevAF = els.prevAll("p:contains(1)"); assertEquals(1, prevAF.size()); assertEquals("1", prevAF.first().text()); }
|
ByteObjectArrayTypeHandler extends BaseTypeHandler<Byte[]> { private Byte[] getBytes(byte[] bytes) { Byte[] returnValue = null; if (bytes != null) { returnValue = ByteArrayUtils.convertToObjectArray(bytes); } return returnValue; } @Override void setNonNullParameter(PreparedStatement ps, int index, Byte[] parameter, JdbcType jdbcType); @Override Byte[] getNullableResult(ResultSet rs, int index); @Override JdbcType getJdbcType(); }
|
@Override @Test public void shouldGetResultFromResultSetByPosition() throws Exception { byte[] byteArray = new byte[]{1, 2}; when(rs.getBytes(1)).thenReturn(byteArray); when(rs.wasNull()).thenReturn(false); assertThat(TYPE_HANDLER.getResult(rs, 1), is(new Byte[]{1, 2})); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public double readDouble() throws IOException, EOFException { return EndianUtils.readSwappedDouble( in ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadDouble() throws IOException { assertEquals( Double.longBitsToDouble(0x0807060504030201L), this.sdis.readDouble(), 0 ); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public float readFloat() throws IOException, EOFException { return EndianUtils.readSwappedFloat( in ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadFloat() throws IOException { assertEquals( Float.intBitsToFloat(0x04030201), this.sdis.readFloat(), 0 ); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public void readFully( final byte[] data ) throws IOException, EOFException { readFully( data, 0, data.length ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadFully() throws IOException { final byte[] bytesIn = new byte[8]; this.sdis.readFully(bytesIn); for( int i=0; i<8; i++) { assertEquals( bytes[i], bytesIn[i] ); } }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public int readInt() throws IOException, EOFException { return EndianUtils.readSwappedInteger( in ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadInt() throws IOException { assertEquals( 0x04030201, this.sdis.readInt() ); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public String readLine() throws IOException, EOFException { throw new UnsupportedOperationException( "Operation not supported: readLine()" ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test(expected = UnsupportedOperationException.class) public void testReadLine() throws IOException { this.sdis.readLine(); fail("readLine should be unsupported. "); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public long readLong() throws IOException, EOFException { return EndianUtils.readSwappedLong( in ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadLong() throws IOException { assertEquals( 0x0807060504030201L, this.sdis.readLong() ); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public short readShort() throws IOException, EOFException { return EndianUtils.readSwappedShort( in ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadShort() throws IOException { assertEquals( (short) 0x0201, this.sdis.readShort() ); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public int readUnsignedByte() throws IOException, EOFException { return in.read(); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadUnsignedByte() throws IOException { assertEquals( 0x01, this.sdis.readUnsignedByte() ); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public int readUnsignedShort() throws IOException, EOFException { return EndianUtils.readSwappedUnsignedShort( in ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testReadUnsignedShort() throws IOException { assertEquals( (short) 0x0201, this.sdis.readUnsignedShort() ); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public String readUTF() throws IOException, EOFException { throw new UnsupportedOperationException( "Operation not supported: readUTF()" ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test(expected = UnsupportedOperationException.class) public void testReadUTF() throws IOException { this.sdis.readUTF(); fail("readUTF should be unsupported. "); }
|
Elements extends ArrayList<Element> { public List<String> eachText() { ArrayList<String> texts = new ArrayList<>(size()); for (Element el: this) { if (el.hasText()) texts.add(el.text()); } return texts; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void eachText() { Document doc = Jsoup.parse("<div><p>1<p>2<p>3<p>4<p>5<p>6</div><div><p>7<p>8<p>9<p>10<p>11<p>12<p></p></div>"); List<String> divText = doc.select("div").eachText(); assertEquals(2, divText.size()); assertEquals("1 2 3 4 5 6", divText.get(0)); assertEquals("7 8 9 10 11 12", divText.get(1)); List<String> pText = doc.select("p").eachText(); Elements ps = doc.select("p"); assertEquals(13, ps.size()); assertEquals(12, pText.size()); assertEquals("1", pText.get(0)); assertEquals("2", pText.get(1)); assertEquals("5", pText.get(4)); assertEquals("7", pText.get(6)); assertEquals("12", pText.get(11)); }
|
SwappedDataInputStream extends ProxyInputStream implements DataInput { public int skipBytes( final int count ) throws IOException, EOFException { return (int)in.skip( count ); } SwappedDataInputStream( final InputStream input ); boolean readBoolean(); byte readByte(); char readChar(); double readDouble(); float readFloat(); void readFully( final byte[] data ); void readFully( final byte[] data, final int offset, final int length ); int readInt(); String readLine(); long readLong(); short readShort(); int readUnsignedByte(); int readUnsignedShort(); String readUTF(); int skipBytes( final int count ); }
|
@Test public void testSkipBytes() throws IOException { this.sdis.skipBytes(4); assertEquals( 0x08070605, this.sdis.readInt() ); }
|
Tailer implements Runnable { private void stop(final Exception e) { listener.handle(e); stop(); } Tailer(final File file, final TailerListener listener); Tailer(final File file, final TailerListener listener, final long delayMillis); Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end); Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end,
final boolean reOpen); Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end,
final int bufSize); Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end,
final boolean reOpen, final int bufSize); Tailer(final File file, final Charset cset, final TailerListener listener, final long delayMillis,
final boolean end, final boolean reOpen
, final int bufSize); static Tailer create(final File file, final TailerListener listener, final long delayMillis,
final boolean end, final int bufSize); static Tailer create(final File file, final TailerListener listener, final long delayMillis,
final boolean end, final boolean reOpen,
final int bufSize); static Tailer create(final File file, final Charset charset, final TailerListener listener,
final long delayMillis, final boolean end, final boolean reOpen
,final int bufSize); static Tailer create(final File file, final TailerListener listener, final long delayMillis,
final boolean end); static Tailer create(final File file, final TailerListener listener, final long delayMillis,
final boolean end, final boolean reOpen); static Tailer create(final File file, final TailerListener listener, final long delayMillis); static Tailer create(final File file, final TailerListener listener); File getFile(); long getDelay(); void run(); void stop(); }
|
@SuppressWarnings("deprecation") @Test public void testMultiByteBreak() throws Exception { System.out.println("testMultiByteBreak() Default charset: "+Charset.defaultCharset().displayName()); final long delay = 50; final File origin = new File(this.getClass().getResource("/test-file-utf8.bin").toURI()); final File file = new File(getTestDirectory(), "testMultiByteBreak.txt"); createFile(file, 0); final TestTailerListener listener = new TestTailerListener(); final String osname = System.getProperty("os.name"); final boolean isWindows = osname.startsWith("Windows"); final Charset charsetUTF8 = Charsets.UTF_8; tailer = new Tailer(file, charsetUTF8, listener, delay, false, isWindows, 4096); final Thread thread = new Thread(tailer); thread.start(); Writer out = new OutputStreamWriter(new FileOutputStream(file), charsetUTF8); BufferedReader reader = null; try{ List<String> lines = new ArrayList<String>(); reader = new BufferedReader(new InputStreamReader(new FileInputStream(origin), charsetUTF8)); String line; while((line = reader.readLine()) != null){ out.write(line); out.write("\n"); lines.add(line); } out.close(); final long testDelayMillis = delay * 10; TestUtils.sleep(testDelayMillis); List<String> tailerlines = listener.getLines(); assertEquals("line count",lines.size(),tailerlines.size()); for(int i = 0,len = lines.size();i<len;i++){ final String expected = lines.get(i); final String actual = tailerlines.get(i); if (!expected.equals(actual)) { fail("Line: " + i + "\nExp: (" + expected.length() + ") " + expected + "\nAct: (" + actual.length() + ") "+ actual); } } }finally{ tailer.stop(); IOUtils.closeQuietly(reader); IOUtils.closeQuietly(out); } }
@Test public void testTailerEof() throws Exception { final long delay = 50; final File file = new File(getTestDirectory(), "tailer2-test.txt"); createFile(file, 0); final TestTailerListener listener = new TestTailerListener(); final Tailer tailer = new Tailer(file, listener, delay, false); final Thread thread = new Thread(tailer); thread.start(); final FileWriter writer = null; try { writeString(file, "Line"); TestUtils.sleep(delay * 2); List<String> lines = listener.getLines(); assertEquals("1 line count", 0, lines.size()); writeString(file, " one\n"); TestUtils.sleep(delay * 2); lines = listener.getLines(); assertEquals("1 line count", 1, lines.size()); assertEquals("1 line 1", "Line one", lines.get(0)); listener.clear(); } finally { tailer.stop(); TestUtils.sleep(delay * 2); IOUtils.closeQuietly(writer); } }
@Test public void testStopWithNoFileUsingExecutor() throws Exception { final File file = new File(getTestDirectory(),"nosuchfile"); assertFalse("nosuchfile should not exist", file.exists()); final TestTailerListener listener = new TestTailerListener(); final int delay = 100; final int idle = 50; tailer = new Tailer(file, listener, delay, false); final Executor exec = new ScheduledThreadPoolExecutor(1); exec.execute(tailer); TestUtils.sleep(idle); tailer.stop(); tailer=null; TestUtils.sleep(delay+idle); assertNull("Should not generate Exception", listener.exception); assertEquals("Expected init to be called", 1 , listener.initialised); assertTrue("fileNotFound should be called", listener.notFound > 0); assertEquals("fileRotated should be not be called", 0 , listener.rotated); assertEquals("end of file never reached", 0, listener.reachedEndOfFile); }
@Test public void testIO335() throws Exception { final long delayMillis = 50; final File file = new File(getTestDirectory(), "tailer-testio334.txt"); createFile(file, 0); final TestTailerListener listener = new TestTailerListener(); tailer = new Tailer(file, listener, delayMillis, false); final Thread thread = new Thread(tailer); thread.start(); writeString(file, "CRLF\r\n", "LF\n", "CR\r", "CRCR\r\r", "trail"); final long testDelayMillis = delayMillis * 10; TestUtils.sleep(testDelayMillis); final List<String> lines = listener.getLines(); assertEquals("line count", 4, lines.size()); assertEquals("line 1", "CRLF", lines.get(0)); assertEquals("line 2", "LF", lines.get(1)); assertEquals("line 3", "CR", lines.get(2)); assertEquals("line 4", "CRCR\r", lines.get(3)); tailer.stop(); tailer=null; thread.interrupt(); TestUtils.sleep(testDelayMillis); }
|
Tailer implements Runnable { public Tailer(final File file, final TailerListener listener) { this(file, listener, DEFAULT_DELAY_MILLIS); } Tailer(final File file, final TailerListener listener); Tailer(final File file, final TailerListener listener, final long delayMillis); Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end); Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end,
final boolean reOpen); Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end,
final int bufSize); Tailer(final File file, final TailerListener listener, final long delayMillis, final boolean end,
final boolean reOpen, final int bufSize); Tailer(final File file, final Charset cset, final TailerListener listener, final long delayMillis,
final boolean end, final boolean reOpen
, final int bufSize); static Tailer create(final File file, final TailerListener listener, final long delayMillis,
final boolean end, final int bufSize); static Tailer create(final File file, final TailerListener listener, final long delayMillis,
final boolean end, final boolean reOpen,
final int bufSize); static Tailer create(final File file, final Charset charset, final TailerListener listener,
final long delayMillis, final boolean end, final boolean reOpen
,final int bufSize); static Tailer create(final File file, final TailerListener listener, final long delayMillis,
final boolean end); static Tailer create(final File file, final TailerListener listener, final long delayMillis,
final boolean end, final boolean reOpen); static Tailer create(final File file, final TailerListener listener, final long delayMillis); static Tailer create(final File file, final TailerListener listener); File getFile(); long getDelay(); void run(); void stop(); }
|
@Test public void testTailer() throws Exception { final long delayMillis = 50; final File file = new File(getTestDirectory(), "tailer1-test.txt"); createFile(file, 0); final TestTailerListener listener = new TestTailerListener(); final String osname = System.getProperty("os.name"); final boolean isWindows = osname.startsWith("Windows"); tailer = new Tailer(file, listener, delayMillis, false, isWindows); final Thread thread = new Thread(tailer); thread.start(); write(file, "Line one", "Line two"); final long testDelayMillis = delayMillis * 10; TestUtils.sleep(testDelayMillis); List<String> lines = listener.getLines(); assertEquals("1 line count", 2, lines.size()); assertEquals("1 line 1", "Line one", lines.get(0)); assertEquals("1 line 2", "Line two", lines.get(1)); listener.clear(); write(file, "Line three"); TestUtils.sleep(testDelayMillis); lines = listener.getLines(); assertEquals("2 line count", 1, lines.size()); assertEquals("2 line 3", "Line three", lines.get(0)); listener.clear(); lines = FileUtils.readLines(file, "UTF-8"); assertEquals("3 line count", 3, lines.size()); assertEquals("3 line 1", "Line one", lines.get(0)); assertEquals("3 line 2", "Line two", lines.get(1)); assertEquals("3 line 3", "Line three", lines.get(2)); file.delete(); final boolean exists = file.exists(); assertFalse("File should not exist", exists); createFile(file, 0); TestUtils.sleep(testDelayMillis); write(file, "Line four"); TestUtils.sleep(testDelayMillis); lines = listener.getLines(); assertEquals("4 line count", 1, lines.size()); assertEquals("4 line 3", "Line four", lines.get(0)); listener.clear(); thread.interrupt(); TestUtils.sleep(testDelayMillis * 4); write(file, "Line five"); assertEquals("4 line count", 0, listener.getLines().size()); assertNotNull("Missing InterruptedException", listener.exception); assertTrue("Unexpected Exception: " + listener.exception, listener.exception instanceof InterruptedException); assertEquals("Expected init to be called", 1 , listener.initialised); assertEquals("fileNotFound should not be called", 0 , listener.notFound); assertEquals("fileRotated should be be called", 1 , listener.rotated); tailer.stop(); tailer=null; }
|
XmlStreamReader extends Reader { public String getEncoding() { return encoding; } XmlStreamReader(final File file); XmlStreamReader(final InputStream is); XmlStreamReader(final InputStream is, final boolean lenient); XmlStreamReader(final InputStream is, final boolean lenient, final String defaultEncoding); XmlStreamReader(final URL url); XmlStreamReader(final URLConnection conn, final String defaultEncoding); XmlStreamReader(final InputStream is, final String httpContentType); XmlStreamReader(final InputStream is, final String httpContentType,
final boolean lenient, final String defaultEncoding); XmlStreamReader(final InputStream is, final String httpContentType,
final boolean lenient); String getDefaultEncoding(); String getEncoding(); @Override int read(final char[] buf, final int offset, final int len); @Override void close(); static final Pattern ENCODING_PATTERN; }
|
@Test public void testRawContent() throws Exception { final String encoding = "UTF-8"; final String xml = getXML("no-bom", XML3, encoding, encoding); final ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes(encoding)); final XmlStreamReader xmlReader = new XmlStreamReader(is); assertEquals("Check encoding", xmlReader.getEncoding(), encoding); assertEquals("Check content", xml, IOUtils.toString(xmlReader)); }
@Test public void testHttpContent() throws Exception { final String encoding = "UTF-8"; final String xml = getXML("no-bom", XML3, encoding, encoding); final ByteArrayInputStream is = new ByteArrayInputStream(xml.getBytes(encoding)); final XmlStreamReader xmlReader = new XmlStreamReader(is, encoding); assertEquals("Check encoding", xmlReader.getEncoding(), encoding); assertEquals("Check content", xml, IOUtils.toString(xmlReader)); }
|
BoundedReader extends Reader { @Override public void close() throws IOException { target.close(); } BoundedReader( Reader target, int maxCharsFromTargetReader ); @Override void close(); @Override void reset(); @Override void mark( int readAheadLimit ); @Override int read(); @Override int read( char[] cbuf, int off, int len ); }
|
@Test public void closeTest() throws IOException { final AtomicBoolean closed = new AtomicBoolean( false ); final Reader sr = new BufferedReader( new StringReader( "01234567890" ) ) { @Override public void close() throws IOException { closed.set( true ); super.close(); } }; BoundedReader mr = new BoundedReader( sr, 3 ); mr.close(); assertTrue( closed.get() ); }
|
BoundedInputStream extends InputStream { @Override public int read() throws IOException { if (max >= 0 && pos >= max) { return EOF; } final int result = in.read(); pos++; return result; } BoundedInputStream(final InputStream in, final long size); BoundedInputStream(final InputStream in); @Override int read(); @Override int read(final byte[] b); @Override int read(final byte[] b, final int off, final int len); @Override long skip(final long n); @Override int available(); @Override String toString(); @Override void close(); @Override synchronized void reset(); @Override synchronized void mark(final int readlimit); @Override boolean markSupported(); boolean isPropagateClose(); void setPropagateClose(final boolean propagateClose); }
|
@Test public void testReadSingle() throws Exception { BoundedInputStream bounded; final byte[] helloWorld = "Hello World".getBytes(); final byte[] hello = "Hello".getBytes(); bounded = new BoundedInputStream(new ByteArrayInputStream(helloWorld), helloWorld.length); for (int i = 0; i < helloWorld.length; i++) { assertEquals("limit = length byte[" + i + "]", helloWorld[i], bounded.read()); } assertEquals("limit = length end", -1, bounded.read()); bounded = new BoundedInputStream(new ByteArrayInputStream(helloWorld), helloWorld.length + 1); for (int i = 0; i < helloWorld.length; i++) { assertEquals("limit > length byte[" + i + "]", helloWorld[i], bounded.read()); } assertEquals("limit > length end", -1, bounded.read()); bounded = new BoundedInputStream(new ByteArrayInputStream(helloWorld), hello.length); for (int i = 0; i < hello.length; i++) { assertEquals("limit < length byte[" + i + "]", hello[i], bounded.read()); } assertEquals("limit < length end", -1, bounded.read()); }
|
Elements extends ArrayList<Element> { public List<String> eachAttr(String attributeKey) { List<String> attrs = new ArrayList<>(size()); for (Element element : this) { if (element.hasAttr(attributeKey)) attrs.add(element.attr(attributeKey)); } return attrs; } Elements(); Elements(int initialCapacity); Elements(Collection<Element> elements); Elements(List<Element> elements); Elements(Element... elements); @Override Elements clone(); String attr(String attributeKey); boolean hasAttr(String attributeKey); List<String> eachAttr(String attributeKey); Elements attr(String attributeKey, String attributeValue); Elements removeAttr(String attributeKey); Elements addClass(String className); Elements removeClass(String className); Elements toggleClass(String className); boolean hasClass(String className); String val(); Elements val(String value); String text(); boolean hasText(); List<String> eachText(); String html(); String outerHtml(); @Override String toString(); Elements tagName(String tagName); Elements html(String html); Elements prepend(String html); Elements append(String html); Elements before(String html); Elements after(String html); Elements wrap(String html); Elements unwrap(); Elements empty(); Elements remove(); Elements select(String query); Elements not(String query); Elements eq(int index); boolean is(String query); Elements next(); Elements next(String query); Elements nextAll(); Elements nextAll(String query); Elements prev(); Elements prev(String query); Elements prevAll(); Elements prevAll(String query); Elements parents(); Element first(); Element last(); Elements traverse(NodeVisitor nodeVisitor); List<FormElement> forms(); }
|
@Test public void eachAttr() { Document doc = Jsoup.parse( "<div><a href='/foo'>1</a><a href='http: "http: List<String> hrefAttrs = doc.select("a").eachAttr("href"); assertEquals(3, hrefAttrs.size()); assertEquals("/foo", hrefAttrs.get(0)); assertEquals("http: assertEquals("", hrefAttrs.get(2)); assertEquals(4, doc.select("a").size()); List<String> absAttrs = doc.select("a").eachAttr("abs:href"); assertEquals(3, absAttrs.size()); assertEquals(3, absAttrs.size()); assertEquals("http: assertEquals("http: assertEquals("http: }
|
BrokenInputStream extends InputStream { @Override public int read() throws IOException { throw exception; } BrokenInputStream(final IOException exception); BrokenInputStream(); @Override int read(); @Override int available(); @Override long skip(final long n); @Override synchronized void reset(); @Override void close(); }
|
@Test public void testRead() { try { stream.read(); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } try { stream.read(new byte[1]); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } try { stream.read(new byte[1], 0, 1); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } }
|
BrokenInputStream extends InputStream { @Override public int available() throws IOException { throw exception; } BrokenInputStream(final IOException exception); BrokenInputStream(); @Override int read(); @Override int available(); @Override long skip(final long n); @Override synchronized void reset(); @Override void close(); }
|
@Test public void testAvailable() { try { stream.available(); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } }
|
BrokenInputStream extends InputStream { @Override public long skip(final long n) throws IOException { throw exception; } BrokenInputStream(final IOException exception); BrokenInputStream(); @Override int read(); @Override int available(); @Override long skip(final long n); @Override synchronized void reset(); @Override void close(); }
|
@Test public void testSkip() { try { stream.skip(1); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } }
|
BrokenInputStream extends InputStream { @Override public synchronized void reset() throws IOException { throw exception; } BrokenInputStream(final IOException exception); BrokenInputStream(); @Override int read(); @Override int available(); @Override long skip(final long n); @Override synchronized void reset(); @Override void close(); }
|
@Test public void testReset() { try { stream.reset(); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } }
|
BrokenInputStream extends InputStream { @Override public void close() throws IOException { throw exception; } BrokenInputStream(final IOException exception); BrokenInputStream(); @Override int read(); @Override int available(); @Override long skip(final long n); @Override synchronized void reset(); @Override void close(); }
|
@Test public void testClose() { try { stream.close(); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } }
|
CountingInputStream extends ProxyInputStream { public int getCount() { final long result = getByteCount(); if (result > Integer.MAX_VALUE) { throw new ArithmeticException("The byte count " + result + " is too large to be converted to an int"); } return (int) result; } CountingInputStream(final InputStream in); @Override synchronized long skip(final long length); int getCount(); int resetCount(); synchronized long getByteCount(); synchronized long resetByteCount(); }
|
@Test public void testCounting() throws Exception { final String text = "A piece of text"; final byte[] bytes = text.getBytes(); final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[21]; final byte[] ba = new byte[5]; int found = cis.read(ba); System.arraycopy(ba, 0, result, 0, 5); assertEquals( found, cis.getCount() ); final int value = cis.read(); found++; result[5] = (byte)value; assertEquals( found, cis.getCount() ); found += cis.read(result, 6, 5); assertEquals( found, cis.getCount() ); found += cis.read(result, 11, 10); assertEquals( found, cis.getCount() ); final String textResult = new String(result).trim(); assertEquals(textResult, text); cis.close(); }
@Test public void testZeroLength1() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); final CountingInputStream cis = new CountingInputStream(bais); final int found = cis.read(); assertEquals(-1, found); assertEquals(0, cis.getCount()); cis.close(); }
@Test public void testZeroLength2() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[10]; final int found = cis.read(result); assertEquals(-1, found); assertEquals(0, cis.getCount()); cis.close(); }
@Test public void testZeroLength3() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[10]; final int found = cis.read(result, 0, 5); assertEquals(-1, found); assertEquals(0, cis.getCount()); cis.close(); }
@Test public void testEOF1() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]); final CountingInputStream cis = new CountingInputStream(bais); int found = cis.read(); assertEquals(0, found); assertEquals(1, cis.getCount()); found = cis.read(); assertEquals(0, found); assertEquals(2, cis.getCount()); found = cis.read(); assertEquals(-1, found); assertEquals(2, cis.getCount()); cis.close(); }
@Test public void testEOF2() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[10]; final int found = cis.read(result); assertEquals(2, found); assertEquals(2, cis.getCount()); cis.close(); }
@Test public void testEOF3() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[10]; final int found = cis.read(result, 0, 5); assertEquals(2, found); assertEquals(2, cis.getCount()); cis.close(); }
|
Selector { public static Elements select(String query, Element root) { return new Selector(query, root).select(); } private Selector(String query, Element root); private Selector(Evaluator evaluator, Element root); static Elements select(String query, Element root); static Elements select(Evaluator evaluator, Element root); static Elements select(String query, Iterable<Element> roots); }
|
@Test public void testByTag() { Elements els = Jsoup.parse("<div id=1><div id=2><p>Hello</p></div></div><DIV id=3>").select("DIV"); assertEquals(3, els.size()); assertEquals("1", els.get(0).id()); assertEquals("2", els.get(1).id()); assertEquals("3", els.get(2).id()); Elements none = Jsoup.parse("<div id=1><div id=2><p>Hello</p></div></div><div id=3>").select("span"); assertEquals(0, none.size()); }
@Test public void testByClass() { Elements els = Jsoup.parse("<p id=0 class='ONE two'><p id=1 class='one'><p id=2 class='two'>").select("P.One"); assertEquals(2, els.size()); assertEquals("0", els.get(0).id()); assertEquals("1", els.get(1).id()); Elements none = Jsoup.parse("<div class='one'></div>").select(".foo"); assertEquals(0, none.size()); Elements els2 = Jsoup.parse("<div class='One-Two'></div>").select(".one-two"); assertEquals(1, els2.size()); }
@Test public void testByClassCaseInsensitive() { String html = "<p Class=foo>One <p Class=Foo>Two <p class=FOO>Three <p class=farp>Four"; Elements elsFromClass = Jsoup.parse(html).select("P.Foo"); Elements elsFromAttr = Jsoup.parse(html).select("p[class=foo]"); assertEquals(elsFromAttr.size(), elsFromClass.size()); assertEquals(3, elsFromClass.size()); assertEquals("Two", elsFromClass.get(1).text()); }
@Test @MultiLocaleTest public void testByAttribute() { String h = "<div Title=Foo /><div Title=Bar /><div Style=Qux /><div title=Balim /><div title=SLIM />" + "<div data-name='with spaces'/>"; Document doc = Jsoup.parse(h); Elements withTitle = doc.select("[title]"); assertEquals(4, withTitle.size()); Elements foo = doc.select("[TITLE=foo]"); assertEquals(1, foo.size()); Elements foo2 = doc.select("[title=\"foo\"]"); assertEquals(1, foo2.size()); Elements foo3 = doc.select("[title=\"Foo\"]"); assertEquals(1, foo3.size()); Elements dataName = doc.select("[data-name=\"with spaces\"]"); assertEquals(1, dataName.size()); assertEquals("with spaces", dataName.first().attr("data-name")); Elements not = doc.select("div[title!=bar]"); assertEquals(5, not.size()); assertEquals("Foo", not.first().attr("title")); Elements starts = doc.select("[title^=ba]"); assertEquals(2, starts.size()); assertEquals("Bar", starts.first().attr("title")); assertEquals("Balim", starts.last().attr("title")); Elements ends = doc.select("[title$=im]"); assertEquals(2, ends.size()); assertEquals("Balim", ends.first().attr("title")); assertEquals("SLIM", ends.last().attr("title")); Elements contains = doc.select("[title*=i]"); assertEquals(2, contains.size()); assertEquals("Balim", contains.first().attr("title")); assertEquals("SLIM", contains.last().attr("title")); }
@Test public void testWildcardNamespacedTag() { Document doc = Jsoup.parse("<div><abc:def id=1>Hello</abc:def></div> <abc:def class=bold id=2>There</abc:def>"); Elements byTag = doc.select("*|def"); assertEquals(2, byTag.size()); assertEquals("1", byTag.first().id()); assertEquals("2", byTag.last().id()); Elements byAttr = doc.select(".bold"); assertEquals(1, byAttr.size()); assertEquals("2", byAttr.last().id()); Elements byTagAttr = doc.select("*|def.bold"); assertEquals(1, byTagAttr.size()); assertEquals("2", byTagAttr.last().id()); Elements byContains = doc.select("*|def:contains(e)"); assertEquals(2, byContains.size()); assertEquals("1", byContains.first().id()); assertEquals("2", byContains.last().id()); }
@Test @MultiLocaleTest public void testByAttributeStarting() { Document doc = Jsoup.parse("<div id=1 ATTRIBUTE data-name=jsoup>Hello</div><p data-val=5 id=2>There</p><p id=3>No</p>"); Elements withData = doc.select("[^data-]"); assertEquals(2, withData.size()); assertEquals("1", withData.first().id()); assertEquals("2", withData.last().id()); withData = doc.select("p[^data-]"); assertEquals(1, withData.size()); assertEquals("2", withData.first().id()); assertEquals(1, doc.select("[^attrib]").size()); }
@Test public void descendant() { String h = "<div class=head><p class=first>Hello</p><p>There</p></div><p>None</p>"; Document doc = Jsoup.parse(h); Element root = doc.getElementsByClass("HEAD").first(); Elements els = root.select(".head p"); assertEquals(2, els.size()); assertEquals("Hello", els.get(0).text()); assertEquals("There", els.get(1).text()); Elements p = root.select("p.first"); assertEquals(1, p.size()); assertEquals("Hello", p.get(0).text()); Elements empty = root.select("p .first"); assertEquals(0, empty.size()); Elements aboveRoot = root.select("body div.head"); assertEquals(0, aboveRoot.size()); }
@Test public void caseInsensitive() { String h = "<dIv tItle=bAr><div>"; Document doc = Jsoup.parse(h); assertEquals(2, doc.select("DiV").size()); assertEquals(1, doc.select("DiV[TiTLE]").size()); assertEquals(1, doc.select("DiV[TiTLE=BAR]").size()); assertEquals(0, doc.select("DiV[TiTLE=BARBARELLA]").size()); }
@Test public void testPseudoHas() { Document doc = Jsoup.parse("<div id=0><p><span>Hello</span></p></div> <div id=1><span class=foo>There</span></div> <div id=2><p>Not</p></div>"); Elements divs1 = doc.select("div:has(span)"); assertEquals(2, divs1.size()); assertEquals("0", divs1.get(0).id()); assertEquals("1", divs1.get(1).id()); Elements divs2 = doc.select("div:has([class])"); assertEquals(1, divs2.size()); assertEquals("1", divs2.get(0).id()); Elements divs3 = doc.select("div:has(span, p)"); assertEquals(3, divs3.size()); assertEquals("0", divs3.get(0).id()); assertEquals("1", divs3.get(1).id()); assertEquals("2", divs3.get(2).id()); Elements els1 = doc.body().select(":has(p)"); assertEquals(3, els1.size()); assertEquals("body", els1.first().tagName()); assertEquals("0", els1.get(1).id()); assertEquals("2", els1.get(2).id()); }
@Test @MultiLocaleTest public void testPseudoContains() { Document doc = Jsoup.parse("<div><p>The Rain.</p> <p class=light>The <i>RAIN</i>.</p> <p>Rain, the.</p></div>"); Elements ps1 = doc.select("p:contains(Rain)"); assertEquals(3, ps1.size()); Elements ps2 = doc.select("p:contains(the rain)"); assertEquals(2, ps2.size()); assertEquals("The Rain.", ps2.first().html()); assertEquals("The <i>RAIN</i>.", ps2.last().html()); Elements ps3 = doc.select("p:contains(the Rain):has(i)"); assertEquals(1, ps3.size()); assertEquals("light", ps3.first().className()); Elements ps4 = doc.select(".light:contains(rain)"); assertEquals(1, ps4.size()); assertEquals("light", ps3.first().className()); Elements ps5 = doc.select(":contains(rain)"); assertEquals(8, ps5.size()); Elements ps6 = doc.select(":contains(RAIN)"); assertEquals(8, ps6.size()); }
@Test @MultiLocaleTest public void containsOwn() { Document doc = Jsoup.parse("<p id=1>Hello <b>there</b> igor</p>"); Elements ps = doc.select("p:containsOwn(Hello IGOR)"); assertEquals(1, ps.size()); assertEquals("1", ps.first().id()); assertEquals(0, doc.select("p:containsOwn(there)").size()); Document doc2 = Jsoup.parse("<p>Hello <b>there</b> IGOR</p>"); assertEquals(1, doc2.select("p:containsOwn(igor)").size()); }
@Test public void attributeWithBrackets() { String html = "<div data='End]'>One</div> <div data='[Another)]]'>Two</div>"; Document doc = Jsoup.parse(html); assertEquals("One", doc.select("div[data='End]']").first().text()); assertEquals("Two", doc.select("div[data='[Another)]]']").first().text()); assertEquals("One", doc.select("div[data=\"End]\"]").first().text()); assertEquals("Two", doc.select("div[data=\"[Another)]]\"]").first().text()); }
@Test @MultiLocaleTest public void containsData() { String html = "<p>function</p><script>FUNCTION</script><style>item</style><span><!-- comments --></span>"; Document doc = Jsoup.parse(html); Element body = doc.body(); Elements dataEls1 = body.select(":containsData(function)"); Elements dataEls2 = body.select("script:containsData(function)"); Elements dataEls3 = body.select("span:containsData(comments)"); Elements dataEls4 = body.select(":containsData(o)"); Elements dataEls5 = body.select("style:containsData(ITEM)"); assertEquals(2, dataEls1.size()); assertEquals(1, dataEls2.size()); assertEquals(dataEls1.last(), dataEls2.first()); assertEquals("<script>FUNCTION</script>", dataEls2.outerHtml()); assertEquals(1, dataEls3.size()); assertEquals("span", dataEls3.first().tagName()); assertEquals(3, dataEls4.size()); assertEquals("body", dataEls4.first().tagName()); assertEquals("script", dataEls4.get(1).tagName()); assertEquals("span", dataEls4.get(2).tagName()); assertEquals(1, dataEls5.size()); }
@Test public void containsWithQuote() { String html = "<p>One'One</p><p>One'Two</p>"; Document doc = Jsoup.parse(html); Elements els = doc.select("p:contains(One\\'One)"); assertEquals(1, els.size()); assertEquals("One'One", els.text()); }
@Test public void testByTag() { Elements els = Jsoup.parse("<div id=1><div id=2><p>Hello</p></div></div><div id=3>").select("div"); assertEquals(3, els.size()); assertEquals("1", els.get(0).id()); assertEquals("2", els.get(1).id()); assertEquals("3", els.get(2).id()); Elements none = Jsoup.parse("<div id=1><div id=2><p>Hello</p></div></div><div id=3>").select("span"); assertEquals(0, none.size()); }
@Test public void testById() { Elements els = Jsoup.parse("<div><p id=foo>Hello</p><p id=foo>Foo two!</p></div>").select("#foo"); assertEquals(2, els.size()); assertEquals("Hello", els.get(0).text()); assertEquals("Foo two!", els.get(1).text()); Elements none = Jsoup.parse("<div id=1></div>").select("#foo"); assertEquals(0, none.size()); }
@Test public void testByClass() { Elements els = Jsoup.parse("<p id=0 class='one two'><p id=1 class='one'><p id=2 class='two'>").select("p.one"); assertEquals(2, els.size()); assertEquals("0", els.get(0).id()); assertEquals("1", els.get(1).id()); Elements none = Jsoup.parse("<div class='one'></div>").select(".foo"); assertEquals(0, none.size()); Elements els2 = Jsoup.parse("<div class='One-Two'></div>").select(".one-two"); assertEquals(1, els2.size()); }
@Test public void testByAttribute() { String h = "<div Title=Foo /><div Title=Bar /><div Style=Qux /><div title=Bam /><div title=SLAM />" + "<div data-name='with spaces'/>"; Document doc = Jsoup.parse(h); Elements withTitle = doc.select("[title]"); assertEquals(4, withTitle.size()); Elements foo = doc.select("[title=foo]"); assertEquals(1, foo.size()); Elements foo2 = doc.select("[title=\"foo\"]"); assertEquals(1, foo2.size()); Elements foo3 = doc.select("[title=\"Foo\"]"); assertEquals(1, foo3.size()); Elements dataName = doc.select("[data-name=\"with spaces\"]"); assertEquals(1, dataName.size()); assertEquals("with spaces", dataName.first().attr("data-name")); Elements not = doc.select("div[title!=bar]"); assertEquals(5, not.size()); assertEquals("Foo", not.first().attr("title")); Elements starts = doc.select("[title^=ba]"); assertEquals(2, starts.size()); assertEquals("Bar", starts.first().attr("title")); assertEquals("Bam", starts.last().attr("title")); Elements ends = doc.select("[title$=am]"); assertEquals(2, ends.size()); assertEquals("Bam", ends.first().attr("title")); assertEquals("SLAM", ends.last().attr("title")); Elements contains = doc.select("[title*=a]"); assertEquals(3, contains.size()); assertEquals("Bar", contains.first().attr("title")); assertEquals("SLAM", contains.last().attr("title")); }
@Test public void testNamespacedTag() { Document doc = Jsoup.parse("<div><abc:def id=1>Hello</abc:def></div> <abc:def class=bold id=2>There</abc:def>"); Elements byTag = doc.select("abc|def"); assertEquals(2, byTag.size()); assertEquals("1", byTag.first().id()); assertEquals("2", byTag.last().id()); Elements byAttr = doc.select(".bold"); assertEquals(1, byAttr.size()); assertEquals("2", byAttr.last().id()); Elements byTagAttr = doc.select("abc|def.bold"); assertEquals(1, byTagAttr.size()); assertEquals("2", byTagAttr.last().id()); Elements byContains = doc.select("abc|def:contains(e)"); assertEquals(2, byContains.size()); assertEquals("1", byContains.first().id()); assertEquals("2", byContains.last().id()); }
@Test public void testByAttributeStarting() { Document doc = Jsoup.parse("<div id=1 data-name=jsoup>Hello</div><p data-val=5 id=2>There</p><p id=3>No</p>"); Elements withData = doc.select("[^data-]"); assertEquals(2, withData.size()); assertEquals("1", withData.first().id()); assertEquals("2", withData.last().id()); withData = doc.select("p[^data-]"); assertEquals(1, withData.size()); assertEquals("2", withData.first().id()); }
@Test public void testByAttributeRegex() { Document doc = Jsoup.parse("<p><img src=foo.png id=1><img src=bar.jpg id=2><img src=qux.JPEG id=3><img src=old.gif><img></p>"); Elements imgs = doc.select("img[src~=(?i)\\.(png|jpe?g)]"); assertEquals(3, imgs.size()); assertEquals("1", imgs.get(0).id()); assertEquals("2", imgs.get(1).id()); assertEquals("3", imgs.get(2).id()); }
@Test public void testByAttributeRegexCharacterClass() { Document doc = Jsoup.parse("<p><img src=foo.png id=1><img src=bar.jpg id=2><img src=qux.JPEG id=3><img src=old.gif id=4></p>"); Elements imgs = doc.select("img[src~=[o]]"); assertEquals(2, imgs.size()); assertEquals("1", imgs.get(0).id()); assertEquals("4", imgs.get(1).id()); }
@Test public void testByAttributeRegexCombined() { Document doc = Jsoup.parse("<div><table class=x><td>Hello</td></table></div>"); Elements els = doc.select("div table[class~=x|y]"); assertEquals(1, els.size()); assertEquals("Hello", els.text()); }
@Test public void testCombinedWithContains() { Document doc = Jsoup.parse("<p id=1>One</p><p>Two +</p><p>Three +</p>"); Elements els = doc.select("p#1 + :contains(+)"); assertEquals(1, els.size()); assertEquals("Two +", els.text()); assertEquals("p", els.first().tagName()); }
@Test public void testAllElements() { String h = "<div><p>Hello</p><p><b>there</b></p></div>"; Document doc = Jsoup.parse(h); Elements allDoc = doc.select("*"); Elements allUnderDiv = doc.select("div *"); assertEquals(8, allDoc.size()); assertEquals(3, allUnderDiv.size()); assertEquals("p", allUnderDiv.first().tagName()); }
@Test public void testAllWithClass() { String h = "<p class=first>One<p class=first>Two<p>Three"; Document doc = Jsoup.parse(h); Elements ps = doc.select("*.first"); assertEquals(2, ps.size()); }
@Test public void testGroupOr() { String h = "<div title=foo /><div title=bar /><div /><p></p><img /><span title=qux>"; Document doc = Jsoup.parse(h); Elements els = doc.select("p,div,[title]"); assertEquals(5, els.size()); assertEquals("div", els.get(0).tagName()); assertEquals("foo", els.get(0).attr("title")); assertEquals("div", els.get(1).tagName()); assertEquals("bar", els.get(1).attr("title")); assertEquals("div", els.get(2).tagName()); assertTrue(els.get(2).attr("title").length() == 0); assertFalse(els.get(2).hasAttr("title")); assertEquals("p", els.get(3).tagName()); assertEquals("span", els.get(4).tagName()); }
@Test public void testGroupOrAttribute() { String h = "<div id=1 /><div id=2 /><div title=foo /><div title=bar />"; Elements els = Jsoup.parse(h).select("[id],[title=foo]"); assertEquals(3, els.size()); assertEquals("1", els.get(0).id()); assertEquals("2", els.get(1).id()); assertEquals("foo", els.get(2).attr("title")); }
@Test public void descendant() { String h = "<div class=head><p class=first>Hello</p><p>There</p></div><p>None</p>"; Document doc = Jsoup.parse(h); Element root = doc.getElementsByClass("head").first(); Elements els = root.select(".head p"); assertEquals(2, els.size()); assertEquals("Hello", els.get(0).text()); assertEquals("There", els.get(1).text()); Elements p = root.select("p.first"); assertEquals(1, p.size()); assertEquals("Hello", p.get(0).text()); Elements empty = root.select("p .first"); assertEquals(0, empty.size()); Elements aboveRoot = root.select("body div.head"); assertEquals(0, aboveRoot.size()); }
@Test public void and() { String h = "<div id=1 class='foo bar' title=bar name=qux><p class=foo title=bar>Hello</p></div"; Document doc = Jsoup.parse(h); Elements div = doc.select("div.foo"); assertEquals(1, div.size()); assertEquals("div", div.first().tagName()); Elements p = doc.select("div .foo"); assertEquals(1, p.size()); assertEquals("p", p.first().tagName()); Elements div2 = doc.select("div#1.foo.bar[title=bar][name=qux]"); assertEquals(1, div2.size()); assertEquals("div", div2.first().tagName()); Elements p2 = doc.select("div *.foo"); assertEquals(1, p2.size()); assertEquals("p", p2.first().tagName()); }
@Test public void deeperDescendant() { String h = "<div class=head><p><span class=first>Hello</div><div class=head><p class=first><span>Another</span><p>Again</div>"; Document doc = Jsoup.parse(h); Element root = doc.getElementsByClass("head").first(); Elements els = root.select("div p .first"); assertEquals(1, els.size()); assertEquals("Hello", els.first().text()); assertEquals("span", els.first().tagName()); Elements aboveRoot = root.select("body p .first"); assertEquals(0, aboveRoot.size()); }
@Test public void parentChildElement() { String h = "<div id=1><div id=2><div id = 3></div></div></div><div id=4></div>"; Document doc = Jsoup.parse(h); Elements divs = doc.select("div > div"); assertEquals(2, divs.size()); assertEquals("2", divs.get(0).id()); assertEquals("3", divs.get(1).id()); Elements div2 = doc.select("div#1 > div"); assertEquals(1, div2.size()); assertEquals("2", div2.get(0).id()); }
@Test public void parentWithClassChild() { String h = "<h1 class=foo><a href=1 /></h1><h1 class=foo><a href=2 class=bar /></h1><h1><a href=3 /></h1>"; Document doc = Jsoup.parse(h); Elements allAs = doc.select("h1 > a"); assertEquals(3, allAs.size()); assertEquals("a", allAs.first().tagName()); Elements fooAs = doc.select("h1.foo > a"); assertEquals(2, fooAs.size()); assertEquals("a", fooAs.first().tagName()); Elements barAs = doc.select("h1.foo > a.bar"); assertEquals(1, barAs.size()); }
@Test public void parentChildStar() { String h = "<div id=1><p>Hello<p><b>there</b></p></div><div id=2><span>Hi</span></div>"; Document doc = Jsoup.parse(h); Elements divChilds = doc.select("div > *"); assertEquals(3, divChilds.size()); assertEquals("p", divChilds.get(0).tagName()); assertEquals("p", divChilds.get(1).tagName()); assertEquals("span", divChilds.get(2).tagName()); }
@Test public void multiChildDescent() { String h = "<div id=foo><h1 class=bar><a href=http: Document doc = Jsoup.parse(h); Elements els = doc.select("div#foo > h1.bar > a[href*=example]"); assertEquals(1, els.size()); assertEquals("a", els.first().tagName()); }
@Test public void caseInsensitive() { String h = "<dIv tItle=bAr><div>"; Document doc = Jsoup.parse(h); assertEquals(2, doc.select("DIV").size()); assertEquals(1, doc.select("DIV[TITLE]").size()); assertEquals(1, doc.select("DIV[TITLE=BAR]").size()); assertEquals(0, doc.select("DIV[TITLE=BARBARELLA").size()); }
@Test public void adjacentSiblings() { String h = "<ol><li>One<li>Two<li>Three</ol>"; Document doc = Jsoup.parse(h); Elements sibs = doc.select("li + li"); assertEquals(2, sibs.size()); assertEquals("Two", sibs.get(0).text()); assertEquals("Three", sibs.get(1).text()); }
@Test public void adjacentSiblingsWithId() { String h = "<ol><li id=1>One<li id=2>Two<li id=3>Three</ol>"; Document doc = Jsoup.parse(h); Elements sibs = doc.select("li#1 + li#2"); assertEquals(1, sibs.size()); assertEquals("Two", sibs.get(0).text()); }
@Test public void notAdjacent() { String h = "<ol><li id=1>One<li id=2>Two<li id=3>Three</ol>"; Document doc = Jsoup.parse(h); Elements sibs = doc.select("li#1 + li#3"); assertEquals(0, sibs.size()); }
@Test public void mixCombinator() { String h = "<div class=foo><ol><li>One<li>Two<li>Three</ol></div>"; Document doc = Jsoup.parse(h); Elements sibs = doc.select("body > div.foo li + li"); assertEquals(2, sibs.size()); assertEquals("Two", sibs.get(0).text()); assertEquals("Three", sibs.get(1).text()); }
@Test public void mixCombinatorGroup() { String h = "<div class=foo><ol><li>One<li>Two<li>Three</ol></div>"; Document doc = Jsoup.parse(h); Elements els = doc.select(".foo > ol, ol > li + li"); assertEquals(3, els.size()); assertEquals("ol", els.get(0).tagName()); assertEquals("Two", els.get(1).text()); assertEquals("Three", els.get(2).text()); }
@Test public void generalSiblings() { String h = "<ol><li id=1>One<li id=2>Two<li id=3>Three</ol>"; Document doc = Jsoup.parse(h); Elements els = doc.select("#1 ~ #3"); assertEquals(1, els.size()); assertEquals("Three", els.first().text()); }
@Test public void testCharactersInIdAndClass() { String h = "<div><p id='a1-foo_bar'>One</p><p class='b2-qux_bif'>Two</p></div>"; Document doc = Jsoup.parse(h); Element el1 = doc.getElementById("a1-foo_bar"); assertEquals("One", el1.text()); Element el2 = doc.getElementsByClass("b2-qux_bif").first(); assertEquals("Two", el2.text()); Element el3 = doc.select("#a1-foo_bar").first(); assertEquals("One", el3.text()); Element el4 = doc.select(".b2-qux_bif").first(); assertEquals("Two", el4.text()); }
@Test public void testSupportsLeadingCombinator() { String h = "<div><p><span>One</span><span>Two</span></p></div>"; Document doc = Jsoup.parse(h); Element p = doc.select("div > p").first(); Elements spans = p.select("> span"); assertEquals(2, spans.size()); assertEquals("One", spans.first().text()); h = "<div id=1><div id=2><div id=3></div></div></div>"; doc = Jsoup.parse(h); Element div = doc.select("div").select(" > div").first(); assertEquals("2", div.id()); }
@Test public void testPseudoLessThan() { Document doc = Jsoup.parse("<div><p>One</p><p>Two</p><p>Three</>p></div><div><p>Four</p>"); Elements ps = doc.select("div p:lt(2)"); assertEquals(3, ps.size()); assertEquals("One", ps.get(0).text()); assertEquals("Two", ps.get(1).text()); assertEquals("Four", ps.get(2).text()); }
@Test public void testPseudoGreaterThan() { Document doc = Jsoup.parse("<div><p>One</p><p>Two</p><p>Three</p></div><div><p>Four</p>"); Elements ps = doc.select("div p:gt(0)"); assertEquals(2, ps.size()); assertEquals("Two", ps.get(0).text()); assertEquals("Three", ps.get(1).text()); }
@Test public void testPseudoEquals() { Document doc = Jsoup.parse("<div><p>One</p><p>Two</p><p>Three</>p></div><div><p>Four</p>"); Elements ps = doc.select("div p:eq(0)"); assertEquals(2, ps.size()); assertEquals("One", ps.get(0).text()); assertEquals("Four", ps.get(1).text()); Elements ps2 = doc.select("div:eq(0) p:eq(0)"); assertEquals(1, ps2.size()); assertEquals("One", ps2.get(0).text()); assertEquals("p", ps2.get(0).tagName()); }
@Test public void testPseudoBetween() { Document doc = Jsoup.parse("<div><p>One</p><p>Two</p><p>Three</>p></div><div><p>Four</p>"); Elements ps = doc.select("div p:gt(0):lt(2)"); assertEquals(1, ps.size()); assertEquals("Two", ps.get(0).text()); }
@Test public void testPseudoCombined() { Document doc = Jsoup.parse("<div class='foo'><p>One</p><p>Two</p></div><div><p>Three</p><p>Four</p></div>"); Elements ps = doc.select("div.foo p:gt(0)"); assertEquals(1, ps.size()); assertEquals("Two", ps.get(0).text()); }
@Test public void testPseudoHas() { Document doc = Jsoup.parse("<div id=0><p><span>Hello</span></p></div> <div id=1><span class=foo>There</span></div> <div id=2><p>Not</p></div>"); Elements divs1 = doc.select("div:has(span)"); assertEquals(2, divs1.size()); assertEquals("0", divs1.get(0).id()); assertEquals("1", divs1.get(1).id()); Elements divs2 = doc.select("div:has([class]"); assertEquals(1, divs2.size()); assertEquals("1", divs2.get(0).id()); Elements divs3 = doc.select("div:has(span, p)"); assertEquals(3, divs3.size()); assertEquals("0", divs3.get(0).id()); assertEquals("1", divs3.get(1).id()); assertEquals("2", divs3.get(2).id()); Elements els1 = doc.body().select(":has(p)"); assertEquals(3, els1.size()); assertEquals("body", els1.first().tagName()); assertEquals("0", els1.get(1).id()); assertEquals("2", els1.get(2).id()); }
@Test public void testNestedHas() { Document doc = Jsoup.parse("<div><p><span>One</span></p></div> <div><p>Two</p></div>"); Elements divs = doc.select("div:has(p:has(span))"); assertEquals(1, divs.size()); assertEquals("One", divs.first().text()); divs = doc.select("div:has(p:matches((?i)two))"); assertEquals(1, divs.size()); assertEquals("div", divs.first().tagName()); assertEquals("Two", divs.first().text()); divs = doc.select("div:has(p:contains(two))"); assertEquals(1, divs.size()); assertEquals("div", divs.first().tagName()); assertEquals("Two", divs.first().text()); }
@Test public void testPseudoContains() { Document doc = Jsoup.parse("<div><p>The Rain.</p> <p class=light>The <i>rain</i>.</p> <p>Rain, the.</p></div>"); Elements ps1 = doc.select("p:contains(Rain)"); assertEquals(3, ps1.size()); Elements ps2 = doc.select("p:contains(the rain)"); assertEquals(2, ps2.size()); assertEquals("The Rain.", ps2.first().html()); assertEquals("The <i>rain</i>.", ps2.last().html()); Elements ps3 = doc.select("p:contains(the Rain):has(i)"); assertEquals(1, ps3.size()); assertEquals("light", ps3.first().className()); Elements ps4 = doc.select(".light:contains(rain)"); assertEquals(1, ps4.size()); assertEquals("light", ps3.first().className()); Elements ps5 = doc.select(":contains(rain)"); assertEquals(8, ps5.size()); }
@Test public void testPsuedoContainsWithParentheses() { Document doc = Jsoup.parse("<div><p id=1>This (is good)</p><p id=2>This is bad)</p>"); Elements ps1 = doc.select("p:contains(this (is good))"); assertEquals(1, ps1.size()); assertEquals("1", ps1.first().id()); Elements ps2 = doc.select("p:contains(this is bad\\))"); assertEquals(1, ps2.size()); assertEquals("2", ps2.first().id()); }
@Test public void containsOwn() { Document doc = Jsoup.parse("<p id=1>Hello <b>there</b> now</p>"); Elements ps = doc.select("p:containsOwn(Hello now)"); assertEquals(1, ps.size()); assertEquals("1", ps.first().id()); assertEquals(0, doc.select("p:containsOwn(there)").size()); }
@Test public void testMatches() { Document doc = Jsoup.parse("<p id=1>The <i>Rain</i></p> <p id=2>There are 99 bottles.</p> <p id=3>Harder (this)</p> <p id=4>Rain</p>"); Elements p1 = doc.select("p:matches(The rain)"); assertEquals(0, p1.size()); Elements p2 = doc.select("p:matches((?i)the rain)"); assertEquals(1, p2.size()); assertEquals("1", p2.first().id()); Elements p4 = doc.select("p:matches((?i)^rain$)"); assertEquals(1, p4.size()); assertEquals("4", p4.first().id()); Elements p5 = doc.select("p:matches(\\d+)"); assertEquals(1, p5.size()); assertEquals("2", p5.first().id()); Elements p6 = doc.select("p:matches(\\w+\\s+\\(\\w+\\))"); assertEquals(1, p6.size()); assertEquals("3", p6.first().id()); Elements p7 = doc.select("p:matches((?i)the):has(i)"); assertEquals(1, p7.size()); assertEquals("1", p7.first().id()); }
@Test public void matchesOwn() { Document doc = Jsoup.parse("<p id=1>Hello <b>there</b> now</p>"); Elements p1 = doc.select("p:matchesOwn((?i)hello now)"); assertEquals(1, p1.size()); assertEquals("1", p1.first().id()); assertEquals(0, doc.select("p:matchesOwn(there)").size()); }
@Test public void testRelaxedTags() { Document doc = Jsoup.parse("<abc_def id=1>Hello</abc_def> <abc-def id=2>There</abc-def>"); Elements el1 = doc.select("abc_def"); assertEquals(1, el1.size()); assertEquals("1", el1.first().id()); Elements el2 = doc.select("abc-def"); assertEquals(1, el2.size()); assertEquals("2", el2.first().id()); }
@Test public void notParas() { Document doc = Jsoup.parse("<p id=1>One</p> <p>Two</p> <p><span>Three</span></p>"); Elements el1 = doc.select("p:not([id=1])"); assertEquals(2, el1.size()); assertEquals("Two", el1.first().text()); assertEquals("Three", el1.last().text()); Elements el2 = doc.select("p:not(:has(span))"); assertEquals(2, el2.size()); assertEquals("One", el2.first().text()); assertEquals("Two", el2.last().text()); }
@Test public void notAll() { Document doc = Jsoup.parse("<p>Two</p> <p><span>Three</span></p>"); Elements el1 = doc.body().select(":not(p)"); assertEquals(2, el1.size()); assertEquals("body", el1.first().tagName()); assertEquals("span", el1.last().tagName()); }
@Test public void notClass() { Document doc = Jsoup.parse("<div class=left>One</div><div class=right id=1><p>Two</p></div>"); Elements el1 = doc.select("div:not(.left)"); assertEquals(1, el1.size()); assertEquals("1", el1.first().id()); }
@Test public void handlesCommasInSelector() { Document doc = Jsoup.parse("<p name='1,2'>One</p><div>Two</div><ol><li>123</li><li>Text</li></ol>"); Elements ps = doc.select("[name=1,2]"); assertEquals(1, ps.size()); Elements containers = doc.select("div, li:matches([0-9,]+)"); assertEquals(2, containers.size()); assertEquals("div", containers.get(0).tagName()); assertEquals("li", containers.get(1).tagName()); assertEquals("123", containers.get(1).text()); }
@Test public void selectSupplementaryCharacter() { String s = new String(Character.toChars(135361)); Document doc = Jsoup.parse("<div k" + s + "='" + s + "'>^" + s +"$/div>"); assertEquals("div", doc.select("div[k" + s + "]").first().tagName()); assertEquals("div", doc.select("div:containsOwn(" + s + ")").first().tagName()); }
@Test public void selectClassWithSpace() { final String html = "<div class=\"value\">class without space</div>\n" + "<div class=\"value \">class with space</div>"; Document doc = Jsoup.parse(html); Elements found = doc.select("div[class=value ]"); assertEquals(2, found.size()); assertEquals("class without space", found.get(0).text()); assertEquals("class with space", found.get(1).text()); found = doc.select("div[class=\"value \"]"); assertEquals(2, found.size()); assertEquals("class without space", found.get(0).text()); assertEquals("class with space", found.get(1).text()); found = doc.select("div[class=\"value\\ \"]"); assertEquals(0, found.size()); }
@Test public void selectSameElements() { final String html = "<div>one</div><div>one</div>"; Document doc = Jsoup.parse(html); Elements els = doc.select("div"); assertEquals(2, els.size()); Elements subSelect = els.select(":contains(one)"); assertEquals(2, subSelect.size()); }
@Test public void attributeWithBrackets() { String html = "<div data='End]'>One</div> <div data='[Another)]]'>Two</div>"; Document doc = Jsoup.parse(html); assertEquals("One", doc.select("div[data='End]'").first().text()); assertEquals("Two", doc.select("div[data='[Another)]]'").first().text()); assertEquals("One", doc.select("div[data=\"End]\"").first().text()); assertEquals("Two", doc.select("div[data=\"[Another)]]\"").first().text()); }
|
AutoCloseInputStream extends ProxyInputStream { @Override public void close() throws IOException { in.close(); in = new ClosedInputStream(); } AutoCloseInputStream(final InputStream in); @Override void close(); }
|
@Test public void testClose() throws IOException { stream.close(); assertTrue("closed", closed); assertEquals("read()", -1, stream.read()); }
|
HexDump { public static void dump(final byte[] data, final long offset, final OutputStream stream, final int index) throws IOException, ArrayIndexOutOfBoundsException, IllegalArgumentException { if (index < 0 || index >= data.length) { throw new ArrayIndexOutOfBoundsException( "illegal index: " + index + " into array of length " + data.length); } if (stream == null) { throw new IllegalArgumentException("cannot write to nullstream"); } long display_offset = offset + index; final StringBuilder buffer = new StringBuilder(74); for (int j = index; j < data.length; j += 16) { int chars_read = data.length - j; if (chars_read > 16) { chars_read = 16; } dump(buffer, display_offset).append(' '); for (int k = 0; k < 16; k++) { if (k < chars_read) { dump(buffer, data[k + j]); } else { buffer.append(" "); } buffer.append(' '); } for (int k = 0; k < chars_read; k++) { if (data[k + j] >= ' ' && data[k + j] < 127) { buffer.append((char) data[k + j]); } else { buffer.append('.'); } } buffer.append(EOL); stream.write(buffer.toString().getBytes(Charset.defaultCharset())); stream.flush(); buffer.setLength(0); display_offset += chars_read; } } HexDump(); static void dump(final byte[] data, final long offset,
final OutputStream stream, final int index); static final String EOL; }
|
@Test public void testDump() throws IOException { final byte[] testArray = new byte[256]; for (int j = 0; j < 256; j++) { testArray[j] = (byte) j; } ByteArrayOutputStream stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0, stream, 0); byte[] outputArray = new byte[16 * (73 + HexDump.EOL.length())]; for (int j = 0; j < 16; j++) { int offset = (73 + HexDump.EOL.length()) * j; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) ' '; for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) toHex(k); outputArray[offset++] = (byte) ' '; } for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toAscii((j * 16) + k); } System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length); } byte[] actualOutput = stream.toByteArray(); assertEquals("array size mismatch", outputArray.length, actualOutput.length); for (int j = 0; j < outputArray.length; j++) { assertEquals("array[ " + j + "] mismatch", outputArray[j], actualOutput[j]); } stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0x10000000, stream, 0); outputArray = new byte[16 * (73 + HexDump.EOL.length())]; for (int j = 0; j < 16; j++) { int offset = (73 + HexDump.EOL.length()) * j; outputArray[offset++] = (byte) '1'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) ' '; for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) toHex(k); outputArray[offset++] = (byte) ' '; } for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toAscii((j * 16) + k); } System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length); } actualOutput = stream.toByteArray(); assertEquals("array size mismatch", outputArray.length, actualOutput.length); for (int j = 0; j < outputArray.length; j++) { assertEquals("array[ " + j + "] mismatch", outputArray[j], actualOutput[j]); } stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0xFF000000, stream, 0); outputArray = new byte[16 * (73 + HexDump.EOL.length())]; for (int j = 0; j < 16; j++) { int offset = (73 + HexDump.EOL.length()) * j; outputArray[offset++] = (byte) 'F'; outputArray[offset++] = (byte) 'F'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) ' '; for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toHex(j); outputArray[offset++] = (byte) toHex(k); outputArray[offset++] = (byte) ' '; } for (int k = 0; k < 16; k++) { outputArray[offset++] = (byte) toAscii((j * 16) + k); } System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length); } actualOutput = stream.toByteArray(); assertEquals("array size mismatch", outputArray.length, actualOutput.length); for (int j = 0; j < outputArray.length; j++) { assertEquals("array[ " + j + "] mismatch", outputArray[j], actualOutput[j]); } stream = new ByteArrayOutputStream(); HexDump.dump(testArray, 0x10000000, stream, 0x81); outputArray = new byte[(8 * (73 + HexDump.EOL.length())) - 1]; for (int j = 0; j < 8; j++) { int offset = (73 + HexDump.EOL.length()) * j; outputArray[offset++] = (byte) '1'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) '0'; outputArray[offset++] = (byte) toHex(j + 8); outputArray[offset++] = (byte) '1'; outputArray[offset++] = (byte) ' '; for (int k = 0; k < 16; k++) { final int index = 0x81 + (j * 16) + k; if (index < 0x100) { outputArray[offset++] = (byte) toHex(index / 16); outputArray[offset++] = (byte) toHex(index); } else { outputArray[offset++] = (byte) ' '; outputArray[offset++] = (byte) ' '; } outputArray[offset++] = (byte) ' '; } for (int k = 0; k < 16; k++) { final int index = 0x81 + (j * 16) + k; if (index < 0x100) { outputArray[offset++] = (byte) toAscii(index); } } System.arraycopy(HexDump.EOL.getBytes(), 0, outputArray, offset, HexDump.EOL.getBytes().length); } actualOutput = stream.toByteArray(); assertEquals("array size mismatch", outputArray.length, actualOutput.length); for (int j = 0; j < outputArray.length; j++) { assertEquals("array[ " + j + "] mismatch", outputArray[j], actualOutput[j]); } try { HexDump.dump(testArray, 0x10000000, new ByteArrayOutputStream(), -1); fail("should have caught ArrayIndexOutOfBoundsException on negative index"); } catch (final ArrayIndexOutOfBoundsException ignored_exception) { } try { HexDump.dump(testArray, 0x10000000, new ByteArrayOutputStream(), testArray.length); fail("should have caught ArrayIndexOutOfBoundsException on large index"); } catch (final ArrayIndexOutOfBoundsException ignored_exception) { } try { HexDump.dump(testArray, 0x10000000, null, 0); fail("should have caught IllegalArgumentException on negative index"); } catch (final IllegalArgumentException ignored_exception) { } }
|
DeferredFileOutputStream extends ThresholdingOutputStream { @Override protected void thresholdReached() throws IOException { if (prefix != null) { outputFile = File.createTempFile(prefix, suffix, directory); } final FileOutputStream fos = new FileOutputStream(outputFile); try { memoryOutputStream.writeTo(fos); } catch (IOException e){ fos.close(); throw e; } currentOutputStream = fos; memoryOutputStream = null; } DeferredFileOutputStream(final int threshold, final File outputFile); DeferredFileOutputStream(final int threshold, final String prefix, final String suffix, final File directory); private DeferredFileOutputStream(final int threshold, final File outputFile, final String prefix,
final String suffix, final File directory); boolean isInMemory(); byte[] getData(); File getFile(); @Override void close(); void writeTo(final OutputStream out); }
|
@Test public void testThresholdReached() { final File testFile = new File("testThresholdReached.dat"); testFile.delete(); final DeferredFileOutputStream dfos = new DeferredFileOutputStream(testBytes.length / 2, testFile); final int chunkSize = testBytes.length / 3; try { dfos.write(testBytes, 0, chunkSize); dfos.write(testBytes, chunkSize, chunkSize); dfos.write(testBytes, chunkSize * 2, testBytes.length - chunkSize * 2); dfos.close(); } catch (final IOException e) { fail("Unexpected IOException"); } assertFalse(dfos.isInMemory()); assertNull(dfos.getData()); verifyResultFile(testFile); testFile.delete(); }
|
DeferredFileOutputStream extends ThresholdingOutputStream { @Override public void close() throws IOException { super.close(); closed = true; } DeferredFileOutputStream(final int threshold, final File outputFile); DeferredFileOutputStream(final int threshold, final String prefix, final String suffix, final File directory); private DeferredFileOutputStream(final int threshold, final File outputFile, final String prefix,
final String suffix, final File directory); boolean isInMemory(); byte[] getData(); File getFile(); @Override void close(); void writeTo(final OutputStream out); }
|
@Test public void testTempFileError() throws Exception { final String prefix = null; final String suffix = ".out"; final File tempDir = new File("."); try { (new DeferredFileOutputStream(testBytes.length - 5, prefix, suffix, tempDir)).close(); fail("Expected IllegalArgumentException "); } catch (final IllegalArgumentException e) { } }
|
BrokenOutputStream extends OutputStream { @Override public void write(final int b) throws IOException { throw exception; } BrokenOutputStream(final IOException exception); BrokenOutputStream(); @Override void write(final int b); @Override void flush(); @Override void close(); }
|
@Test public void testWrite() { try { stream.write(1); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } try { stream.write(new byte[1]); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } try { stream.write(new byte[1], 0, 1); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } }
|
BrokenOutputStream extends OutputStream { @Override public void flush() throws IOException { throw exception; } BrokenOutputStream(final IOException exception); BrokenOutputStream(); @Override void write(final int b); @Override void flush(); @Override void close(); }
|
@Test public void testFlush() { try { stream.flush(); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } }
|
BrokenOutputStream extends OutputStream { @Override public void close() throws IOException { throw exception; } BrokenOutputStream(final IOException exception); BrokenOutputStream(); @Override void write(final int b); @Override void flush(); @Override void close(); }
|
@Test public void testClose() { try { stream.close(); fail("Expected exception not thrown."); } catch (final IOException e) { assertEquals(exception, e); } }
|
ProxyWriter extends FilterWriter { @Override public void close() throws IOException { try { out.close(); } catch (final IOException e) { handleIOException(e); } } ProxyWriter(final Writer proxy); @Override Writer append(final char c); @Override Writer append(final CharSequence csq, final int start, final int end); @Override Writer append(final CharSequence csq); @Override void write(final int idx); @Override void write(final char[] chr); @Override void write(final char[] chr, final int st, final int len); @Override void write(final String str); @Override void write(final String str, final int st, final int len); @Override void flush(); @Override void close(); }
|
@Test(expected = UnsupportedEncodingException.class) public void exceptions_in_close() throws IOException { OutputStreamWriter osw = new OutputStreamWriter(new ByteArrayOutputStream()) { @Override public void close() throws IOException { throw new UnsupportedEncodingException("Bah"); } }; final ProxyWriter proxy = new ProxyWriter(osw); proxy.close(); }
|
StringBuilderWriter extends Writer implements Serializable { @Override public void close() { } StringBuilderWriter(); StringBuilderWriter(final int capacity); StringBuilderWriter(final StringBuilder builder); @Override Writer append(final char value); @Override Writer append(final CharSequence value); @Override Writer append(final CharSequence value, final int start, final int end); @Override void close(); @Override void flush(); @Override void write(final String value); @Override void write(final char[] value, final int offset, final int length); StringBuilder getBuilder(); @Override String toString(); }
|
@Test public void testClose() { final Writer writer = new StringBuilderWriter(); try { writer.append("Foo"); writer.close(); writer.append("Bar"); } catch (final Throwable t) { fail("Threw: " + t); } assertEquals("FooBar", writer.toString()); }
|
ChunkedOutputStream extends FilterOutputStream { @Override public void write(byte[] data, int srcOffset, int length) throws IOException { int bytes = length; int dstOffset = srcOffset; while(bytes > 0) { int chunk = Math.min(bytes, chunkSize); out.write(data, dstOffset, chunk); bytes -= chunk; dstOffset += chunk; } } ChunkedOutputStream(final OutputStream stream, int chunkSize); ChunkedOutputStream(final OutputStream stream); @Override void write(byte[] data, int srcOffset, int length); }
|
@Test public void write_four_chunks() throws Exception { final AtomicInteger numWrites = new AtomicInteger(); ByteArrayOutputStream baos = getByteArrayOutputStream(numWrites); ChunkedOutputStream chunked = new ChunkedOutputStream(baos, 10); chunked.write("0123456789012345678901234567891".getBytes()); assertEquals(4, numWrites.get()); chunked.close(); }
@Test public void defaultConstructor() throws IOException { final AtomicInteger numWrites = new AtomicInteger(); ByteArrayOutputStream baos = getByteArrayOutputStream(numWrites); ChunkedOutputStream chunked = new ChunkedOutputStream(baos); chunked.write(new byte[1024 * 4 + 1]); assertEquals(2, numWrites.get()); chunked.close(); }
|
CloseShieldOutputStream extends ProxyOutputStream { @Override public void close() { out = new ClosedOutputStream(); } CloseShieldOutputStream(final OutputStream out); @Override void close(); }
|
@Test public void testClose() throws IOException { shielded.close(); assertFalse("closed", closed); try { shielded.write('x'); fail("write(b)"); } catch (final IOException ignore) { } original.write('y'); assertEquals(1, original.size()); assertEquals('y', original.toByteArray()[0]); }
|
ChunkedWriter extends FilterWriter { @Override public void write(char[] data, int srcOffset, int length) throws IOException { int bytes = length; int dstOffset = srcOffset; while(bytes > 0) { int chunk = Math.min(bytes, chunkSize); out.write(data, dstOffset, chunk); bytes -= chunk; dstOffset += chunk; } } ChunkedWriter(final Writer writer, int chunkSize); ChunkedWriter(final Writer writer); @Override void write(char[] data, int srcOffset, int length); }
|
@Test public void write_four_chunks() throws Exception { final AtomicInteger numWrites = new AtomicInteger(); OutputStreamWriter osw = getOutputStreamWriter(numWrites); ChunkedWriter chunked = new ChunkedWriter(osw, 10); chunked.write("0123456789012345678901234567891".toCharArray()); chunked.flush(); assertEquals(4, numWrites.get()); chunked.close(); }
@Test public void write_two_chunks_default_constructor() throws Exception { final AtomicInteger numWrites = new AtomicInteger(); OutputStreamWriter osw = getOutputStreamWriter(numWrites); ChunkedWriter chunked = new ChunkedWriter(osw); chunked.write(new char[1024 * 4 + 1]); chunked.flush(); assertEquals(2, numWrites.get()); chunked.close(); }
|
WriterOutputStream extends OutputStream { @Override public void flush() throws IOException { flushOutput(); writer.flush(); } WriterOutputStream(final Writer writer, final CharsetDecoder decoder); WriterOutputStream(final Writer writer, final CharsetDecoder decoder, final int bufferSize,
final boolean writeImmediately); WriterOutputStream(final Writer writer, final Charset charset, final int bufferSize,
final boolean writeImmediately); WriterOutputStream(final Writer writer, final Charset charset); WriterOutputStream(final Writer writer, final String charsetName, final int bufferSize,
final boolean writeImmediately); WriterOutputStream(final Writer writer, final String charsetName); @Deprecated WriterOutputStream(final Writer writer); @Override void write(final byte[] b, int off, int len); @Override void write(final byte[] b); @Override void write(final int b); @Override void flush(); @Override void close(); }
|
@Test public void testFlush() throws IOException { final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024, false); out.write("abc".getBytes("us-ascii")); assertEquals(0, writer.getBuffer().length()); out.flush(); assertEquals("abc", writer.toString()); out.close(); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.