Package ru.vassaev.core.io

Examples of ru.vassaev.core.io.OutputByteBuffer


              stmtSTPO.setParam(st, "value_blob", blob, java.sql.Types.BLOB);
              stmtSTPO.setParam(st, "value_clob", null, java.sql.Types.CLOB);
              stmtSTPO.setParam(st, "len", blob.length(), java.sql.Types.BIGINT);
              is.close();
            } else if (val instanceof byte[]) {
              OutputByteBuffer buf = new OutputByteBuffer(((byte[]) val).length);
              buf.write((byte[])val);
              buf.close();
              InputStream is = buf.getIS();
              stmtSTPO.setParam(st, "value_clmn", "VALUE_BLOB", java.sql.Types.VARCHAR);
              stmtSTPO.setParam(st, "value", null, java.sql.Types.VARCHAR);
              Blob blob = tp.writeBlob(con, is);
              stmtSTPO.setParam(st, "value_blob", blob, java.sql.Types.BLOB);
              stmtSTPO.setParam(st, "value_clob", null, java.sql.Types.CLOB);
View Full Code Here


//*/
 
  public Object readBlob(Blob a) throws SQLException, IOException {
    // File x = ru.vassaev.core.thread.Process.getTempFile("GROUP", ".BLOB");
    // FileOutputStream wr = new FileOutputStream(x);
    OutputByteBuffer wr = Process
        .getByteBuffer(8000);
    tp.readBlob(a, wr);
    // Object result = new FileInputStream(x);
    // ru.vassaev.core.thread.Process.registerResource(result);
    return wr;
View Full Code Here

              if ("VALUE_BLOB".equalsIgnoreCase(k)) {
                Blob a = rs.getBlob(4);
                if (a != null) {
                  InputStream r = a.getBinaryStream();
                  //TODO Размер буфера надо сделать параметром
                  OutputByteBuffer wr = Process.getByteBuffer(8000);
                  byte[] buf = new byte[1024];
                  int l;
                  while ((l = r.read(buf)) > 0) {
                    wr.write(buf, 0, l);
                  }
                  wr.close();
                  r.close();
                  result = wr;
                  ru.vassaev.core.thread.Process.registerResource(wr);
                }
              } else if ("VALUE_CLOB".equalsIgnoreCase(k)) {
                Clob a = rs.getClob(3);
                if (a != null) {
                  Reader r = a.getCharacterStream();
                  OutputByteBuffer obb = Process.getByteBuffer(8000);// !!!
                  OutputStreamWriter wr = new OutputStreamWriter(obb, "utf-8");
                  char[] buf = new char[1024];
                  int l;
                  while ((l = r.read(buf)) > 0) {
                    wr.write(buf, 0, l);
View Full Code Here

            result = null;
            if ("VALUE_BLOB".equalsIgnoreCase(k)) {
              Blob a = rs.getBlob("VALUE_BLOB");
              if (a != null) {
                InputStream r = a.getBinaryStream();
                OutputByteBuffer wr = ru.vassaev.core.thread.Process
                    .getByteBuffer(8000);
                byte[] buf = new byte[1024];
                int l;
                while ((l = r.read(buf)) > 0) {
                  wr.write(buf, 0, l);
                }
                wr.close();
                r.close();
                result = wr;
                ru.vassaev.core.thread.Process.registerResource(result);
              }
              return result;
            }
            if ("VALUE_CLOB".equalsIgnoreCase(k)) {
              Clob a = rs.getClob("VALUE_CLOB");
              if (a != null) {
                Reader r = a.getCharacterStream();
                File x = ru.vassaev.core.thread.Process.getTempFile("GET",
                    ".CLOB");
                OutputStreamWriter wr = new OutputStreamWriter(
                    new FileOutputStream(x.getCanonicalPath()), "utf-8");
                char[] buf = new char[1024];
                int l;
                while ((l = r.read(buf)) > 0) {
                  wr.write(buf, 0, l);
                }
                wr.close();
                FileInputStream rd = new FileInputStream(x.getCanonicalPath());
                ru.vassaev.core.thread.Process.registerResource(rd);
                result = new InputStreamReader(rd, "utf-8");
              }
              return result;
View Full Code Here

        } catch (Throwable e1) {
          throw new SysException(e1);
        }
      if (Null.equ(o))
        return o;
      OutputByteBuffer obb = null;
      if (o instanceof Element) {
        String n = ((Element) o).getNodeName();
        if (skip_header_xml) {
          try {
            obb = Process.getByteBuffer(buf_size, ("<"+n).getBytes(encode));
          } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        } else
          obb = Process.getByteBuffer(buf_size);
        XMLFileWaiter.putStream((Element)o, obb, encode);
        try {
          obb.close();
          return obb;
        } catch (IOException e) {
          e.printStackTrace();
        }
      } else if (o instanceof OutputByteBuffer) {
        return o;
      } else if (o instanceof String) {
        obb = Process.getByteBuffer(buf_size);
        try {
          obb.write(((String) o).getBytes(encode));
          obb.close();
          return obb;
        } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else if (o instanceof StringBuffer) {
        obb = Process.getByteBuffer(buf_size);
        try {
          obb.write(((StringBuffer) o).toString().getBytes(encode));
          obb.close();
          return obb;
        } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else if (o instanceof File) {
        obb = Process.getByteBuffer(buf_size);
        try {
          FileInputStream is = new FileInputStream(((File)o).getCanonicalPath());
          try {
            obb.write(is);
            obb.close();
          } finally {
            is.close();
          }
          return obb;
        } catch (UnsupportedEncodingException e) {
View Full Code Here

            if (x == null)
              result.value.addLast(Null.NULL);
            else {
              if (x instanceof Blob) {
                InputStream r = ((Blob)x).getBinaryStream();
                OutputByteBuffer wr = ru.vassaev.core.thread.Process
                    .getByteBuffer(8000);
                byte[] buf = new byte[1024];
                int l;
                try {
                while ((l = r.read(buf)) > 0) {
                  wr.write(buf, 0, l);
                }
                wr.close();
                r.close();
                } catch (IOException e) {
                  throw new CalculateException(owner, e);
                }
                x = wr;
View Full Code Here

    Object body = cntx.getPrmByFullName(grp_in + "/body");
    if (body != null) {
      long length = -1;
      con.setDoOutput(true);
      InputStream is = null;
      OutputByteBuffer obb = null;
      if (body instanceof InputStream) {
        try {
          obb = Process.getByteBuffer(8000, (InputStream) body);
          is = obb.getIS();
        } catch (IOException e) {
          e.printStackTrace();
        }
      } else if (body instanceof OutputByteBuffer) {
        obb = (OutputByteBuffer)body;
        is = obb.getIS();
      } else if (body instanceof Element) {
        Element e = (Element) body;
        if (Strings.parseBooleanNvl(cntx.getPrmByFullName("skip-header-xml-body"), false)) {
          String n = e.getNodeName();
          try {
            obb = Process.getByteBuffer(8000, ("<"+n).getBytes(encode));
          } catch (UnsupportedEncodingException e1) {
            throw new TaskException(State.DONE_ERR, e1);
          }
        } else
          obb = Process.getByteBuffer(8000);
        XMLFileWaiter.putStream(e, obb, encode);
        try {
          obb.close();
          length = obb.getLength();
        } catch (IOException e1) {
          e1.printStackTrace();
        }
        is = obb.getIS();
      } else if (body instanceof Document) {
        Document e = (Document) body;
        if (Strings.parseBooleanNvl(cntx.getPrmByFullName("skip-header-xml-body"), false)) {
          String n = e.getDocumentElement().getNodeName();
          try {
            obb = Process.getByteBuffer(8000, ("<"+n).getBytes(encode));
          } catch (UnsupportedEncodingException e1) {
            throw new TaskException(State.DONE_ERR, e1);
          }
        } else
          obb = Process.getByteBuffer(8000);
        XMLFileWaiter.putStream(e, obb, encode);
        try {
          obb.close();
          length = obb.getLength();
        } catch (IOException e1) {
          e1.printStackTrace();
        }
        is = obb.getIS();
      } else {
        String r = Strings.getString(body);
        byte[] b = null;
        try {
          b = r.getBytes(encode);
          length = b.length;
        } catch (UnsupportedEncodingException e) {
          throw new TaskException(State.DONE_ERR, e);
        }
        is = new ByteArrayInputStream(b);
      }
      System.out.println("=============Request=============");
      if (length >= 0) {
        prc.regResourceName(obb, "query.body.length");
        String n = "Content-Length";
        String v = Long.toString(length);
        con.addRequestProperty(n, v);
        System.out.println(((n == null) ? "" : n + ":") + v);
      }
      for(Map.Entry<String, Object> i : headers.entrySet()) {
        String n = i.getKey();
        n = n.substring((grp_in + ".header/").length());
        Object v = i.getValue();
        if (v != null) {
          if (v instanceof Type)
            try {
              v = ((Type)v).getValue(cntx);
            } catch (CalculateException e) {
              v = null;
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          con.addRequestProperty(n, Strings.getString(v));
          System.out.println(((n == null) ? "" : n + ":") + Strings.getString(v));
        } else
          con.setRequestProperty(n, null);
      }

      {
        int ch = 0;
        try {
          OutputStream os = con.getOutputStream();
          while((ch = is.read()) != -1) {
            System.out.print((char)ch);
            os.write(ch);
          }
          os.write("\r\n".getBytes());
          System.out.print("\r\n");
        } catch (IOException e) {
          throw new TaskException(State.DONE_ERR, e);
        } finally {
          try {
            is.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    } else {
      for(Map.Entry<String, Object> i : headers.entrySet()) {
        String n = i.getKey();
        n = n.substring((grp_in + ".header/").length());
        Object v = i.getValue();
        if (v != null)
          con.addRequestProperty(n, Strings.getString(v));
        else
          con.setRequestProperty(n, null);
      }
    }

    System.out.println("=============Response=============");
    InputStream is = null;
    try {
      Map<String, List<String>> flds = con.getHeaderFields();
      for(Map.Entry<String, List<String>> fld : flds.entrySet()) {
        List<String> val = fld.getValue();
        StringBuffer sb = new StringBuffer();
        for(String v:val) { 
          sb.append(v).append("\r\n");
        }
        if (sb.length() > 0)
          sb.setLength(sb.length() - 2);
        String n = fld.getKey();
        System.out.println(((n == null)? "" : n + ":") + sb.toString());
        cntx.ta.setParamObject(cntx.id_task, grp_out+".header/" + fld.getKey(), sb.toString());
      }
      is = con.getInputStream();
      int l = con.getContentLength();
      int l_b = l >= 0 ? (l < 1024*1024 ? l : 1024*1024) : 8000;
      OutputByteBuffer obb = new OutputByteBuffer(l_b);
      obb.write(is);
      obb.close();
      prc.regResourceName(obb, "msg.body");
      if (Strings.parseBooleanNvl(cntx.getPrmString("save-out-body"), true)) {
        String fn = cntx.getPrmString("filename");
        if (fn == null)
          cntx.ta.setParamObject(cntx.id_task, grp_out + "/body", obb);
        else {
          File f = new File(fn);
          FileOutputStream fos = new FileOutputStream(f.getCanonicalPath());
          InputStream isb = obb.getIS();
          try {
            byte[] buf = new byte[l_b];
            int lr = 0;
            while ((lr = isb.read(buf)) > 0)
              fos.write(buf, 0, lr);
View Full Code Here

 
  private Object zip(Object v) throws IOException {
      if (v instanceof Document) {
        Document d = (Document)v;
        Element e = d.getDocumentElement();
        OutputByteBuffer res = Process.getByteBuffer(sizeCache);
        OutputStream os = new java.util.zip.GZIPOutputStream(res, sizeBuffer);     
        XMLFileWaiter.putStream(e, os, "utf-8");
        os.close();
        return res;
      } else if (v instanceof Element) {
        Element e = (Element)v;
        OutputByteBuffer res = Process.getByteBuffer(sizeCache);
        OutputStream os = new java.util.zip.GZIPOutputStream(res, sizeBuffer);
        XMLFileWaiter.putStream(e, os, "utf-8");
        os.close();
        return res;
      } else if (v instanceof InputStream) {
        InputStream is = (InputStream) v;
        OutputByteBuffer res = Process.getByteBuffer(sizeCache);
        GZIPOutputStream os = new GZIPOutputStream(res, sizeBuffer);
        Bytes.copyStream(is, os, res.getBufferSize());
        os.close();
        return res;
      } else if (v instanceof OutputByteBuffer) {
        InputStream is = ((OutputByteBuffer) v).getIS();
        OutputByteBuffer res = Process.getByteBuffer(sizeCache);
        GZIPOutputStream os = new GZIPOutputStream(res, sizeBuffer);
        Bytes.copyStream(is, os, res.getBufferSize());
        os.close();
        return res;
      } else if (v instanceof String || v instanceof StringBuffer) {
        String r = v.toString();
        ByteArrayInputStream is = new ByteArrayInputStream(r.getBytes("utf-8"));
        OutputByteBuffer res = Process.getByteBuffer(sizeCache);
        GZIPOutputStream os = new GZIPOutputStream(res, sizeBuffer);
        Bytes.copyStream(is, os, res.getBufferSize());
        os.close();
        return res;
      } else if (v instanceof File) {
        File r = (File)v;
        FileInputStream is = new FileInputStream(r.getCanonicalPath());
        OutputByteBuffer res = null;
        try {
          res = Process.getByteBuffer(sizeCache);
          GZIPOutputStream os = new GZIPOutputStream(res, sizeBuffer);
          Bytes.copyStream(is, os, res.getBufferSize());
          os.close();
        } finally {
          is.close();
        }
        return res;
      } else if (v instanceof Record) {
        String r = Strings.getString(((Record) v).value.get(0));
        if (r == null)
          return null;
        ByteArrayInputStream is = new ByteArrayInputStream(r.getBytes("utf-8"));
        OutputByteBuffer res = Process.getByteBuffer(sizeCache);
        GZIPOutputStream os = new GZIPOutputStream(res, sizeBuffer);
        Bytes.copyStream(is, os, res.getBufferSize());
        os.close();
        return res;
      } else
        throw new SysRuntimeException("The source's type isn't supported:"
                + v.getClass().getCanonicalName());
View Full Code Here

  }

  private Object unzip(Object v) throws IOException, ZipException {
    if (v instanceof InputStream) {
      InputStream is = new GZIPInputStream((InputStream) v, sizeBuffer);
      OutputByteBuffer res = Process.getByteBuffer(sizeCache);
      Bytes.copyStream(is, res, res.getBufferSize());
      res.close();
      is.close();
      return res;
    } else if (v instanceof File) {
      FileInputStream fis = new FileInputStream(((File) v).getCanonicalPath());
      try {
        InputStream is = new GZIPInputStream(fis, sizeBuffer);
        OutputByteBuffer res = Process.getByteBuffer(sizeCache);
        Bytes.copyStream(is, res, res.getBufferSize());
        res.close();
        is.close();
        return res;
      } finally {
        fis.close();
      }
    } else if (v instanceof OutputByteBuffer) {
      InputStream is = new GZIPInputStream(((OutputByteBuffer) v).getIS(), sizeBuffer);
      OutputByteBuffer res = Process.getByteBuffer(sizeCache);
      Bytes.copyStream(is, res, res.getBufferSize());
      res.close();
      is.close();
      return res;
    } else
      throw new SysRuntimeException("The source's type isn't supported:"
              + v.getClass().getCanonicalName());
View Full Code Here

          setPrms(cp, prms, "hdrs." + k, v.toString());
        }

        InputStream is = httpExchange.getRequestBody();
        try {
          OutputByteBuffer obb = Process.getByteBuffer(8000, is);
          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);

            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 (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";
        }
        try {
          String grp_in = cntx.getPrmNvl("grp_in", "in");
          String grp_out = cntx.getPrmNvl("grp_out", "out");

          setPrms(cp, prms, "out.result", cntx.getPrmByFullName("update"));
         
          Object res = cntx.getPrmByFullName(cntx.getFullName(grp_out, "body"));
          if (res != null) {
            long l = 0;
            if (res instanceof FileInputStream) {
              FileInputStream f = (FileInputStream) res;
              is = f;
              l = f.getChannel().size();
            } else if (res instanceof Element) {
              Element el = (Element)res;
              OutputByteBuffer 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

TOP

Related Classes of ru.vassaev.core.io.OutputByteBuffer

Copyright © 2018 www.massapicom. 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.