mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Merge branch 'sonarqubefixes01' into 'master'
Fixes some SonarQube detected bugs See merge request core-developers/forge!2019
This commit is contained in:
@@ -228,7 +228,7 @@ public class ComputerUtilCard {
|
|||||||
Card cheapest = null;
|
Card cheapest = null;
|
||||||
|
|
||||||
for (Card c : all) {
|
for (Card c : all) {
|
||||||
if (cheapest == null || cheapest.getManaCost().getCMC() <= cheapest.getManaCost().getCMC()) {
|
if (cheapest == null || c.getManaCost().getCMC() <= cheapest.getManaCost().getCMC()) {
|
||||||
cheapest = c;
|
cheapest = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
|
|||||||
return "n/a";
|
return "n/a";
|
||||||
}
|
}
|
||||||
final String toReturn = MagicColor.toLongString(myColor);
|
final String toReturn = MagicColor.toLongString(myColor);
|
||||||
if (toReturn == MagicColor.Constant.COLORLESS && myColor != 0) {
|
if (toReturn.equals(MagicColor.Constant.COLORLESS) && myColor != 0) {
|
||||||
return "multi";
|
return "multi";
|
||||||
}
|
}
|
||||||
return toReturn;
|
return toReturn;
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ public class BoosterGenerator {
|
|||||||
// 1 out of ~30 normal and mythic rares are foil,
|
// 1 out of ~30 normal and mythic rares are foil,
|
||||||
// match that.
|
// match that.
|
||||||
// If not special card, make it always foil.
|
// If not special card, make it always foil.
|
||||||
if ((MyRandom.getRandom().nextInt(30) == 1) || (foilSlot != BoosterSlots.SPECIAL)) {
|
if ((MyRandom.getRandom().nextInt(30) == 1) || (!foilSlot.equals(BoosterSlots.SPECIAL))) {
|
||||||
foilCardGeneratedAndHeld.add(generateFoilCard(ps));
|
foilCardGeneratedAndHeld.add(generateFoilCard(ps));
|
||||||
} else {
|
} else {
|
||||||
// Otherwise it's not foil (even though this is the
|
// Otherwise it's not foil (even though this is the
|
||||||
|
|||||||
@@ -106,11 +106,8 @@ public final class FileUtil {
|
|||||||
File source = new File(sourceFilename);
|
File source = new File(sourceFilename);
|
||||||
if (!source.exists()) { return; } //if source doesn't exist, nothing to copy
|
if (!source.exists()) { return; } //if source doesn't exist, nothing to copy
|
||||||
|
|
||||||
InputStream is = null;
|
try (InputStream is = new FileInputStream(source);
|
||||||
OutputStream os = null;
|
OutputStream os = new FileOutputStream(new File(destFilename))){
|
||||||
try {
|
|
||||||
is = new FileInputStream(source);
|
|
||||||
os = new FileOutputStream(new File(destFilename));
|
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int length;
|
int length;
|
||||||
while ((length = is.read(buffer)) > 0) {
|
while ((length = is.read(buffer)) > 0) {
|
||||||
@@ -120,15 +117,6 @@ public final class FileUtil {
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
try {
|
|
||||||
is.close();
|
|
||||||
os.close();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeFile(String filename, String text) {
|
public static void writeFile(String filename, String text) {
|
||||||
@@ -136,10 +124,8 @@ public final class FileUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void writeFile(File file, String text) {
|
public static void writeFile(File file, String text) {
|
||||||
try {
|
try (PrintWriter p = new PrintWriter(file)) {
|
||||||
PrintWriter p = new PrintWriter(file);
|
|
||||||
p.print(text);
|
p.print(text);
|
||||||
p.close();
|
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex);
|
throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex);
|
||||||
}
|
}
|
||||||
@@ -174,12 +160,10 @@ public final class FileUtil {
|
|||||||
* a {@link java.util.List} object.
|
* a {@link java.util.List} object.
|
||||||
*/
|
*/
|
||||||
public static void writeFile(File file, Collection<?> data) {
|
public static void writeFile(File file, Collection<?> data) {
|
||||||
try {
|
try (PrintWriter p = new PrintWriter(file)) {
|
||||||
PrintWriter p = new PrintWriter(file);
|
|
||||||
for (Object o : data) {
|
for (Object o : data) {
|
||||||
p.println(o);
|
p.println(o);
|
||||||
}
|
}
|
||||||
p.close();
|
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex);
|
throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex);
|
||||||
}
|
}
|
||||||
@@ -291,11 +275,12 @@ public final class FileUtil {
|
|||||||
ThreadUtil.executeWithTimeout(new Callable<Void>() {
|
ThreadUtil.executeWithTimeout(new Callable<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void call() throws Exception {
|
public Void call() throws Exception {
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
|
try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) {
|
||||||
String line;
|
String line;
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, 5000); //abort reading file if it takes longer than 5 seconds
|
}, 5000); //abort reading file if it takes longer than 5 seconds
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ public class GameFormat implements Comparable<GameFormat> {
|
|||||||
rarities = Lists.newArrayList();
|
rarities = Lists.newArrayList();
|
||||||
for (String s: Arrays.asList(strCars.split(", "))) {
|
for (String s: Arrays.asList(strCars.split(", "))) {
|
||||||
cr = CardRarity.smartValueOf(s);
|
cr = CardRarity.smartValueOf(s);
|
||||||
if (cr.name() != "Unknown") {
|
if (!cr.name().equals("Unknown")) {
|
||||||
rarities.add(cr);
|
rarities.add(cr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
|||||||
sb.append(num).append(" of those ").append(type).append(" card(s)");
|
sb.append(num).append(" of those ").append(type).append(" card(s)");
|
||||||
} else {
|
} else {
|
||||||
sb.append(destination.equals("Exile") ? " exiles " : " puts ");
|
sb.append(destination.equals("Exile") ? " exiles " : " puts ");
|
||||||
if (type == "Card") {
|
if (type.equals("Card")) {
|
||||||
sb.append(num);
|
sb.append(num);
|
||||||
} else {
|
} else {
|
||||||
sb.append(num).append(" ").append(type);
|
sb.append(num).append(" ").append(type);
|
||||||
@@ -208,7 +208,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sb.append(" of ").append(fetchPlayer);
|
sb.append(" of ").append(fetchPlayer);
|
||||||
if (fetchPlayer != "their") {
|
if (!fetchPlayer.equals("their")) {
|
||||||
sb.append("'s");
|
sb.append("'s");
|
||||||
}
|
}
|
||||||
sb.append(" library");
|
sb.append(" library");
|
||||||
|
|||||||
@@ -1011,21 +1011,12 @@ public class ImportDialog {
|
|||||||
destFile.createNewFile();
|
destFile.createNewFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInputStream srcStream = null;
|
try (FileInputStream srcStream = new FileInputStream(srcFile);
|
||||||
FileChannel src = null;
|
FileChannel src = srcStream.getChannel();
|
||||||
FileOutputStream destStream = null;
|
FileOutputStream destStream = new FileOutputStream(destFile);
|
||||||
FileChannel dest = null;
|
FileChannel dest = destStream.getChannel()
|
||||||
try {
|
) {
|
||||||
srcStream = new FileInputStream(srcFile);
|
|
||||||
src = srcStream.getChannel();
|
|
||||||
destStream = new FileOutputStream(destFile);
|
|
||||||
dest = destStream.getChannel();
|
|
||||||
dest.transferFrom(src, 0, src.size());
|
dest.transferFrom(src, 0, src.size());
|
||||||
} finally {
|
|
||||||
if (src != null) { src.close(); }
|
|
||||||
if (srcStream != null) { srcStream.close(); }
|
|
||||||
if (dest != null) { dest.close(); }
|
|
||||||
if (destStream != null) { destStream.close(); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleteSrcAfter) {
|
if (deleteSrcAfter) {
|
||||||
|
|||||||
@@ -174,8 +174,7 @@ public class CardReaderExperiments {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
try {
|
try (PrintWriter p = new PrintWriter(file)) {
|
||||||
PrintWriter p = new PrintWriter(file);
|
|
||||||
for (int i = 0; i < lines.size(); i++) {
|
for (int i = 0; i < lines.size(); i++) {
|
||||||
if (i < lines.size() - 1) {
|
if (i < lines.size() - 1) {
|
||||||
p.println(lines.get(i));
|
p.println(lines.get(i));
|
||||||
@@ -184,7 +183,6 @@ public class CardReaderExperiments {
|
|||||||
p.print(lines.get(i));
|
p.print(lines.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.close();
|
|
||||||
output.add(rules.getName());
|
output.add(rules.getName());
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,13 +49,11 @@ public final class CardScriptInfo {
|
|||||||
public boolean trySetText(final String text0) {
|
public boolean trySetText(final String text0) {
|
||||||
if (file == null) { return false; }
|
if (file == null) { return false; }
|
||||||
|
|
||||||
try {
|
try (PrintWriter p = new PrintWriter(file)) {
|
||||||
final PrintWriter p = new PrintWriter(file);
|
|
||||||
p.print(text0);
|
p.print(text0);
|
||||||
if (!text0.endsWith(("\n"))){
|
if (!text0.endsWith(("\n"))){
|
||||||
p.print("\n");
|
p.print("\n");
|
||||||
}
|
}
|
||||||
p.close();
|
|
||||||
|
|
||||||
text = text0;
|
text = text0;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -19,31 +19,19 @@ public class CardThemedLDAIO {
|
|||||||
|
|
||||||
public static void saveRawLDA(String format, List<Archetype> lda){
|
public static void saveRawLDA(String format, List<Archetype> lda){
|
||||||
File file = getRAWLDAFile(format);
|
File file = getRAWLDAFile(format);
|
||||||
ObjectOutputStream s = null;
|
try (FileOutputStream f = new FileOutputStream(file);
|
||||||
try {
|
ObjectOutputStream s = new ObjectOutputStream(f)){
|
||||||
FileOutputStream f = new FileOutputStream(file);
|
|
||||||
s = new ObjectOutputStream(f);
|
|
||||||
s.writeObject(lda);
|
s.writeObject(lda);
|
||||||
s.close();
|
s.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error writing matrix data: " + e);
|
System.out.println("Error writing matrix data: " + e);
|
||||||
} finally {
|
|
||||||
if(s!=null) {
|
|
||||||
try {
|
|
||||||
s.close();
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Archetype> loadRawLDA(String format){
|
public static List<Archetype> loadRawLDA(String format){
|
||||||
try {
|
try (FileInputStream fin = new FileInputStream(getRAWLDAFile(format));
|
||||||
FileInputStream fin = new FileInputStream(getRAWLDAFile(format));
|
ObjectInputStream s = new ObjectInputStream(fin)) {
|
||||||
ObjectInputStream s = new ObjectInputStream(fin);
|
|
||||||
List<Archetype> matrix = (List<Archetype>) s.readObject();
|
List<Archetype> matrix = (List<Archetype>) s.readObject();
|
||||||
s.close();
|
|
||||||
return matrix;
|
return matrix;
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
System.out.println("Error reading LDA data: " + e);
|
System.out.println("Error reading LDA data: " + e);
|
||||||
@@ -54,37 +42,24 @@ public class CardThemedLDAIO {
|
|||||||
|
|
||||||
public static void saveLDA(String format, Map<String,List<List<Pair<String, Double>>>> map){
|
public static void saveLDA(String format, Map<String,List<List<Pair<String, Double>>>> map){
|
||||||
File file = getLDAFile(format);
|
File file = getLDAFile(format);
|
||||||
ObjectOutputStream s = null;
|
|
||||||
try {
|
try (FileOutputStream f = new FileOutputStream(file);
|
||||||
FileOutputStream f = new FileOutputStream(file);
|
ObjectOutputStream s = new ObjectOutputStream(f)){
|
||||||
s = new ObjectOutputStream(f);
|
|
||||||
s.writeObject(map);
|
s.writeObject(map);
|
||||||
s.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error writing matrix data: " + e);
|
System.out.println("Error writing matrix data: " + e);
|
||||||
} finally {
|
|
||||||
if(s!=null) {
|
|
||||||
try {
|
|
||||||
s.close();
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String,List<List<Pair<String, Double>>>> loadLDA(String format){
|
public static Map<String,List<List<Pair<String, Double>>>> loadLDA(String format){
|
||||||
try {
|
try (FileInputStream fin = new FileInputStream(getLDAFile(format));
|
||||||
FileInputStream fin = new FileInputStream(getLDAFile(format));
|
ObjectInputStream s = new ObjectInputStream(fin)) {
|
||||||
ObjectInputStream s = new ObjectInputStream(fin);
|
|
||||||
Map<String,List<List<Pair<String, Double>>>> matrix = (Map<String,List<List<Pair<String, Double>>>>) s.readObject();
|
Map<String,List<List<Pair<String, Double>>>> matrix = (Map<String,List<List<Pair<String, Double>>>>) s.readObject();
|
||||||
s.close();
|
|
||||||
return matrix;
|
return matrix;
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
System.out.println("Error reading LDA data: " + e);
|
System.out.println("Error reading LDA data: " + e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getLDAFile(final String name) {
|
public static File getLDAFile(final String name) {
|
||||||
|
|||||||
@@ -24,37 +24,23 @@ public class CardThemedMatrixIO {
|
|||||||
|
|
||||||
public static void saveMatrix(String format, HashMap<String,List<Map.Entry<PaperCard,Integer>>> map){
|
public static void saveMatrix(String format, HashMap<String,List<Map.Entry<PaperCard,Integer>>> map){
|
||||||
File file = getMatrixFile(format);
|
File file = getMatrixFile(format);
|
||||||
ObjectOutputStream s = null;
|
try (FileOutputStream f = new FileOutputStream(file);
|
||||||
try {
|
ObjectOutputStream s = new ObjectOutputStream(f)) {
|
||||||
FileOutputStream f = new FileOutputStream(file);
|
|
||||||
s = new ObjectOutputStream(f);
|
|
||||||
s.writeObject(map);
|
s.writeObject(map);
|
||||||
s.close();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Error writing matrix data: " + e);
|
System.out.println("Error writing matrix data: " + e);
|
||||||
} finally {
|
|
||||||
if(s!=null) {
|
|
||||||
try {
|
|
||||||
s.close();
|
|
||||||
}catch(Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String,List<Map.Entry<PaperCard,Integer>>> loadMatrix(String format){
|
public static HashMap<String,List<Map.Entry<PaperCard,Integer>>> loadMatrix(String format){
|
||||||
try {
|
try (FileInputStream fin = new FileInputStream(getMatrixFile(format));
|
||||||
FileInputStream fin = new FileInputStream(getMatrixFile(format));
|
ObjectInputStream s = new ObjectInputStream(fin)){
|
||||||
ObjectInputStream s = new ObjectInputStream(fin);
|
|
||||||
HashMap<String, List<Map.Entry<PaperCard,Integer>>> matrix = (HashMap<String, List<Map.Entry<PaperCard,Integer>>>) s.readObject();
|
HashMap<String, List<Map.Entry<PaperCard,Integer>>> matrix = (HashMap<String, List<Map.Entry<PaperCard,Integer>>>) s.readObject();
|
||||||
s.close();
|
|
||||||
return matrix;
|
return matrix;
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
System.out.println("Error reading matrix data: " + e);
|
System.out.println("Error reading matrix data: " + e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getMatrixFile(final String name) {
|
public static File getMatrixFile(final String name) {
|
||||||
|
|||||||
@@ -145,12 +145,9 @@ public class BugReporter {
|
|||||||
|
|
||||||
f = GuiBase.getInterface().getSaveFile(f);
|
f = GuiBase.getInterface().getSaveFile(f);
|
||||||
|
|
||||||
try {
|
try (BufferedWriter bw = new BufferedWriter(new FileWriter(f))){
|
||||||
final BufferedWriter bw = new BufferedWriter(new FileWriter(f));
|
|
||||||
bw.write(text);
|
bw.write(text);
|
||||||
bw.close();
|
} catch (final IOException ex) {
|
||||||
}
|
|
||||||
catch (final IOException ex) {
|
|
||||||
SOptionPane.showMessageDialog("There was an error during saving. Sorry!\n" + ex,
|
SOptionPane.showMessageDialog("There was an error during saving. Sorry!\n" + ex,
|
||||||
"Error saving file", SOptionPane.ERROR_ICON);
|
"Error saving file", SOptionPane.ERROR_ICON);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,37 +109,23 @@ public class GauntletIO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static GauntletData loadGauntlet(final File xmlSaveFile) {
|
public static GauntletData loadGauntlet(final File xmlSaveFile) {
|
||||||
GZIPInputStream zin = null;
|
|
||||||
boolean isCorrupt = false;
|
boolean isCorrupt = false;
|
||||||
try {
|
try (GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
||||||
zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
InputStreamReader reader = new InputStreamReader(zin)) {
|
||||||
final InputStreamReader reader = new InputStreamReader(zin);
|
|
||||||
|
|
||||||
final GauntletData data = (GauntletData)GauntletIO.getSerializer(true).fromXML(reader);
|
final GauntletData data = (GauntletData)GauntletIO.getSerializer(true).fromXML(reader);
|
||||||
|
|
||||||
final String filename = xmlSaveFile.getName();
|
final String filename = xmlSaveFile.getName();
|
||||||
data.setName(filename.substring(0, filename.length() - SUFFIX_DATA.length()));
|
data.setName(filename.substring(0, filename.length() - SUFFIX_DATA.length()));
|
||||||
return data;
|
return data;
|
||||||
}
|
} catch (final IOException e) {
|
||||||
catch (final IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
} catch (final ConversionException e) {
|
||||||
catch (final ConversionException e) {
|
|
||||||
BugReporter.reportException(e);
|
BugReporter.reportException(e);
|
||||||
}
|
} catch (final Exception e) { //if there's a non-IO exception, delete the corrupt file
|
||||||
catch (final Exception e) { //if there's a non-IO exception, delete the corrupt file
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
isCorrupt = true;
|
isCorrupt = true;
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
if (zin != null) {
|
|
||||||
try {
|
|
||||||
zin.close();
|
|
||||||
} catch (final IOException e) {
|
|
||||||
System.out.println("error closing gauntlet data reader: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isCorrupt) {
|
if (isCorrupt) {
|
||||||
try {
|
try {
|
||||||
xmlSaveFile.delete();
|
xmlSaveFile.delete();
|
||||||
|
|||||||
@@ -120,11 +120,11 @@ public class QuestDataIO {
|
|||||||
*/
|
*/
|
||||||
public static QuestData loadData(final File xmlSaveFile) throws IOException {
|
public static QuestData loadData(final File xmlSaveFile) throws IOException {
|
||||||
QuestData data;
|
QuestData data;
|
||||||
|
|
||||||
final GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
|
||||||
final StringBuilder xml = new StringBuilder();
|
final StringBuilder xml = new StringBuilder();
|
||||||
|
|
||||||
|
try (GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
||||||
|
InputStreamReader reader = new InputStreamReader(zin)) {
|
||||||
final char[] buf = new char[1024];
|
final char[] buf = new char[1024];
|
||||||
final InputStreamReader reader = new InputStreamReader(zin);
|
|
||||||
while (reader.ready()) {
|
while (reader.ready()) {
|
||||||
final int len = reader.read(buf);
|
final int len = reader.read(buf);
|
||||||
if (len == -1) {
|
if (len == -1) {
|
||||||
@@ -132,8 +132,7 @@ public class QuestDataIO {
|
|||||||
} // when end of stream was reached
|
} // when end of stream was reached
|
||||||
xml.append(buf, 0, len);
|
xml.append(buf, 0, len);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
zin.close();
|
|
||||||
|
|
||||||
String bigXML = xml.toString();
|
String bigXML = xml.toString();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -83,34 +83,21 @@ public class TournamentIO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static TournamentData loadTournament(final File xmlSaveFile) {
|
public static TournamentData loadTournament(final File xmlSaveFile) {
|
||||||
GZIPInputStream zin = null;
|
|
||||||
boolean isCorrupt = false;
|
boolean isCorrupt = false;
|
||||||
try {
|
try (GZIPInputStream zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
||||||
zin = new GZIPInputStream(new FileInputStream(xmlSaveFile));
|
InputStreamReader reader = new InputStreamReader(zin)) {
|
||||||
final InputStreamReader reader = new InputStreamReader(zin);
|
|
||||||
|
|
||||||
final TournamentData data = (TournamentData)TournamentIO.getSerializer(true).fromXML(reader);
|
final TournamentData data = (TournamentData)TournamentIO.getSerializer(true).fromXML(reader);
|
||||||
|
|
||||||
final String filename = xmlSaveFile.getName();
|
final String filename = xmlSaveFile.getName();
|
||||||
data.setName(filename.substring(0, filename.length() - SUFFIX_DATA.length()));
|
data.setName(filename.substring(0, filename.length() - SUFFIX_DATA.length()));
|
||||||
return data;
|
return data;
|
||||||
}
|
} catch (final IOException e) {
|
||||||
catch (final IOException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
} catch (final Exception e) { //if there's a non-IO exception, delete the corrupt file
|
||||||
catch (final Exception e) { //if there's a non-IO exception, delete the corrupt file
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
isCorrupt = true;
|
isCorrupt = true;
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
if (zin != null) {
|
|
||||||
try {
|
|
||||||
zin.close();
|
|
||||||
} catch (final IOException e) {
|
|
||||||
System.out.println("error closing tournament data reader: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isCorrupt) {
|
if (isCorrupt) {
|
||||||
try {
|
try {
|
||||||
xmlSaveFile.delete();
|
xmlSaveFile.delete();
|
||||||
|
|||||||
@@ -86,15 +86,9 @@ public class HttpUtil {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileInputStream uploadFileReader = null;
|
|
||||||
try {
|
|
||||||
uploadFileReader = new FileInputStream(f);
|
|
||||||
} catch (final FileNotFoundException e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final int numBytesToRead = 1024;
|
final int numBytesToRead = 1024;
|
||||||
int availableBytesToRead;
|
int availableBytesToRead;
|
||||||
try {
|
try (FileInputStream uploadFileReader = new FileInputStream(f)) {
|
||||||
while ((availableBytesToRead = uploadFileReader.available()) > 0) {
|
while ((availableBytesToRead = uploadFileReader.available()) > 0) {
|
||||||
byte[] bufferBytesRead;
|
byte[] bufferBytesRead;
|
||||||
bufferBytesRead = availableBytesToRead >= numBytesToRead ? new byte[numBytesToRead]
|
bufferBytesRead = availableBytesToRead >= numBytesToRead ? new byte[numBytesToRead]
|
||||||
@@ -103,10 +97,10 @@ public class HttpUtil {
|
|||||||
httpOut.write(bufferBytesRead);
|
httpOut.write(bufferBytesRead);
|
||||||
httpOut.flush();
|
httpOut.flush();
|
||||||
}
|
}
|
||||||
uploadFileReader.close();
|
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
httpOut.write(("--" + HttpUtil.BOUNDARY + "--\r\n").getBytes());
|
httpOut.write(("--" + HttpUtil.BOUNDARY + "--\r\n").getBytes());
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
@@ -157,15 +151,10 @@ public class HttpUtil {
|
|||||||
} catch (final MalformedURLException e) {
|
} catch (final MalformedURLException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
InputStream is = null;
|
|
||||||
try {
|
|
||||||
is = url.openStream();
|
|
||||||
} catch (final IOException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int ptr = 0;
|
int ptr = 0;
|
||||||
final StringBuffer buffer = new StringBuffer();
|
final StringBuffer buffer = new StringBuffer();
|
||||||
try {
|
try (InputStream is = url.openStream()) {
|
||||||
while ((ptr = is.read()) != -1) {
|
while ((ptr = is.read()) != -1) {
|
||||||
buffer.append((char) ptr);
|
buffer.append((char) ptr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user