Skip to content

Commit

Permalink
Switch to Java's UncheckedIOException.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Jun 2, 2023
1 parent 0b10d51 commit fe40c14
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jsoup is an open source project distributed under the liberal [MIT license](http
3. Enjoy!

### Android support
When used in Android projects, [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) should be enabled to support Java 8+ features.
When used in Android projects, [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) with the [NIO specification](https://developer.android.com/studio/write/java11-nio-support-table) should be enabled to support Java 8+ features.

## Development and support
If you have any questions on how to use jsoup, or have ideas for future development, please get in touch via the [mailing list](https://jsoup.org/discussion).
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<ignore>java.util.function.Consumer</ignore>
<ignore>java.util.function.Supplier</ignore>
<ignore>java.lang.ThreadLocal</ignore>
<ignore>java.io.UncheckedIOException</ignore>
</ignores>
<!-- ^ Provided by https://developer.android.com/studio/write/java8-support#library-desugaring
Possibly OK to remove androidscents; keep for now to validate other additions are supported. -->
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jsoup/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.CookieStore;
import java.net.Proxy;
import java.net.URL;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jsoup/UncheckedIOException.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.io.IOException;

/**
* @deprecated Use {@link java.io.UncheckedIOException} instead.
*/
@Deprecated
public class UncheckedIOException extends RuntimeException {
public UncheckedIOException(IOException cause) {
super(cause);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jsoup/helper/DataUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jsoup.helper;

import org.jsoup.UncheckedIOException;
import org.jsoup.internal.ConstrainableInputStream;
import org.jsoup.internal.Normalizer;
import org.jsoup.internal.StringUtil;
Expand All @@ -23,6 +22,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
Expand Down Expand Up @@ -163,7 +163,7 @@ static Document parseInputStream(@Nullable @WillClose InputStream input, @Nullab
else
doc = parser.parseInput(defaultDecoded.toString(), baseUri);
} catch (UncheckedIOException e) {
throw e.ioException();
throw e.getCause();
}

// look for <meta http-equiv="Content-Type" content="text/html;charset=gb2312"> or HTML5 <meta charset="gb2312">
Expand Down Expand Up @@ -218,7 +218,7 @@ else if (first instanceof Comment) {
doc = parser.parseInput(reader, baseUri);
} catch (UncheckedIOException e) {
// io exception when parsing (not seen before because reading the stream as we go)
throw e.ioException();
throw e.getCause();
}
Charset charset = charsetName.equals(defaultCharsetName) ? UTF_8 : Charset.forName(charsetName);
doc.outputSettings().charset(charset);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jsoup/helper/HttpConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.jsoup.Connection;
import org.jsoup.HttpStatusException;
import org.jsoup.UncheckedIOException;
import org.jsoup.UnsupportedMimeTypeException;
import org.jsoup.internal.ConstrainableInputStream;
import org.jsoup.internal.StringUtil;
Expand All @@ -20,6 +19,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UncheckedIOException;
import java.net.CookieManager;
import java.net.CookieStore;
import java.net.HttpURLConnection;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jsoup/parser/CharacterReader.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.jsoup.parser;

import org.jsoup.UncheckedIOException;
import org.jsoup.helper.Validate;

import javax.annotation.Nullable;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jsoup/integration/SessionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.UncheckedIOException;
import org.jsoup.integration.servlets.FileServlet;
import org.jsoup.integration.servlets.SlowRider;
import org.jsoup.nodes.Document;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.concurrent.atomic.AtomicInteger;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/jsoup/parser/CharacterReaderTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.jsoup.parser;

import org.jsoup.UncheckedIOException;
import org.jsoup.integration.ParseTest;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.io.UncheckedIOException;

import static org.junit.jupiter.api.Assertions.*;

Expand Down

0 comments on commit fe40c14

Please sign in to comment.