Skip to content

Commit 74ad4f5

Browse files
Ensure PhysFSInputStream throws FileNotFoundException like SFSInputStream
1 parent 32fa232 commit 74ad4f5

File tree

5 files changed

+28
-29
lines changed

5 files changed

+28
-29
lines changed

physfs_java/src/main/java/com/maddox/rts/PhysFSInputStream.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package com.maddox.rts;
22

33
import java.io.File;
4-
import java.io.IOException;
4+
import java.io.FileNotFoundException;
55
import java.io.InputStream;
6-
import java.sql.SQLException;
76
import java.util.Arrays;
8-
import java.util.Locale;
97
import java.util.Objects;
10-
import java.util.concurrent.atomic.AtomicBoolean;
11-
import java.util.concurrent.atomic.AtomicInteger;
128

139
public class PhysFSInputStream extends InputStream {
1410

@@ -17,21 +13,25 @@ public class PhysFSInputStream extends InputStream {
1713
private long fd;
1814
private final String fileName;
1915

20-
public PhysFSInputStream(String file) {
16+
public PhysFSInputStream(String file) throws FileNotFoundException {
2117
this.fd = openRead(file);
2218
this.fileName = file;
2319
if (this.fd == 0) {
2420
var exc = new PhysFSException("while opening file " + file);
25-
var stackTrace = Thread.currentThread().getStackTrace();
26-
var stackTraceElems = Arrays.stream(stackTrace);
27-
if (stackTraceElems.noneMatch(elem -> "com.maddox.rts.ObjIO".equals(elem.getClassName()))) {
28-
PhysFS.logMissing(file);
21+
if (exc.getCode() == PhysFS.ERR_NOT_FOUND) {
22+
var stackTrace = Thread.currentThread().getStackTrace();
23+
var stackTraceElems = Arrays.stream(stackTrace);
24+
if (stackTraceElems.noneMatch(elem -> "com.maddox.rts.ObjIO".equals(elem.getClassName()))) {
25+
PhysFS.logMissing(file);
26+
}
27+
throw new FileNotFoundException(exc.getMessage());
28+
} else {
29+
throw exc;
2930
}
30-
throw exc;
3131
}
3232
}
3333

34-
public PhysFSInputStream(File file) {
34+
public PhysFSInputStream(File file) throws FileNotFoundException {
3535
this(file.getPath());
3636
}
3737

physfs_java/src/main/java/com/maddox/rts/PhysFSLoader.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.maddox.rts;
22

33
import java.io.ByteArrayOutputStream;
4-
import java.io.IOException;
54
import java.net.MalformedURLException;
65
import java.net.URL;
7-
import java.util.Enumeration;
86

97
public class PhysFSLoader extends ClassLoader {
108
private static PhysFSLoader loader = new PhysFSLoader();
@@ -57,7 +55,7 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
5755
} else {
5856
throw new ClassNotFoundException(name);
5957
}
60-
} catch (PhysFSException exc) {
58+
} catch (Exception exc) {
6159
throw new ClassNotFoundException(name, exc);
6260
}
6361
}

physfs_java/src/main/java/com/maddox/rts/PhysFSReader.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
package com.maddox.rts;
22

33
import java.io.File;
4+
import java.io.FileNotFoundException;
45
import java.io.InputStreamReader;
56
import java.io.UnsupportedEncodingException;
67

78
public class PhysFSReader extends InputStreamReader {
8-
public PhysFSReader(String file) {
9+
public PhysFSReader(String file) throws FileNotFoundException {
910
super(new PhysFSInputStream(file));
1011
}
1112

12-
public PhysFSReader(File file) {
13+
public PhysFSReader(File file) throws FileNotFoundException {
1314
super(new PhysFSInputStream(file));
1415
}
1516

16-
public PhysFSReader(String file, String charset) throws UnsupportedEncodingException {
17+
public PhysFSReader(String file, String charset) throws UnsupportedEncodingException, FileNotFoundException {
1718
super(new PhysFSInputStream(file), charset);
1819
}
1920

20-
public PhysFSReader(File file, String charset) throws UnsupportedEncodingException {
21+
public PhysFSReader(File file, String charset) throws UnsupportedEncodingException, FileNotFoundException {
2122
super(new PhysFSInputStream(file), charset);
2223
}
2324

24-
public PhysFSReader(String var1, int[] var2) {
25+
public PhysFSReader(String var1, int[] var2) throws FileNotFoundException {
2526
super(new PhysFSInputStream(var1));
2627
}
2728

28-
public PhysFSReader(File var1, int[] var2) {
29+
public PhysFSReader(File var1, int[] var2) throws FileNotFoundException {
2930
super(new PhysFSInputStream(var1));
3031
}
3132

32-
public PhysFSReader(String var1, String var2, int[] var3) throws UnsupportedEncodingException {
33+
public PhysFSReader(String var1, String var2, int[] var3) throws UnsupportedEncodingException, FileNotFoundException {
3334
super(new PhysFSInputStream(var1), var2);
3435
}
3536

36-
public PhysFSReader(File var1, String var2, int[] var3) throws UnsupportedEncodingException {
37+
public PhysFSReader(File var1, String var2, int[] var3) throws UnsupportedEncodingException, FileNotFoundException {
3738
super(new PhysFSInputStream(var1), var2);
3839
}
3940

physfs_java/src/main/java/com/maddox/rts/PhysFSURLConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public int getContentLength() {
2323
if (len > Integer.MAX_VALUE)
2424
return -1;
2525
else
26-
return (int)len;
26+
return (int) len;
2727
}
2828

2929
@Override

physfs_java/src/test/java/com/maddox/rts/PhysFSTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void redirectsSfsMountToZip() {
9595
@Test
9696
void inputStreamOpenUnmountedFile() {
9797
assertThrows(
98-
PhysFSException.class,
98+
FileNotFoundException.class,
9999
() -> new PhysFSInputStream("test2.ini"),
100100
"Attempting to open a file from an unmounted archive didn't throw an exception");
101101
}
@@ -112,7 +112,7 @@ void inputStreamTell() throws IOException {
112112
}
113113

114114
@Test
115-
void inputStreamSeek() {
115+
void inputStreamSeek() throws FileNotFoundException {
116116
long expectedPosition = -1;
117117
long actualPosition = -1;
118118

@@ -127,7 +127,7 @@ void inputStreamSeek() {
127127
}
128128

129129
@Test
130-
void inputStreamSeekEof() {
130+
void inputStreamSeekEof() throws FileNotFoundException {
131131
long seekPosition = -1;
132132
long fileLength = 0;
133133

@@ -141,7 +141,7 @@ void inputStreamSeekEof() {
141141
}
142142

143143
@Test
144-
void inputStreamSeekAfterEof() {
144+
void inputStreamSeekAfterEof() throws FileNotFoundException {
145145
try (PhysFSInputStream is = new PhysFSInputStream("test.ini")) {
146146
assertThrows(
147147
PhysFSException.class,
@@ -151,7 +151,7 @@ void inputStreamSeekAfterEof() {
151151
}
152152

153153
@Test
154-
void inputStreamEndOfFile() {
154+
void inputStreamEndOfFile() throws FileNotFoundException {
155155
try (PhysFSInputStream is = new PhysFSInputStream("test.ini")) {
156156
is.seek(is.fileLength());
157157
assertTrue(is.endOfFile(), "End of file condition was not set when seeking to end of file");

0 commit comments

Comments
 (0)