Skip to content

Commit 0a66b4e

Browse files
committed
Fix biojava#933 URLConnection to invalid HTTP URL is not detected as failure
When the httpConnection is invalid, the application does not detect it, and it saves an empty (precisely a 20 bytes) file. This fix detects when the connection is invalid or the file has no contents. Related to biojava#703
1 parent 7b76f8f commit 0a66b4e

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/chem/DownloadChemCompProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.io.FileOutputStream;
1515
import java.io.FilenameFilter;
1616
import java.io.IOException;
17-
import java.io.InputStream;
1817
import java.io.InputStreamReader;
1918
import java.io.PrintWriter;
2019
import java.io.StringWriter;
@@ -320,8 +319,13 @@ private static boolean downloadChemCompRecord(String recordName) {
320319
try (PrintWriter pw = new PrintWriter(new GZIPOutputStream(new FileOutputStream(newFile)));
321320
BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(uconn.getInputStream()))) {
322321
String line;
322+
boolean success = false;
323323
while ((line = fileBuffer.readLine()) != null) {
324324
pw.println(line);
325+
success = true;
326+
}
327+
if(!success) {
328+
throw new IOException("Could not read from URL "+url.toString());
325329
}
326330

327331
pw.flush();

0 commit comments

Comments
 (0)