Exemplo n.º 1
0
  private void writeNumber(Number obj, Buffer buf) {
    long value = obj.longValue();

    if (value >= -32 && value <= Byte.MAX_VALUE) {
      // Integer
      if (T) Log.trace("writing Integer value: " + value);
      buf.writeI8((byte) value);
    } else if (value >= Byte.MIN_VALUE && value < -32) {
      if (T) Log.trace("writing I8 value: " + value);
      buf.writeI8(TYPE_I8);
      buf.writeI8((byte) value);
    } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
      // I16
      if (T) Log.trace("writing I16 value: " + value);
      buf.writeI8(TYPE_I16);
      buf.writeI16((short) value);
    } else if (value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE) {
      // I32
      if (T) Log.trace("writing I32 value: " + value);
      buf.writeI8(TYPE_I32);
      buf.writeI32((int) value);
    } else {
      // I64
      if (T) Log.trace("writing I64 value: " + value);
      buf.writeI8(TYPE_I64);
      buf.writeI64(value);
    }
  }
Exemplo n.º 2
0
 private void writeBoolean(Boolean obj, Buffer buf) {
   if (obj.booleanValue()) {
     // true
     if (T) Log.trace("writing true");
     buf.writeI8(TYPE_TRUE);
   } else {
     // false
     if (T) Log.trace("writing false");
     buf.writeI8(TYPE_FALSE);
   }
 }
Exemplo n.º 3
0
  private void servletEnv() {
    if (!log.isDebugEnabled()) return;

    try {
      java.net.URL url = servletContext.getResource("/");
      log.trace("Joseki base directory: " + url);
    } catch (Exception ex) {
    }

    if (servletConfig != null) {
      String tmp = servletConfig.getServletName();
      log.trace("Servlet = " + (tmp != null ? tmp : "<null>"));
      @SuppressWarnings("unchecked")
      Enumeration<String> en = servletConfig.getInitParameterNames();

      for (; en.hasMoreElements(); ) {
        String s = en.nextElement();
        log.trace("Servlet parameter: " + s + " = " + servletConfig.getInitParameter(s));
      }
    }
    if (servletContext != null) {
      // Name of webapp
      String tmp = servletContext.getServletContextName();
      // msg(Level.FINE, "Webapp = " + (tmp != null ? tmp : "<null>"));
      log.debug("Webapp = " + (tmp != null ? tmp : "<null>"));

      // NB This servlet may not have been loaded as part of a web app
      @SuppressWarnings("unchecked")
      Enumeration<String> en = servletContext.getInitParameterNames();
      for (; en.hasMoreElements(); ) {
        String s = en.nextElement();
        log.debug("Webapp parameter: " + s + " = " + servletContext.getInitParameter(s));
      }
    }
    /*
    for ( Enumeration enum = servletContext.getAttributeNames() ;  enum.hasMoreElements() ; )
    {
        String s = (String)enum.nextElement() ;
        logger.log(LEVEL, "Webapp attribute: "+s+" = "+context.getAttribute(s)) ;
    }
     */
  }
Exemplo n.º 4
0
  private void writeList(List obj, Buffer buf) {
    if (T) Log.trace("writing List value: " + obj);

    int num = obj.size();
    if (num < MASK_LENGTH_1) {
      buf.writeI8(TYPE_LIST | (byte) num);
    } else {
      buf.writeI8(TYPE_LIST | MASK_LENGTH_1);
      buf.writeI32(num);
    }

    for (int i = 0; i < num; i++) {
      write(obj.get(i), buf);
    }
  }
Exemplo n.º 5
0
  private void writeMap(Map obj, Buffer buf) {
    if (T) Log.trace("writing Map value: " + obj);

    int num = obj.size();
    if (num < MASK_LENGTH_2) {
      buf.writeI8(TYPE_MAP | (byte) num);
    } else {
      buf.writeI8(TYPE_MAP | MASK_LENGTH_2);
      buf.writeI32(num);
    }

    for (Iterator iter = obj.keySet().iterator(); iter.hasNext(); ) {
      Object k = iter.next();
      write(k, buf);
      write(obj.get(k), buf);
    }
  }
Exemplo n.º 6
0
  private void writeString(String obj, Buffer buf) {
    try {
      if (T) Log.trace("writing String value: " + obj);

      byte[] str = obj.getBytes("UTF8");
      int strlen = str.length;

      if (strlen < MASK_LENGTH_1) {
        // length is encoded with type.
        buf.writeI8(TYPE_STRING | (byte) str.length);
      } else {
        buf.writeI8(TYPE_STRING | MASK_LENGTH_1);
        buf.writeI32(strlen);
      }
      buf.writeBytes(str, 0, str.length);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
      throw new RemoteException("utf8 not supported");
    }
  }
Exemplo n.º 7
0
 private void writeDouble(Double obj, Buffer buf) {
   if (T) Log.trace("writing F64 value: " + obj);
   buf.writeI8(TYPE_F64);
   buf.writeF64(obj.doubleValue());
 }
Exemplo n.º 8
0
 private void writeFloat(Float obj, Buffer buf) {
   if (T) Log.trace("writing F32 value: " + obj);
   buf.writeI8(TYPE_F32);
   buf.writeF32(obj.floatValue());
 }