public InputStream getInputStream() throws IOException { if (resource != null) { InputStream is = resource.openStream(); try { return new LoadServiceResourceInputStream(is); } finally { is.close(); } } byte[] bytes = new byte[(int)path.length()]; ByteBuffer buffer = ByteBuffer.wrap(bytes); FileInputStream fis = new FileInputStream(path); FileChannel fc = fis.getChannel(); fc.read(buffer); fis.close(); return new LoadServiceResourceInputStream(bytes); }
/** * Construct a new LoadServiceInputStream by reading all bytes from the * specified stream. * * You are responsible for the lifecycle of the given stream after this * constructor has been called (i.e. it will not be closed for you). * * @param stream the stream from which to read bytes * @throws IOException if the reading causes an IOException */ public LoadServiceResourceInputStream(InputStream stream) throws IOException { super(NULL_BYTE_ARRAY); bufferEntireStream(stream); }
@SuppressWarnings("unchecked") public Node parse(String file, InputStream content, DynamicScope blockScope, ParserConfiguration configuration) { RubyArray list = getLines(configuration, runtime, file); if (content instanceof LoadServiceResourceInputStream) { return parse(file, ((LoadServiceResourceInputStream) content).getBytes(), blockScope, configuration); } else { LexerSource lexerSource = LexerSource.getSource(file, content, list, configuration); return parse(file, lexerSource, blockScope, configuration); } }
@SuppressWarnings("unchecked") public Node parse(String file, InputStream content, DynamicScope blockScope, ParserConfiguration configuration) { RubyArray list = getLines(configuration, runtime, file); if (content instanceof LoadServiceResourceInputStream) { return parse(file, ((LoadServiceResourceInputStream) content).getBytes(), blockScope, configuration); } else { LexerSource lexerSource = LexerSource.getSource(file, content, list, configuration); return parse(file, lexerSource, blockScope, configuration); } }
public InputStream getInputStream() throws IOException { if (resource != null) { InputStream is = resource.openStream(); try { return new LoadServiceResourceInputStream(is); } finally { is.close(); } } byte[] bytes = new byte[(int)path.length()]; ByteBuffer buffer = ByteBuffer.wrap(bytes); FileInputStream fis = new FileInputStream(path); FileChannel fc = fis.getChannel(); fc.read(buffer); fis.close(); return new LoadServiceResourceInputStream(bytes); }
@SuppressWarnings("unchecked") public Node parse(String file, InputStream content, DynamicScope blockScope, ParserConfiguration configuration) { if (content instanceof LoadServiceResourceInputStream) { return parse(file, ((LoadServiceResourceInputStream) content).getBytes(), blockScope, configuration); } else { RubyArray list = getLines(configuration, runtime, file); RubyIO io; if (content instanceof FileInputStream) { io = new RubyFile(runtime, file, ((FileInputStream) content).getChannel()); } else { io = RubyIO.newIO(runtime, Channels.newChannel(content)); } LexerSource lexerSource = new GetsLexerSource(file, configuration.getLineNumber(), io, list, configuration.getDefaultEncoding()); try { return parse(file, lexerSource, blockScope, configuration); } finally { // In case of GetsLexerSource we actually will dispatch to gets which will increment $. // We do not want that in the case of raw parsing. runtime.setCurrentLine(0); } } }
/** * Construct a new LoadServiceInputStream by reading all bytes from the * specified stream. * * You are responsible for the lifecycle of the given stream after this * constructor has been called (i.e. it will not be closed for you). * * @param stream the stream from which to read bytes * @throws IOException if the reading causes an IOException */ public LoadServiceResourceInputStream(InputStream stream) throws IOException { super(new byte[0]); bufferEntireStream(stream); }
public InputStream getInputStream() throws IOException { if (resource != null) { InputStream is = resource.openStream(); try { return new LoadServiceResourceInputStream(is); } finally { is.close(); } } byte[] bytes = new byte[(int)path.length()]; ByteBuffer buffer = ByteBuffer.wrap(bytes); FileInputStream fis = new FileInputStream(path); FileChannel fc = fis.getChannel(); fc.read(buffer); fis.close(); return new LoadServiceResourceInputStream(bytes); }
@SuppressWarnings("unchecked") public Node parse(String file, InputStream content, DynamicScope blockScope, ParserConfiguration configuration) { if (content instanceof LoadServiceResourceInputStream) { return parse(file, ((LoadServiceResourceInputStream) content).getBytes(), blockScope, configuration); } else { RubyArray list = getLines(configuration, runtime, file); RubyIO io; if (content instanceof FileInputStream) { io = new RubyFile(runtime, file, ((FileInputStream) content).getChannel()); } else { io = RubyIO.newIO(runtime, Channels.newChannel(content)); } LexerSource lexerSource = new GetsLexerSource(file, configuration.getLineNumber(), io, list, configuration.getDefaultEncoding()); try { return parse(file, lexerSource, blockScope, configuration); } finally { // In case of GetsLexerSource we actually will dispatch to gets which will increment $. // We do not want that in the case of raw parsing. runtime.setCurrentLine(0); } } }
/** * Construct a new LoadServiceInputStream by reading all bytes from the * specified stream. * * You are responsible for the lifecycle of the given stream after this * constructor has been called (i.e. it will not be closed for you). * * @param stream the stream from which to read bytes * @throws IOException if the reading causes an IOException */ public LoadServiceResourceInputStream(InputStream stream) throws IOException { super(NULL_BYTE_ARRAY); bufferEntireStream(stream); }
public InputStream getInputStream() throws IOException { if (resource != null) { InputStream is = resource.openStream(); try { return new LoadServiceResourceInputStream(is); } finally { is.close(); } } byte[] bytes = new byte[(int)path.length()]; ByteBuffer buffer = ByteBuffer.wrap(bytes); FileInputStream fis = new FileInputStream(path); FileChannel fc = fis.getChannel(); fc.read(buffer); fis.close(); return new LoadServiceResourceInputStream(bytes); }
/** * Construct a new LoadServiceInputStream by reading all bytes from the * specified stream. * * You are responsible for the lifecycle of the given stream after this * constructor has been called (i.e. it will not be closed for you). * * @param stream the stream from which to read bytes * @throws IOException if the reading causes an IOException */ public LoadServiceResourceInputStream(InputStream stream) throws IOException { super(new byte[0]); bufferEntireStream(stream); }
@Override public void load(Ruby runtime, boolean wrap) { InputStream ris = null; try { ris = resource.inputStream(); if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) { runtime.compileAndLoadFile(scriptName, ris, wrap); } else { runtime.loadFile(scriptName, new LoadServiceResourceInputStream(ris), wrap); } } catch(IOException e) { throw runtime.newLoadError("no such file to load -- " + searchName, searchName); } finally { try { if (ris != null) ris.close(); } catch (IOException ioE) { /* At least we tried.... */} } } }
@Override public void load(Ruby runtime, boolean wrap) { InputStream ris = null; try { ris = resource.inputStream(); if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) { runtime.compileAndLoadFile(scriptName, ris, wrap); } else { runtime.loadFile(scriptName, new LoadServiceResourceInputStream(ris), wrap); } } catch(IOException e) { throw runtime.newLoadError("no such file to load -- " + searchName, searchName); } finally { try { if (ris != null) ris.close(); } catch (IOException ioE) { /* At least we tried.... */} } } }
public void load(Ruby runtime, boolean wrap) { InputStream in = null; try { in = resource.getInputStream(); String name = resource.getName(); if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) { runtime.compileAndLoadFile(name, in, wrap); } else { name = CompiledScriptLoader.getFilenameFromPathAndName(resource.getPath(), name, resource.isAbsolute()); runtime.loadFile(name, new LoadServiceResourceInputStream(in), wrap); } } catch (IOException e) { throw runtime.newIOErrorFromException(e); } finally { try { in.close(); } catch (Exception ex) {} } }
public void load(Ruby runtime, boolean wrap) { InputStream in = null; try { in = resource.getInputStream(); String name = resource.getName(); if (runtime.getInstanceConfig().getCompileMode().shouldPrecompileAll()) { runtime.compileAndLoadFile(name, in, wrap); } else { name = CompiledScriptLoader.getFilenameFromPathAndName(resource.getPath(), name, resource.isAbsolute()); runtime.loadFile(name, new LoadServiceResourceInputStream(in), wrap); } } catch (IOException e) { throw runtime.newIOErrorFromException(e); } finally { try { in.close(); } catch (Exception ex) {} } }