コード例 #1
0
ファイル: LibRt.java プロジェクト: yamila87/rt_src
 public static int pipe_stream(InputStream is, OutputStream os, boolean wantsKeepOpen)
     throws IOException { // U: copia de un stream al otro
   int cnt = 0;
   int n;
   byte[] buffer = new byte[BUFF_SZ];
   while ((n = is.read(buffer)) > -1) {
     cnt += n;
     os.write(buffer, 0, n);
   }
   if (!wantsKeepOpen) {
     is.close();
     os.close();
   }
   return cnt;
 }
コード例 #2
0
 @Override
 public CompiledScript compile(Reader script) throws ScriptException {
   try {
     InputStream is = new Utf8Encoder(script);
     try {
       final Globals g = context.globals;
       final LuaFunction f = g.load(script, "script").checkfunction();
       return new LuajCompiledScript(f, g);
     } catch (LuaError lee) {
       throw new ScriptException(lee.getMessage());
     } finally {
       is.close();
     }
   } catch (Exception e) {
     throw new ScriptException("eval threw " + e.toString());
   }
 }
コード例 #3
0
ファイル: LibRt.java プロジェクト: yamila87/rt_src
 public static String get_stream(InputStream is, String encoding) throws IOException {
   if (encoding == null) {
     encoding = CfgEncodingDflt;
   }
   byte[] buffer = new byte[BUFF_SZ];
   StringBuilder out = new StringBuilder();
   logm("DBG", 9, "STREAM GET", is + "");
   for (; ; ) {
     int rsz = is.read(buffer, 0, buffer.length);
     logm("DBG", 9, "STREAM GET READ", rsz);
     if (rsz < 0) break;
     out.append(new String(buffer, 0, rsz, encoding));
   }
   String s = out.toString();
   logm("DBG", 9, "STREAM GET RESULT", s);
   return s;
 }