Skip to content

Commit 79269fd

Browse files
committed
use the code from jossl-0.9.5 for wrapJRubyNormalizedInputStream
the new JRubyFile.createResource.inputStream is new to jruby-1.7.17, i.e. use the old code for older jrubies Sponsored by Lookout Inc.
1 parent 5bd16b9 commit 79269fd

File tree

1 file changed

+23
-7
lines changed
  • src/main/java/org/jruby/ext/openssl/x509store

1 file changed

+23
-7
lines changed

src/main/java/org/jruby/ext/openssl/x509store/Lookup.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import java.io.BufferedReader;
4949
import java.io.File;
5050
import java.io.FileInputStream;
51-
import java.io.FileNotFoundException;
5251
import java.io.IOException;
5352
import java.io.InputStream;
5453
import java.io.InputStreamReader;
@@ -66,8 +65,12 @@
6665
import org.jruby.Ruby;
6766
import org.jruby.RubyHash;
6867
import org.jruby.ext.openssl.SecurityHelper;
69-
import org.jruby.util.FileResource;
7068
import org.jruby.util.JRubyFile;
69+
import org.jruby.util.io.ChannelDescriptor;
70+
import org.jruby.util.io.ChannelStream;
71+
import org.jruby.util.io.FileExistsException;
72+
import org.jruby.util.io.InvalidValueException;
73+
import org.jruby.util.io.ModeFlags;
7174

7275
/**
7376
* X509_LOOKUP
@@ -299,12 +302,25 @@ private InputStream wrapJRubyNormalizedInputStream(String file) throws IOExcepti
299302
try {
300303
return JRubyFile.createResource(runtime, file).inputStream();
301304
}
302-
catch (NoSuchMethodError e) { // JRubyFile.createResource (JRuby < 1.7.13)
303-
File f = new File(file);
304-
if ( ! f.isAbsolute() ) {
305-
f = new File(runtime.getCurrentDirectory(), file);
305+
catch (NoSuchMethodError e) { // JRubyFile.createResource.inputStream (JRuby < 1.7.17)
306+
try {
307+
ChannelDescriptor descriptor = ChannelDescriptor.open(runtime.getCurrentDirectory(), file, new ModeFlags(ModeFlags.RDONLY));
308+
return ChannelStream.open(runtime, descriptor).newInputStream();
309+
} catch (NoSuchMethodError nsme) {
310+
File f = new File(file);
311+
if ( ! f.isAbsolute() ) {
312+
f = new File(runtime.getCurrentDirectory(), file);
313+
}
314+
return new BufferedInputStream(new FileInputStream(f));
315+
} catch (FileExistsException fee) {
316+
// should not happen because ModeFlag does not contain CREAT.
317+
fee.printStackTrace(System.err);
318+
throw new IllegalStateException(fee.getMessage(), fee);
319+
} catch (InvalidValueException ive) {
320+
// should not happen because ModeFlasg does not contain APPEND.
321+
ive.printStackTrace(System.err);
322+
throw new IllegalStateException(ive.getMessage(), ive);
306323
}
307-
return new BufferedInputStream(new FileInputStream(f));
308324
}
309325
}
310326

0 commit comments

Comments
 (0)