mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-12 08:48:39 +00:00
Cleanup - File IO streams
This commit is contained in:
@@ -382,25 +382,14 @@ public class CardStorageReader {
|
||||
* @return a new Card instance
|
||||
*/
|
||||
protected final CardRules loadCard(final CardRules.Reader reader, final File file) {
|
||||
FileInputStream fileInputStream = null;
|
||||
try {
|
||||
fileInputStream = new FileInputStream(file);
|
||||
try (InputStream fileInputStream = java.nio.file.Files.newInputStream(file.toPath())) {
|
||||
reader.reset();
|
||||
final List<String> lines = readScript(fileInputStream);
|
||||
return reader.readCard(lines, Files.getNameWithoutExtension(file.getName()));
|
||||
} catch (final FileNotFoundException ex) {
|
||||
throw new RuntimeException("CardReader : run error -- file not found: " + file.getPath(), ex);
|
||||
} catch (final Exception ex) {
|
||||
System.out.println("Error loading cardscript " + file.getName() + ". Please close Forge and resolve this.");
|
||||
throw ex;
|
||||
} finally {
|
||||
try {
|
||||
assert fileInputStream != null;
|
||||
fileInputStream.close();
|
||||
} catch (final IOException ignored) {
|
||||
// 11:08
|
||||
// PM
|
||||
}
|
||||
throw new RuntimeException("Error loading cardscript " + file.getName() + ". Please close Forge and resolve this.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package forge.util;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
public class CardTranslation {
|
||||
|
||||
private static Map <String, String> translatednames;
|
||||
@@ -24,7 +24,7 @@ public class CardTranslation {
|
||||
private static void readTranslationFile(String language, String languagesDirectory) {
|
||||
String filename = "cardnames-" + language + ".txt";
|
||||
|
||||
try (LineReader translationFile = new LineReader(new FileInputStream(languagesDirectory + filename), Charsets.UTF_8)) {
|
||||
try (LineReader translationFile = new LineReader(Files.newInputStream(Paths.get(languagesDirectory + filename)), StandardCharsets.UTF_8)) {
|
||||
for (String line : translationFile.readLines()) {
|
||||
String[] matches = line.split("\\|");
|
||||
if (matches.length >= 2) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -252,7 +253,7 @@ public final class FileUtil {
|
||||
final List<String> list = new ArrayList<>();
|
||||
try {
|
||||
final BufferedReader in = new BufferedReader(
|
||||
new InputStreamReader(new FileInputStream(file), "UTF-8"));
|
||||
new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
if (mayTrim) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package forge.assets;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
@@ -370,7 +371,7 @@ public class FSkinFont {
|
||||
String[] translationFilePaths = { ForgeConstants.LANG_DIR + "cardnames-" + langCode + ".txt",
|
||||
ForgeConstants.LANG_DIR + langCode + ".properties" };
|
||||
for (String translationFilePath : translationFilePaths) {
|
||||
try (LineReader translationFile = new LineReader(new FileInputStream(translationFilePath),
|
||||
try (LineReader translationFile = new LineReader(Files.newInputStream(Paths.get(translationFilePath)),
|
||||
StandardCharsets.UTF_8)) {
|
||||
for (String fileLine : translationFile.readLines()) {
|
||||
final int stringLength = fileLine.length();
|
||||
|
||||
@@ -98,7 +98,7 @@ public class GauntletIO {
|
||||
|
||||
public static GauntletData loadGauntlet(final File xmlSaveFile) {
|
||||
boolean isCorrupt = false;
|
||||
try (GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
||||
try (GZIPInputStream zin = new GZIPInputStream(Files.newInputStream(xmlSaveFile.toPath()));
|
||||
InputStreamReader reader = new InputStreamReader(zin)) {
|
||||
final GauntletData data = (GauntletData)GauntletIO.getSerializer(true).fromXML(reader);
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ public class QuestDataIO {
|
||||
QuestData data;
|
||||
final StringBuilder xml = new StringBuilder();
|
||||
|
||||
try (GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
||||
try (GZIPInputStream zin = new GZIPInputStream(Files.newInputStream(xmlSaveFile.toPath()));
|
||||
InputStreamReader reader = new InputStreamReader(zin)) {
|
||||
final char[] buf = new char[1024];
|
||||
while (reader.ready()) {
|
||||
|
||||
@@ -79,7 +79,7 @@ public class TournamentIO {
|
||||
|
||||
public static TournamentData loadTournament(final File xmlSaveFile) {
|
||||
boolean isCorrupt = false;
|
||||
try (GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
||||
try (GZIPInputStream zin = new GZIPInputStream(Files.newInputStream(xmlSaveFile.toPath()));
|
||||
InputStreamReader reader = new InputStreamReader(zin)) {
|
||||
final TournamentData data = (TournamentData)TournamentIO.getSerializer(true).fromXML(reader);
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ public class GuiDownloadZipService extends GuiDownloadService {
|
||||
final byte[] buffer = new byte[1024];
|
||||
int len;
|
||||
|
||||
try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outPath))) {
|
||||
try (BufferedOutputStream out = new BufferedOutputStream(java.nio.file.Files.newOutputStream(Paths.get(outPath)))) {
|
||||
while ((len = in.read(buffer)) >= 0) {
|
||||
out.write(buffer, 0, len);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
package forge.localinstance.properties;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ForgeProfileProperties {
|
||||
final File propFile = new File(ForgeConstants.PROFILE_FILE);
|
||||
try {
|
||||
if (propFile.canRead() && !isUsingAppDirectory) {
|
||||
props.load(new FileInputStream(propFile));
|
||||
props.load(Files.newInputStream(propFile.toPath()));
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
System.err.println("error while reading from profile properties file");
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
@@ -55,7 +56,7 @@ public class ZipUtil {
|
||||
public static String unzip(File fileZip, File destDir) throws IOException {
|
||||
StringBuilder val = new StringBuilder();
|
||||
byte[] buffer = new byte[1024];
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
|
||||
ZipInputStream zis = new ZipInputStream(Files.newInputStream(fileZip.toPath()));
|
||||
ZipEntry zipEntry = zis.getNextEntry();
|
||||
while (zipEntry != null) {
|
||||
File newFile = newFile(destDir, zipEntry);
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package forge.lda.lda.inference;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
public class InferenceProperties {
|
||||
@@ -63,8 +63,8 @@ public class InferenceProperties {
|
||||
}
|
||||
|
||||
class PropertiesLoader {
|
||||
public InputStream getInputStream(String fileName) throws FileNotFoundException {
|
||||
public InputStream getInputStream(String fileName) throws IOException {
|
||||
if (fileName == null) throw new NullPointerException();
|
||||
return new FileInputStream(fileName);
|
||||
return Files.newInputStream(Paths.get(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user