Skip to content

Commit

Permalink
Fixed loading licenses on non-windows systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
crbednarz committed Dec 17, 2013
1 parent 7fcde13 commit 8a2a57e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/amidst/gui/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;

import amidst.logging.Log;
import amidst.resources.ResourceLoader;

public class License {
private File file;
private InputStream fileStream;
private String name;
private String contents;
private boolean loaded = false;

public License(String name, String path) {
this.name = name;
try {
file = new File(ResourceLoader.getResourceURL(path).toURI());
} catch (URISyntaxException e) {
Log.w("Error loading license for: " + name + " at path: " + path);
e.printStackTrace();
fileStream = ResourceLoader.getResourceStream(path);
} catch (NullPointerException e) {
Log.w("Error finding license for: " + name + " at path: " + path);
e.printStackTrace();
Expand All @@ -36,14 +35,7 @@ public String getName() {
public void load() {
if (loaded)
return;
FileReader fileReader = null;
try {
fileReader = new FileReader(file);
} catch (FileNotFoundException e) {
Log.w("Unable to find license: " + name + " with file: " + file);
e.printStackTrace();
return;
}
BufferedReader fileReader = new BufferedReader(new InputStreamReader(fileStream));
BufferedReader bufferedReader = new BufferedReader(fileReader);
try {
StringBuilder stringBuilder = new StringBuilder();
Expand All @@ -57,13 +49,13 @@ public void load() {
contents = stringBuilder.toString();
loaded = true;
} catch (IOException e) {
Log.w("Unable to read file: " + name + " with path " + file);
Log.w("Unable to read file: " + name + ".");
e.printStackTrace();
} finally {
try {
bufferedReader.close();
} catch (IOException e) {
Log.w("Unable to close BufferedReader for: " + name + " with file: " + file);
Log.w("Unable to close BufferedReader for: " + name + ".");
e.printStackTrace();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/amidst/resources/ResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class ResourceLoader {
Expand All @@ -14,6 +15,10 @@ public static URL getResourceURL(String name) {
return ResourceLoader.class.getResource(name);
}

public static InputStream getResourceStream(String name) {
return ResourceLoader.class.getResourceAsStream(name);
}

public static BufferedImage getImage(String name) {
try {
return ImageIO.read(getResourceURL(name));
Expand Down

0 comments on commit 8a2a57e

Please sign in to comment.