Skip to content

Commit

Permalink
Use newInputStream instead of FileInputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo committed Jan 16, 2025
1 parent 834eff3 commit fa64861
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import static com.google.common.net.HttpHeaders.USER_AGENT;
import static java.net.Proxy.Type.HTTP;
import static java.net.Proxy.Type.SOCKS;
import static java.nio.file.Files.newInputStream;
import static java.util.Collections.list;
import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -325,7 +326,7 @@ private static KeyStore loadTrustStore(File trustStorePath, Optional<String> tru
catch (IOException | GeneralSecurityException ignored) {
}

try (InputStream in = new FileInputStream(trustStorePath)) {
try (InputStream in = newInputStream(trustStorePath.toPath())) {
trustStore.load(in, trustStorePassword.map(String::toCharArray).orElse(null));
}
return trustStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import com.google.common.collect.Sets;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -29,6 +29,7 @@
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.nio.file.Files.newInputStream;
import static java.util.Objects.requireNonNull;

public class ServiceConfig
Expand Down Expand Up @@ -83,8 +84,8 @@ public static Map<String, ServiceConfig> loadServiceConfigs(File configFile)
return ImmutableMap.of();
}
Properties properties = new Properties();
try {
properties.load(new FileInputStream(configFile));
try (InputStream inputStream = newInputStream(configFile.toPath())) {
properties.load(inputStream);
}
catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.trino.plugin.exchange.filesystem.MetricsBuilder;
import io.trino.plugin.exchange.filesystem.MetricsBuilder.CounterMetricBuilder;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -55,6 +54,7 @@
import static io.trino.plugin.exchange.filesystem.MetricsBuilder.SOURCE_FILES_PROCESSED;
import static java.lang.Math.toIntExact;
import static java.nio.file.Files.createFile;
import static java.nio.file.Files.newInputStream;
import static java.util.Objects.requireNonNull;

public class LocalFileSystemExchangeStorage
Expand Down Expand Up @@ -215,9 +215,9 @@ public synchronized void close()
}

private InputStreamSliceInput getSliceInput(ExchangeSourceFile sourceFile)
throws FileNotFoundException
throws IOException
{
return new InputStreamSliceInput(new FileInputStream(Paths.get(sourceFile.getFileUri()).toFile()), BUFFER_SIZE_IN_BYTES);
return new InputStreamSliceInput(newInputStream(Paths.get(sourceFile.getFileUri())), BUFFER_SIZE_IN_BYTES);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.trino.spi.connector.SchemaTableName;
import jakarta.annotation.PreDestroy;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.DirectoryIteratorException;
Expand All @@ -37,6 +36,7 @@

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Throwables.throwIfUnchecked;
import static java.nio.file.Files.newInputStream;
import static java.util.Objects.requireNonNull;

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ public Map<SchemaTableName, KinesisStreamDescription> getTablesFromPath()
try {
for (Path file : listFiles(Paths.get(tableDescriptionLocation))) {
if (Files.isRegularFile(file) && file.getFileName().toString().endsWith("json")) {
try (InputStream stream = new FileInputStream(file.toFile())) {
try (InputStream stream = newInputStream(file)) {
KinesisStreamDescription table = streamDescriptionCodec.fromJson(stream);
String schemaName = firstNonNull(table.schemaName(), defaultSchema);
log.debug("Kinesis table %s %s %s", schemaName, table.tableName(), table);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.trino.spi.resourcegroups.SelectionContext;
import io.trino.spi.resourcegroups.SelectionCriteria;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
Expand All @@ -38,6 +37,7 @@

import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
import static java.lang.String.format;
import static java.nio.file.Files.newInputStream;
import static java.util.Objects.requireNonNull;

public class FileResourceGroupConfigurationManager
Expand Down Expand Up @@ -86,7 +86,7 @@ private FileResourceGroupConfigurationManager(Optional<LifeCycleManager> lifeCyc
static ManagerSpec parseManagerSpec(FileResourceGroupConfig config)
{
ManagerSpec managerSpec;
try (InputStream stream = new FileInputStream(Paths.get(config.getConfigFile()).toFile())) {
try (InputStream stream = newInputStream(Paths.get(config.getConfigFile()))) {
managerSpec = CODEC.fromJson(stream);
}
catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.List;

import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
Expand All @@ -45,8 +44,7 @@ public class FileSessionPropertyManager
@Inject
public FileSessionPropertyManager(FileSessionPropertyManagerConfig config)
{
Path configurationFile = config.getConfigFile().toPath();
try (InputStream stream = new FileInputStream(configurationFile.toFile())) {
try (InputStream stream = new FileInputStream(config.getConfigFile())) {
sessionMatchSpecs = ImmutableList.copyOf(CODEC.fromJson(stream));
}
catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.testcontainers.utility.DockerImageName;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
Expand All @@ -45,6 +44,7 @@
import static io.trino.tests.product.launcher.util.UriDownloader.download;
import static java.nio.file.Files.exists;
import static java.nio.file.Files.isDirectory;
import static java.nio.file.Files.newInputStream;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -133,7 +133,7 @@ else if (!exists(extractPath)) { // Distribution not extracted and not downloade
private static void extractTar(Path filePath, Path extractPath)
{
try {
try (TarArchiveInputStream archiveStream = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(filePath.toFile())))) {
try (TarArchiveInputStream archiveStream = new TarArchiveInputStream(new GzipCompressorInputStream(newInputStream(filePath)))) {
TarArchiveEntry entry;
while ((entry = archiveStream.getNextTarEntry()) != null) {
if (!archiveStream.canReadEntryData(entry)) {
Expand Down

0 comments on commit fa64861

Please sign in to comment.