Skip to content

Commit

Permalink
forgot to read resource from stream so it failed when packaged as a jar
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltester authored and eviltester committed Dec 12, 2017
1 parent 014633c commit 98361f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,25 @@ public LinkQueueFileReader(File linkQueueFile) {
try {
BufferedReader fileReader = new BufferedReader(new FileReader(linkQueueFile));

String aURL = fileReader.readLine();
readBufferedReaderAsLinkQueue(fileReader, linkQueueFile.getAbsolutePath());

} catch (Exception e) {
e.printStackTrace();
System.out.println("Something went wrong reading file " + linkQueueFile.getAbsolutePath());
}
}

public LinkQueueFileReader(InputStream fileToRead, String fileName) {

queue = new LinkQueue();

BufferedReader reader = new BufferedReader(new InputStreamReader(fileToRead));
readBufferedReaderAsLinkQueue(reader, fileName);
}

private void readBufferedReaderAsLinkQueue(BufferedReader reader, String fileName) {
try{
String aURL = reader.readLine();
while(aURL!=null){
try{
URL anActualURL = new URL(aURL);
Expand All @@ -24,15 +42,15 @@ public LinkQueueFileReader(File linkQueueFile) {
System.out.println("Ignoring non-url line");
System.out.println(aURL);
}
aURL = fileReader.readLine();
aURL = reader.readLine();
}

} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("Something went wrong creating reader for file " + linkQueueFile.getAbsolutePath());
System.out.println("Something went wrong creating reader for file " + fileName);
} catch (IOException e) {
e.printStackTrace();
System.out.println("Something went wrong reading file " + linkQueueFile.getAbsolutePath());
System.out.println("Something went wrong reading file " + fileName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import uk.co.compendiumdev.javafortesters.gui.urllauncher.PhysicalUrlLauncher;

import java.io.File;
import java.net.URL;
import java.io.InputStream;
import java.util.Optional;


Expand Down Expand Up @@ -293,13 +293,10 @@ private LinkQueue loadDefaultLinks() {

try {

URL fileToRead = HTTPLinkCheckerGridStage.class.getResource(filenameForResource);
File linkQueueFile;
InputStream fileToRead = HTTPLinkCheckerGridStage.class.getResourceAsStream(filenameForResource);

linkQueueFile = new File(fileToRead.toURI());

if(linkQueueFile!=null) {
LinkQueueFileReader fileReader = new LinkQueueFileReader(linkQueueFile);
if(fileToRead!=null) {
LinkQueueFileReader fileReader = new LinkQueueFileReader(fileToRead, "Resource: " + filenameForResource);
links = fileReader.getQueue();
}

Expand Down

0 comments on commit 98361f4

Please sign in to comment.