Skip to content

Commit d718f50

Browse files
committed
Fix compilation + Cleanup
1 parent 4f16112 commit d718f50

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import org.schabi.newpipe.extractor.downloader.Response;
88

99
import java.io.IOException;
10+
import java.io.UncheckedIOException;
1011
import java.nio.file.Files;
12+
import java.nio.file.Path;
1113
import java.nio.file.Paths;
1214
import java.util.HashMap;
1315
import java.util.Map;
@@ -27,17 +29,20 @@ class MockDownloader extends Downloader {
2729
public MockDownloader(@Nonnull final String path) {
2830
this.path = path;
2931
this.mocks = new HashMap<>();
32+
3033
try (final var directoryStream = Files.newDirectoryStream(Paths.get(path),
3134
entry -> entry.getFileName().toString()
3235
.startsWith(RecordingDownloader.FILE_NAME_PREFIX))) {
33-
for (final var entry : directoryStream) {
36+
for (final Path entry : directoryStream) {
3437
try (final var reader = Files.newBufferedReader(entry)) {
3538
final var response = new GsonBuilder()
3639
.create()
3740
.fromJson(reader, TestRequestResponse.class);
3841
mocks.put(response.getRequest(), response.getResponse());
3942
}
4043
}
44+
} catch (final IOException ioe) {
45+
throw new UncheckedIOException(ioe);
4146
}
4247
}
4348

extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.io.IOException;
1111
import java.io.UncheckedIOException;
1212
import java.nio.file.Files;
13+
import java.nio.file.Path;
1314
import java.nio.file.Paths;
1415

1516
import javax.annotation.Nonnull;
@@ -40,28 +41,30 @@ class RecordingDownloader extends Downloader {
4041
"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
4142

4243
private int index = 0;
43-
private final String path;
44+
private final Path path;
4445

4546
/**
4647
* Creates the folder described by {@code stringPath} if it does not exist.
4748
* Deletes existing files starting with {@link RecordingDownloader#FILE_NAME_PREFIX}.
4849
* @param stringPath Path to the folder where the json files will be saved to.
4950
*/
5051
public RecordingDownloader(final String stringPath) {
51-
this.path = stringPath;
52-
final var path = Paths.get(stringPath);
52+
this.path = Paths.get(stringPath);
53+
5354
if (Files.exists(path)) {
5455
try (final var directoryStream = Files.newDirectoryStream(path,
5556
entry -> entry.getFileName().toString()
5657
.startsWith(RecordingDownloader.FILE_NAME_PREFIX))) {
57-
for (final var entry : directoryStream) {
58+
for (final Path entry : directoryStream) {
5859
Files.delete(entry);
5960
}
61+
} catch (final IOException ioe) {
62+
throw new UncheckedIOException(ioe);
6063
}
6164
} else {
6265
try {
6366
Files.createDirectories(path);
64-
} catch (IOException e) {
67+
} catch (final IOException e) {
6568
throw new UncheckedIOException(e);
6669
}
6770
}
@@ -80,7 +83,7 @@ public Response execute(@Nonnull final Request request) throws IOException,
8083
response.latestUrl()
8184
);
8285

83-
final var outputPath = Paths.get(path).resolve(FILE_NAME_PREFIX + index + ".json");
86+
final Path outputPath = path.resolve(FILE_NAME_PREFIX + index + ".json");
8487
index++;
8588
try (final var writer = Files.newBufferedWriter(outputPath)) {
8689
new GsonBuilder()

0 commit comments

Comments
 (0)