Skip to content

Commit

Permalink
Correct javadoc and add @willclose annotations
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Artysiewicz <[email protected]>
  • Loading branch information
jartysiewicz and jartysiewicz authored Jun 24, 2022
1 parent fc41ec9 commit 38b3224
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/jsoup/Jsoup.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.jsoup.safety.Safelist;

import javax.annotation.Nullable;
import javax.annotation.WillClose;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -185,15 +187,15 @@ public static Document parse(File file, @Nullable String charsetName, String bas
/**
Read an input stream, and parse it to a Document.
@param in input stream to read. Make sure to close it after parsing.
@param in input stream to read. The stream will be closed after reading.
@param charsetName (optional) character set of file contents. Set to {@code null} to determine from {@code http-equiv} meta tag, if
present, or fall back to {@code UTF-8} (which is often safe to do).
@param baseUri The URL where the HTML was retrieved from, to resolve relative links against.
@return sane HTML
@throws IOException if the file could not be found, or read, or if the charsetName is invalid.
*/
public static Document parse(InputStream in, @Nullable String charsetName, String baseUri) throws IOException {
public static Document parse(@WillClose InputStream in, @Nullable String charsetName, String baseUri) throws IOException {
return DataUtil.load(in, charsetName, baseUri);
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/jsoup/helper/DataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.jsoup.select.Elements;

import javax.annotation.Nullable;
import javax.annotation.WillClose;

import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.File;
Expand Down Expand Up @@ -103,7 +105,7 @@ public static Document load(File file, @Nullable String charsetName, String base
* @return Document
* @throws IOException on IO error
*/
public static Document load(InputStream in, @Nullable String charsetName, String baseUri) throws IOException {
public static Document load(@WillClose InputStream in, @Nullable String charsetName, String baseUri) throws IOException {
return parseInputStream(in, charsetName, baseUri, Parser.htmlParser());
}

Expand All @@ -116,7 +118,7 @@ public static Document load(InputStream in, @Nullable String charsetName, String
* @return Document
* @throws IOException on IO error
*/
public static Document load(InputStream in, @Nullable String charsetName, String baseUri, Parser parser) throws IOException {
public static Document load(@WillClose InputStream in, @Nullable String charsetName, String baseUri, Parser parser) throws IOException {
return parseInputStream(in, charsetName, baseUri, parser);
}

Expand All @@ -134,7 +136,7 @@ static void crossStreams(final InputStream in, final OutputStream out) throws IO
}
}

static Document parseInputStream(@Nullable InputStream input, @Nullable String charsetName, String baseUri, Parser parser) throws IOException {
static Document parseInputStream(@Nullable @WillClose InputStream input, @Nullable String charsetName, String baseUri, Parser parser) throws IOException {
if (input == null) // empty body
return new Document(baseUri);
input = ConstrainableInputStream.wrap(input, bufferSize, 0);
Expand Down

0 comments on commit 38b3224

Please sign in to comment.