Пример #1
0
 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
 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;
 }