Examples of OutputByteBuffer


Examples of ru.vassaev.core.io.OutputByteBuffer

        Date d = new Date(t);
        return d;
      }
    }
    if ("<b>".equals(type)) { // Stream
      OutputByteBuffer out = new OutputByteBuffer(1024*1024);
      try {
        byte[] r = ru.vassaev.core.util.Util.parseBase64(s);
        out.write(r);
        out.close();
        return out;
      } catch (SysException e1) {
        throw new SysException(e1);
      } catch (IOException e1) {
        throw new SysException(e1);
      }
    }
    if ("<u>".equals(type)) { // Unknown
      OutputByteBuffer out = new OutputByteBuffer(1024*1024);
      try {
        byte[] r = ru.vassaev.core.util.Util.parseBase64(s);
        //if (r.length > 8000)
        //  System.out.println("!!! LENGTH = " + r.length);
        out.write(r);
        out.close();
        return getObject(out);
      } catch (SysException e1) {
        throw new SysException(e1);
      } catch (IOException e1) {
        throw new SysException(e1);
      }
    }
    if ("<x>".equals(type)) { // Stream
      OutputByteBuffer out = new OutputByteBuffer(1024*1024);
      try {
        byte[] r = ru.vassaev.core.util.Util.parseBase64(s);
        out.write(r);
        out.close();
        Document d = XMLFileWaiter.getDocument(out.getIS(), "utf-8");
        return d.getDocumentElement();
      } catch (IOException e1) {
        throw new SysException(e1);
      }
    }
View Full Code Here

Examples of ru.vassaev.core.io.OutputByteBuffer

      Date v = (Date) o;
      e = e.append("<t>");
      e.append(Long.toHexString(v.getTime()));
    } else if (OutputByteBuffer.class.equals(c))
      try {
        OutputByteBuffer v = (OutputByteBuffer) o;
        InputStream is = v.getIS();
        OutputByteBuffer os = new OutputByteBuffer(
            (int) (v.getLength() * 4.0 / 3.0 + 5.0));
        ru.vassaev.core.util.Util.getBase64String(is, os);
        os.close();
        is.close();
        StringBuffer sb = new StringBuffer();
        is = os.getIS();
        int cnt;
        byte[] b = new byte[8 * 1024];
        while ((cnt = is.read(b)) != -1) {
          sb.append(new String(b, 0, cnt, "utf-8"));
        }
        is.close();
        e = e.append("<b>");
        e.append(sb);
      } catch (IOException e1) {
        throw new SysException(e1);
      }
    else if (o instanceof Element) try {
      Element val = (Element)o;
      OutputByteBuffer v = new OutputByteBuffer(1024*1024);
      XMLFileWaiter.putStream(val, v, "utf-8");
      v.close();
      InputStream is = v.getIS();
      InputStream ib;
      OutputStream ob;
//      if (v.getLength() > 10000) {
//        File f = new File("F:\\PROJECTS\\CENTER\\MA\\tmp\\" + System.currentTimeMillis() + ".xml");
//        f.createNewFile();
//        ob = new FileOutputStream(f);
//        ib = new FileInputStream(f);
//      } else
      {
        OutputByteBuffer os = new OutputByteBuffer(
          (int) (1024*1024));
        ob = os;
        ib = os.getIS();
      }
      ru.vassaev.core.util.Util.getBase64String(is, ob);
      ob.close();
      is.close();
      StringBuffer sb = new StringBuffer();
      int cnt;
      byte[] b = new byte[8 * 1024];
      while ((cnt = ib.read(b)) != -1) {
        sb.append(new String(b, 0, cnt, "utf-8"));
      }
      is.close();
      e = e.append("<x>");
      e.append(sb);
    } catch (IOException e1) {
      throw new SysException(e1);
    }
    else
      try {
        OutputByteBuffer v = getStream(o);
        InputStream is = v.getIS();
        OutputByteBuffer os = new OutputByteBuffer(
            (int) (v.getLength() * 4.0 / 3.0 + 5.0));
        ru.vassaev.core.util.Util.getBase64String(is, os);
        os.close();
        is.close();
        StringBuffer sb = new StringBuffer();
        is = os.getIS();
        int cnt;
        byte[] b = new byte[8 * 1024];
        while ((cnt = is.read(b)) != -1) {
          sb.append(new String(b, 0, cnt, "utf-8"));
        }
View Full Code Here

Examples of ru.vassaev.core.io.OutputByteBuffer

      }
    return e;
  }
 
  private static OutputByteBuffer getStream(Object obj) throws SysException {
    OutputByteBuffer obb = new OutputByteBuffer(1024*1024);
    ObjectOutputStream oos = null;
    try {
      oos = new ObjectOutputStream(obb);
      oos.writeObject(obj);
      return obb;
    } catch (IOException e) {
      throw new SysException(e);
    } finally {
      if (oos != null) {
        try {
          oos.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      try {
        obb.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
View Full Code Here

Examples of ru.vassaev.core.io.OutputByteBuffer

            cl = Strings.parseInteger(v.get(0));
          setPrms(cp, prms, "hdrs." + k, v.toString());
        }
        InputStream is = httpExchange.getRequestBody();
        Process tprc = executor.occupyOrNew();
        OutputByteBuffer obb = null;
        try {
          long read_wait = Strings.parseIntegerNvl(
              cntx.getPrmByFullName("read_wait"), 10000);// !!!
          TimeoutInputStream tis = new TimeoutInputStream(tprc);
          tis.setTimeout(read_wait);
          tis.setLimitRead(cl);
          tis.setCircleBufferSize(50);
          tis.startReadSource(is);
          obb = (cl <= 0) ? Process.getByteBuffer(8000, tis)
              : Process.getByteBuffer(8000, tis, cl);
        } catch (SysException e) {
          e.printStackTrace();
          tprc.interrupt();
          throw new SysRuntimeException(e);
        } finally {
          executor.free(tprc);
        }
        try {
          setPrms(cp, prms, "body", obb);
          if ("POST".equals(httpExchange.getRequestMethod())
              && ct != null
              && ct.indexOf("application/x-www-form-urlencoded") >= 0) {
            String enc;
            try {
              enc = cntx.getPrmNvl("request.encoding", "UTF-8");
              if (enc == null || enc.trim().length() == 0)
                enc = "UTF-8";
            } catch (SysException e2) {
              enc = "UTF-8";
            }
            StringBuffer sb = Strings.getStringBuffer(obb.getIS(),
                enc);
            setPrms(cp, prms, "postquery", sb);
            try {
              boolean parse_postquery = cntx.getPrmNvl(
                  "parse_postquery", false);
              if (parse_postquery) {
                String[] eqs = Strings.parseXVSLine(
                    sb.toString(), '/', '&');
                for (String eq : eqs) {
                  int j = eq.indexOf('=');
                  if (j >= 0)
                    setPrms(cp, prms,
                        "post." + eq.substring(0, j),
                        eq.substring(j + 1));
                }
              }
            } catch (SysException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
            }
          }
        } catch (IOException e) {
          e.printStackTrace();
          throw new SysRuntimeException(e);
        }

        String enc;
        try {
          enc = cntx.getPrmNvl("response.encoding", "UTF-8");
          if (enc == null || enc.trim().length() == 0)
            enc = "UTF-8";
        } catch (SysException e2) {
          enc = "UTF-8";
        }

        // if (https) {
        // HttpsServer srv = (HttpsServer)
        // httpExchange.getHttpContext().getServer();
        // SSLContext ssl = srv.getHttpsConfigurator().getSSLContext();
        // }
        NewTaskInfo nti = getChild();
        Context cntx_child = null;
        try {
          String grp_in = cntx.getPrmString("grp_in");
          if (grp_in == null)
            grp_in = "in";
          String grp_out = cntx.getPrmString("grp_out");
          if (grp_out == null)
            grp_out = "out";

          if (!Strings.parseBooleanNvl(
              cntx.getPrmString("save-in-body"), true)) {
            prms.remove("body");
          }
          cntx_child = nti.createAndReadyTask(cntx.ta, cntx,
              cntx.id_subject, grp_in, prms);
          Object res = null;
          if ((cntx_child == null) || (cntx_child.id_task <= 0)) {
            res = cntx_child
                .getPrmByFullName(((grp_out == null) || (grp_out
                    .length() == 0)) ? "body" : grp_out
                    + "/body");
            if (res == null) {
              Headers hd = httpExchange.getResponseHeaders();
              hd.put("Content-Type",
                  Arrays.asList("text/plain; charset=" + enc));
              httpExchange.sendResponseHeaders(503, 0);
              OutputStream w = httpExchange.getResponseBody();
              w.write("Обработчик не выбран".getBytes(enc));
              w.close();
              return;
            }
          } else {
            Process.currentProcess().regResourceName(
                cntx_child.id_task, "child.id");
            long wait = Strings.parseIntegerNvl(
                cntx.getPrmByFullName("wait"), 30000);// !!!
            cntx.log(false, "Start waiting (", wait, ")");
            cntx_child.ta.waitFinished(cntx_child.id_subject,
                cntx_child.id_task, wait);
            cntx.log(false, "End waiting");
            res = cntx_child
                .getPrmByFullName(((grp_out == null) || (grp_out
                    .length() == 0)) ? "body" : grp_out
                    + "/body");
          }

          if (res != null) {
            Map<String, Object> result = cntx_child
                .getGroupParams(grp_out);
            long l = 0;
            if (res instanceof FileInputStream) {
              is = (FileInputStream) res;
              l = ((FileInputStream) is).getChannel().size();
            } else if (res instanceof Element) {
              Element el = (Element) res;
              obb = new OutputByteBuffer(8000);
              XMLFileWaiter.putStream(el, obb, "utf-8");
              try {
                obb.close();
                l = obb.getLength();
              } catch (IOException e1) {
                e1.printStackTrace();
              }
              is = obb.getIS();
            } else if (res instanceof OutputByteBuffer) {
              is = ((OutputByteBuffer) res).getIS();
              l = ((OutputByteBuffer) res).getLength();
            } else if (res instanceof File) {
              File f = (File) res;
View Full Code Here

Examples of ru.vassaev.core.io.OutputByteBuffer

      }
      if (v instanceof OutputByteBuffer)
        v = ((OutputByteBuffer)v).getIS();
      else if (v instanceof File) {
        File f = (File)v;
        OutputByteBuffer obb = null;
        try {
          FileInputStream is = new FileInputStream(f.getCanonicalPath());
          obb = ru.vassaev.core.thread.Process.getByteBuffer(8000, is);
          is.close();
          obb.close();
          v = obb.getIS();
        } catch(IOException e) {
          throw new CalculateException(gl_name, e);
       
      }
      InputStream dh;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.