|
48 | 48 | import java.io.BufferedReader;
|
49 | 49 | import java.io.File;
|
50 | 50 | import java.io.FileInputStream;
|
51 |
| -import java.io.FileNotFoundException; |
52 | 51 | import java.io.IOException;
|
53 | 52 | import java.io.InputStream;
|
54 | 53 | import java.io.InputStreamReader;
|
|
66 | 65 | import org.jruby.Ruby;
|
67 | 66 | import org.jruby.RubyHash;
|
68 | 67 | import org.jruby.ext.openssl.SecurityHelper;
|
69 |
| -import org.jruby.util.FileResource; |
70 | 68 | 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; |
71 | 74 |
|
72 | 75 | /**
|
73 | 76 | * X509_LOOKUP
|
@@ -299,12 +302,25 @@ private InputStream wrapJRubyNormalizedInputStream(String file) throws IOExcepti
|
299 | 302 | try {
|
300 | 303 | return JRubyFile.createResource(runtime, file).inputStream();
|
301 | 304 | }
|
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); |
306 | 323 | }
|
307 |
| - return new BufferedInputStream(new FileInputStream(f)); |
308 | 324 | }
|
309 | 325 | }
|
310 | 326 |
|
|
0 commit comments