コード例 #1
0
 public void destroy() {
   try {
     conn.close();
   } catch (Exception e) {
     RpcCommunicator.instance().getLogger().error(e.getMessage());
   }
 }
コード例 #2
0
 public void onError_oneway(String errcode, String errmsg, HashMap<String, String> props)
     throws RpcException {
   boolean r_1 = false;
   RpcMessage m_2 = new RpcMessage(RpcMessage.CALL | RpcMessage.ONEWAY);
   m_2.ifidx = 0;
   m_2.opidx = 2;
   m_2.paramsize = 2;
   m_2.extra.setProperties(props);
   try {
     ByteArrayOutputStream bos_3 = new ByteArrayOutputStream();
     DataOutputStream dos_4 = new DataOutputStream(bos_3);
     byte[] sb_5 = errcode.getBytes();
     dos_4.writeInt(sb_5.length);
     dos_4.write(sb_5, 0, sb_5.length);
     byte[] sb_6 = errmsg.getBytes();
     dos_4.writeInt(sb_6.length);
     dos_4.write(sb_6, 0, sb_6.length);
     m_2.paramstream = bos_3.toByteArray();
     m_2.prx = this;
   } catch (Exception e) {
     throw new RpcException(RpcConsts.RPCERROR_DATADIRTY, e.toString());
   }
   r_1 = this.conn.sendMessage(m_2);
   if (!r_1) {
     throw new RpcException(RpcConsts.RPCERROR_SENDFAILED);
   }
 }
コード例 #3
0
 public void onError_async(
     String errcode,
     String errmsg,
     ITerminal_AsyncCallBack async,
     HashMap<String, String> props,
     Object cookie)
     throws RpcException {
   boolean r_7 = false;
   RpcMessage m_8 = new RpcMessage(RpcMessage.CALL | RpcMessage.ASYNC);
   m_8.ifidx = 0;
   m_8.opidx = 2;
   m_8.paramsize = 2;
   m_8.extra.setProperties(props);
   m_8.cookie = cookie;
   try {
     ByteArrayOutputStream bos_9 = new ByteArrayOutputStream();
     DataOutputStream dos_10 = new DataOutputStream(bos_9);
     byte[] sb_11 = errcode.getBytes();
     dos_10.writeInt(sb_11.length);
     dos_10.write(sb_11, 0, sb_11.length);
     byte[] sb_12 = errmsg.getBytes();
     dos_10.writeInt(sb_12.length);
     dos_10.write(sb_12, 0, sb_12.length);
     m_8.paramstream = bos_9.toByteArray();
     m_8.prx = this;
     m_8.async = async;
   } catch (Exception e) {
     throw new RpcException(RpcConsts.RPCERROR_DATADIRTY, e.toString());
   }
   r_7 = this.conn.sendMessage(m_8);
   if (!r_7) {
     throw new RpcException(RpcConsts.RPCERROR_SENDFAILED);
   }
 }
コード例 #4
0
 public void onSystemNotification_async(
     Notification_t notification,
     ITerminal_AsyncCallBack async,
     HashMap<String, String> props,
     Object cookie)
     throws RpcException {
   boolean r_5 = false;
   RpcMessage m_6 = new RpcMessage(RpcMessage.CALL | RpcMessage.ASYNC);
   m_6.ifidx = 0;
   m_6.opidx = 3;
   m_6.paramsize = 1;
   m_6.extra.setProperties(props);
   m_6.cookie = cookie;
   try {
     ByteArrayOutputStream bos_7 = new ByteArrayOutputStream();
     DataOutputStream dos_8 = new DataOutputStream(bos_7);
     notification.marshall(dos_8);
     m_6.paramstream = bos_7.toByteArray();
     m_6.prx = this;
     m_6.async = async;
   } catch (Exception e) {
     throw new RpcException(RpcConsts.RPCERROR_DATADIRTY, e.toString());
   }
   r_5 = this.conn.sendMessage(m_6);
   if (!r_5) {
     throw new RpcException(RpcConsts.RPCERROR_SENDFAILED);
   }
 }
コード例 #5
0
 public String readString(TiffIFDEntry entry) {
   try {
     if (null != entry && entry.type == Tiff.Type.ASCII) {
       return new String(this.readBytes(entry));
     }
   } catch (Exception e) {
     Logging.logger().severe(e.getMessage());
   }
   return null;
 }
コード例 #6
0
ファイル: UploadFile.java プロジェクト: venci78/maven
  public static void main(String args[]) {
    Connection c = null;
    PreparedStatement stmt = null;
    try {
      Class.forName("org.postgresql.Driver");
      c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "pdv", "pdv");
      System.out.println("Opened database successfully");
      List<String> results = new ArrayList<String>();
      File dir = new File("D:/jboss/eclipse/workspace/LTF");
      Iterator<File> files =
          FileUtils.iterateFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
      StopWatch timerAll = new StopWatch();
      timerAll.start();
      while (files.hasNext()) {
        File file = (File) files.next();
        if (file.isFile()) {
          StopWatch timeForAFile = new StopWatch();
          timeForAFile.start();
          String toDB = encodeFileToBase64Binary(file);
          String sql =
              "INSERT INTO test (file_id,file_name,file_data,file_date) VALUES (nextval('test_file_id_seq'),?,?,?)";
          stmt = c.prepareStatement(sql);

          stmt.setString(1, file.getAbsolutePath());
          stmt.setString(2, toDB);
          stmt.setDate(3, new java.sql.Date(Calendar.getInstance().getTimeInMillis()));
          stmt.executeUpdate();
          timeForAFile.stop();
          System.out.println(timeForAFile.toString());
        }
      }
      timerAll.stop();
      System.out.println("=================================================");
      System.out.println(timerAll.toString());

      stmt.close();
      /*
       * Statement statement = null; statement = c.createStatement();
       * ResultSet rs = statement.executeQuery(
       * "select file_data from test limit 1"); while (rs.next()) { String
       * encoded = rs.getString("file_data"); byte[] decoded =
       * Base64.getDecoder().decode(encoded); FileOutputStream fos = new
       * FileOutputStream("c:/temp/2.jpg"); fos.write(decoded);
       * fos.close(); }
       */

      c.close();
    } catch (Exception e) {
      System.err.println(e.getClass().getName() + ": " + e.getMessage());
      System.exit(0);
    }
    System.out.println("Table created successfully");
  }
コード例 #7
0
ファイル: Overlord.java プロジェクト: rf/bitster
  /** Registers a SelectableQueue */
  public boolean register(SelectableQueue sq, Communicator communicator) {
    try {
      // Register the new pipe with the queue. It will write a byte to this
      // pipe when the queue is hot, and it will offer its communicator to our
      // queue.
      sq.register(this, communicator);

      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
コード例 #8
0
ファイル: PktExitResp.java プロジェクト: silentjesse/dir_work
 public boolean fromBytes(byte[] b, int off, int len) {
   try {
     if (len != PKT_LEN) return false;
     ByteBuffer bb = ByteBuffer.wrap(b, off, len);
     bb.order(SMSPApp.smspcfg.bo);
     pktLen = bb.getInt();
     reqId = bb.getInt();
     seqId = bb.getInt();
     if (pktLen != PKT_LEN) return false;
     if (reqId != REQ_ID) return false;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
   return true;
 }
コード例 #9
0
ファイル: TJUnitTest.java プロジェクト: sbesson/bioformats
 public static void main(String argv[]) {
   try {
     String testName = "javatest";
     boolean doyuv = false;
     for (int i = 0; i < argv.length; i++) {
       if (argv[i].equalsIgnoreCase("-yuv")) doyuv = true;
       if (argv[i].substring(0, 1).equalsIgnoreCase("-h") || argv[i].equalsIgnoreCase("-?"))
         usage();
       if (argv[i].equalsIgnoreCase("-bi")) {
         bi = true;
         testName = "javabitest";
       }
     }
     if (doyuv) yuv = YUVENCODE;
     doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_444, testName);
     doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_444, testName);
     doTest(41, 35, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_422, testName);
     doTest(35, 39, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_422, testName);
     doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_420, testName);
     doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_420, testName);
     doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_440, testName);
     doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_440, testName);
     doTest(35, 39, bi ? onlyGrayBI : onlyGray, TJ.SAMP_GRAY, testName);
     doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_GRAY, testName);
     doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_GRAY, testName);
     if (!doyuv && !bi) bufSizeTest();
     if (doyuv && !bi) {
       yuv = YUVDECODE;
       doTest(48, 48, onlyRGB, TJ.SAMP_444, "javatest_yuv0");
       doTest(35, 39, onlyRGB, TJ.SAMP_444, "javatest_yuv1");
       doTest(48, 48, onlyRGB, TJ.SAMP_422, "javatest_yuv0");
       doTest(39, 41, onlyRGB, TJ.SAMP_422, "javatest_yuv1");
       doTest(48, 48, onlyRGB, TJ.SAMP_420, "javatest_yuv0");
       doTest(41, 35, onlyRGB, TJ.SAMP_420, "javatest_yuv1");
       doTest(48, 48, onlyRGB, TJ.SAMP_440, "javatest_yuv0");
       doTest(35, 39, onlyRGB, TJ.SAMP_440, "javatest_yuv1");
       doTest(48, 48, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv0");
       doTest(35, 39, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv1");
       doTest(48, 48, onlyGray, TJ.SAMP_GRAY, "javatest_yuv0");
       doTest(39, 41, onlyGray, TJ.SAMP_GRAY, "javatest_yuv1");
     }
   } catch (Exception e) {
     e.printStackTrace();
     exitStatus = -1;
   }
   System.exit(exitStatus);
 }
コード例 #10
0
ファイル: Error_t.java プロジェクト: adoggie/Koala-Messaging
 public boolean unmarshall(ByteBuffer d) {
   boolean r = false;
   try {
     byte v_1 = d.get();
     this.succ = v_1 == 0 ? false : true;
     this.code = d.getInt();
     int v_2 = d.getInt();
     byte[] _sb_3 = new byte[v_2];
     d.get(_sb_3);
     this.msg = new String(_sb_3);
   } catch (Exception e) {
     tce.RpcCommunicator.instance().getLogger().error(e.getMessage());
     r = false;
     return r;
   }
   return true;
 }
コード例 #11
0
 void show() { // 打印任务执行的结果
   String result;
   if (connectFinish != 0) result = Long.toString(connectFinish - connectStart) + "ms";
   else if (failure != null) result = failure.toString();
   else result = "Timed out";
   System.out.println(address + " : " + result);
   shown = true;
 }
コード例 #12
0
 public void run() {
   while (!shutdown) {
     try {
       registerTargets();
       if (selector.select() > 0) {
         processSelectedKeys();
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   try {
     selector.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 @FXML
 private void Ok_click(ActionEvent event) {
   logger.entry();
   LogEntry log = new LogEntry("6.16", "Local Delete Object Instance service");
   try {
     ObjectInstanceHandle instanceHandle =
         rtiAmb
             .getObjectInstanceHandleFactory()
             .decode(
                 ByteBuffer.allocate(4)
                     .putInt(Integer.parseInt(ObjectInstanceDesignator.getText()))
                     .array(),
                 0);
     log.getSuppliedArguments()
         .add(
             new ClassValuePair(
                 "Object instance designator",
                 ObjectInstanceHandle.class,
                 instanceHandle.toString()));
     rtiAmb.localDeleteObjectInstance(instanceHandle);
     log.setDescription("Local Object instance deleted successfully");
     log.setLogType(LogEntryType.REQUEST);
   } catch (FederateNotExecutionMember
       | NotConnected
       | NumberFormatException
       | CouldNotDecode
       | RTIinternalError
       | OwnershipAcquisitionPending
       | FederateOwnsAttributes
       | ObjectInstanceNotKnown
       | SaveInProgress
       | RestoreInProgress ex) {
     log.setException(ex);
     log.setLogType(LogEntryType.ERROR);
     logger.log(Level.ERROR, ex.getMessage(), ex);
   } catch (Exception ex) {
     log.setException(ex);
     log.setLogType(LogEntryType.FATAL);
     logger.log(Level.FATAL, ex.getMessage(), ex);
   }
   logEntries.add(log);
   ((Stage) OkButton.getScene().getWindow()).close();
   logger.exit();
 }
コード例 #14
0
  private void readPalette() {
    RandomAccessFile rIn = null;
    ByteBuffer buf = null;
    int i;
    try {
      if (paletteFile != null) {
        // see if the file exists, if not, set it to the default palette.
        File file = new File(paletteFile);

        numPaletteEntries = (int) (file.length() / 4);

        buf = ByteBuffer.allocate(numPaletteEntries * 4);

        rIn = new RandomAccessFile(paletteFile, "r");

        FileChannel inChannel = rIn.getChannel();

        inChannel.position(0);
        inChannel.read(buf);

        // Check the byte order.
        buf.order(ByteOrder.LITTLE_ENDIAN);

        buf.rewind();
        IntBuffer ib = buf.asIntBuffer();
        paletteData = new int[numPaletteEntries];
        ib.get(paletteData);
        ib = null;
      }

    } catch (Exception e) {
      System.err.println("Caught exception: " + e.toString());
      System.err.println(e.getStackTrace());
    } finally {
      if (rIn != null) {
        try {
          rIn.close();
        } catch (Exception e) {
        }
      }
    }
  }
コード例 #15
0
 // timeout - msec ,  0 means waiting infinitely
 public void onError(String errcode, String errmsg, int timeout, HashMap<String, String> props)
     throws RpcException {
   boolean r_1 = false;
   RpcMessage m_2 = new RpcMessage(RpcMessage.CALL);
   m_2.ifidx = 0;
   m_2.opidx = 2;
   m_2.paramsize = 2;
   m_2.extra.setProperties(props);
   try {
     ByteArrayOutputStream bos_3 = new ByteArrayOutputStream();
     DataOutputStream dos_4 = new DataOutputStream(bos_3);
     byte[] sb_5 = errcode.getBytes();
     dos_4.writeInt(sb_5.length);
     dos_4.write(sb_5, 0, sb_5.length);
     byte[] sb_6 = errmsg.getBytes();
     dos_4.writeInt(sb_6.length);
     dos_4.write(sb_6, 0, sb_6.length);
     m_2.paramstream = bos_3.toByteArray();
     m_2.prx = this;
   } catch (Exception e) {
     throw new RpcException(RpcConsts.RPCERROR_DATADIRTY, e.toString());
   }
   synchronized (m_2) {
     r_1 = this.conn.sendMessage(m_2);
     if (!r_1) {
       throw new RpcException(RpcConsts.RPCERROR_SENDFAILED);
     }
     try {
       if (timeout > 0) m_2.wait(timeout);
       else m_2.wait();
     } catch (Exception e) {
       throw new RpcException(RpcConsts.RPCERROR_INTERNAL_EXCEPTION, e.getMessage());
     }
   }
   if (m_2.errcode != RpcConsts.RPCERROR_SUCC) {
     throw new RpcException(m_2.errcode);
   }
   if (m_2.result == null) {
     throw new RpcException(RpcConsts.RPCERROR_TIMEOUT);
   }
 }
コード例 #16
0
ファイル: Teste.java プロジェクト: mhadaniya/3cop005
  /**
   * Reads an image from an archived file and return it as ByteBuffer object.
   *
   * @author Mike Butler, Kiet Le
   */
  private ByteBuffer readImage(String filename, Dimension dim) {
    if (dim == null) dim = new Dimension(0, 0);
    ByteBuffer bytes = null;
    try {
      DataInputStream dis =
          new DataInputStream(getClass().getClassLoader().getResourceAsStream(filename));
      dim.width = dis.readInt();
      dim.height = dis.readInt();
      System.out.println("Creating buffer, width: " + dim.width + " height: " + dim.height);
      // byte[] buf = new byte[3 * dim.height * dim.width];
      bytes = BufferUtil.newByteBuffer(3 * dim.width * dim.height);
      for (int i = 0; i < bytes.capacity(); i++) {
        bytes.put(dis.readByte());
      }
      dis.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
    bytes.rewind();
    return bytes;
  }
コード例 #17
0
 public void onSimpleText_oneway(SimpleText_t text, HashMap<String, String> props)
     throws RpcException {
   boolean r_1 = false;
   RpcMessage m_2 = new RpcMessage(RpcMessage.CALL | RpcMessage.ONEWAY);
   m_2.ifidx = 0;
   m_2.opidx = 0;
   m_2.paramsize = 1;
   m_2.extra.setProperties(props);
   try {
     ByteArrayOutputStream bos_3 = new ByteArrayOutputStream();
     DataOutputStream dos_4 = new DataOutputStream(bos_3);
     text.marshall(dos_4);
     m_2.paramstream = bos_3.toByteArray();
     m_2.prx = this;
   } catch (Exception e) {
     throw new RpcException(RpcConsts.RPCERROR_DATADIRTY, e.toString());
   }
   r_1 = this.conn.sendMessage(m_2);
   if (!r_1) {
     throw new RpcException(RpcConsts.RPCERROR_SENDFAILED);
   }
 }
コード例 #18
0
 // timeout - msec ,  0 means waiting infinitely
 public void onSimpleText(SimpleText_t text, int timeout, HashMap<String, String> props)
     throws RpcException {
   boolean r_1 = false;
   RpcMessage m_2 = new RpcMessage(RpcMessage.CALL);
   m_2.ifidx = 0;
   m_2.opidx = 0;
   m_2.paramsize = 1;
   m_2.extra.setProperties(props);
   try {
     ByteArrayOutputStream bos_3 = new ByteArrayOutputStream();
     DataOutputStream dos_4 = new DataOutputStream(bos_3);
     text.marshall(dos_4);
     m_2.paramstream = bos_3.toByteArray();
     m_2.prx = this;
   } catch (Exception e) {
     throw new RpcException(RpcConsts.RPCERROR_DATADIRTY, e.toString());
   }
   synchronized (m_2) {
     r_1 = this.conn.sendMessage(m_2);
     if (!r_1) {
       throw new RpcException(RpcConsts.RPCERROR_SENDFAILED);
     }
     try {
       if (timeout > 0) m_2.wait(timeout);
       else m_2.wait();
     } catch (Exception e) {
       throw new RpcException(RpcConsts.RPCERROR_INTERNAL_EXCEPTION, e.getMessage());
     }
   }
   if (m_2.errcode != RpcConsts.RPCERROR_SUCC) {
     throw new RpcException(m_2.errcode);
   }
   if (m_2.result == null) {
     throw new RpcException(RpcConsts.RPCERROR_TIMEOUT);
   }
 }
コード例 #19
0
ファイル: Mesh.java プロジェクト: DuncanCragg/NetMash
  @SuppressWarnings("unchecked")
  public Mesh(LinkedHashMap mesh, User user) {

    this.mesh = mesh;
    this.user = user;

    try {
      title = getStringFromHash(mesh, "title", "Some Object");

      ArrayList<Float> vs = new ArrayList<Float>(256);
      ArrayList<Float> ns = new ArrayList<Float>(256);
      ArrayList<Float> tp = new ArrayList<Float>(256);

      LinkedList verts = getListFromHash(mesh, "vertices");
      for (Object vert : verts) {
        vs.add(getFloatFromList(vert, 0, 0f));
        vs.add(getFloatFromList(vert, 1, 0f));
        vs.add(getFloatFromList(vert, 2, 0f));
      }
      LinkedList norms = getListFromHash(mesh, "normals");
      for (Object norm : norms) {
        ns.add(getFloatFromList(norm, 0, 0f));
        ns.add(getFloatFromList(norm, 1, 0f));
        ns.add(getFloatFromList(norm, 2, 0f));
      }
      LinkedList texts = getListFromHash(mesh, "texturepoints");
      for (Object text : texts) {
        tp.add(getFloatFromList(text, 0, 0f));
        tp.add(getFloatFromList(text, 1, 0f));
      }
      ArrayList<Float> vnt = new ArrayList<Float>(1024);
      ArrayList<Short> ind = new ArrayList<Short>(1024);
      short index = 0;
      LinkedList faces = getListFromHash(mesh, "faces");
      for (Object face : faces) {
        for (int i = 0; i < 3; i++) {
          String f = getStringFromList(face, i, "1/1/2");
          StringTokenizer st = new StringTokenizer(f, "/");
          int fv = Integer.parseInt(st.nextToken()) - 1;
          int ft = Integer.parseInt(st.nextToken()) - 1;
          int fn = Integer.parseInt(st.nextToken()) - 1;

          vnt.add(vs.get(fv * 3));
          vnt.add(vs.get(fv * 3 + 1));
          vnt.add(vs.get(fv * 3 + 2));

          vnt.add(ns.get(fn * 3));
          vnt.add(ns.get(fn * 3 + 1));
          vnt.add(ns.get(fn * 3 + 2));

          vnt.add(tp.get(ft * 2));
          vnt.add(tp.get(ft * 2 + 1));

          ind.add(index++);
        }
      }
      vnt.trimToSize();
      float[] va = new float[vnt.size()];
      for (int i = 0; i < vnt.size(); i++) va[i] = vnt.get(i);

      ind.trimToSize();
      short[] ia = new short[ind.size()];
      for (int i = 0; i < ind.size(); i++) ia[i] = ind.get(i);

      vb = ByteBuffer.allocateDirect(va.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
      vb.put(va).position(0);

      ib = ByteBuffer.allocateDirect(ia.length * 2).order(ByteOrder.nativeOrder()).asShortBuffer();
      ib.put(ia).position(0);

      il = ia.length;

      textures = getListFromHash(mesh, "textures");
      if (textures.size() == 0) textures = list("placeholder");
      vertexShader = user.shaders.get(getStringFromHash(mesh, "vertex-shader", ""));
      fragmentShader = user.shaders.get(getStringFromHash(mesh, "fragment-shader", ""));
      subObjects = getListFromHash(mesh, "sub-items");
      rotationX = getFloatFromList(getListFromHash(mesh, "rotation"), 0, 0f);
      rotationY = getFloatFromList(getListFromHash(mesh, "rotation"), 1, 0f);
      rotationZ = getFloatFromList(getListFromHash(mesh, "rotation"), 2, 0f);
      scaleX = getFloatFromList(getListFromHash(mesh, "scale"), 0, 1f);
      scaleY = getFloatFromList(getListFromHash(mesh, "scale"), 1, 1f);
      scaleZ = getFloatFromList(getListFromHash(mesh, "scale"), 2, 1f);
      lightR = getFloatFromList(getListFromHash(mesh, "light"), 0, 0f);
      lightG = getFloatFromList(getListFromHash(mesh, "light"), 1, 0f);
      lightB = getFloatFromList(getListFromHash(mesh, "light"), 2, 0f);

    } catch (Exception e) {
      e.printStackTrace();
      Log.e("Mesh Constructor", e.getLocalizedMessage());
      return;
    }
  }
コード例 #20
0
  /** Update or add a sprite to the client side game. */
  public void addPacket(HacktendoPacket Packet) {
    while (!getInitialized()) { // Make sure things have loaded before we start mucking with stuff.
      try {
        Thread.sleep(5);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    do {
      Sprite S = (Sprite) Sprites.get(new Integer(Packet.getID()));
      boolean setRenderType = false;
      if (S == null) {
        S = new Sprite(this);
        setRenderType = true;
        S.setParameter("destroy", new TypeBoolean(false));
        S.setParameter("globalID", new TypeInteger(Packet.getID()));
        S.setParameter("id", new TypeInteger(Packet.getID()));
        Sprites.put(new Integer(Packet.getID()), S);
        S.setOffscreenProcessing(false);
      }
      S.setScriptID(Packet.getScriptID());
      S.setImageID(Packet.getImage());

      if (S.getSpriteID() != playerID || setRenderType) { // Allow the sprite to move client side.
        S.setX(Packet.getX());
        S.setY(Packet.getY());
        S.setZ(Packet.getZ());
        S.setParameter("xTarget", new TypeInteger(Packet.getTargetX()));
        S.setParameter("yTarget", new TypeInteger(Packet.getTargetY()));
        S.setParameter("newTarget", new TypeBoolean(true));
      }

      if (Packet.getExplodeSprite()) S.explode();
      if (Packet.getDestroySprite()) S.setParameter("destroy", new TypeBoolean(true));
      S.setFrame(Packet.getFrame());
      S.setXRotation(Packet.getXRotation());
      S.setYRotation(Packet.getYRotation());
      S.setZRotation(Packet.getZRotation());

      S.setWidth(Packet.getWidth());
      S.setHeight(Packet.getHeight());
      S.setDepth(Packet.getDepth());
      S.setZOffset(Packet.getZOffset() * -1);

      if (setRenderType) S.setRenderType(Packet.getRenderType());

    } while (Packet.next() > 0);

    // Takes the form Object[]{ID,IP,Name,NPC,BODY_ID}
    if (Packet.getReferenceArray() != null) {
      for (int i = 0; i < Packet.getReferenceArray().size(); i++) {
        Object O[] = (Object[]) Packet.getReferenceArray().get(i);
        Sprite S = (Sprite) Sprites.get((Integer) O[0]);

        System.out.println("ID: " + O[0]);
        if (S != null) {
          String ip = (String) O[1];
          String name = (String) O[2];
          boolean npc = (Boolean) O[3];

          S.setParameter("ip", new TypeString(ip));
          S.setParameter("name", new TypeString(name));
          S.setParameter("npc", new TypeBoolean(npc));

          if (S.getScriptID() == SPRITE_SCRIPT) {
            S.setOffscreenProcessing(true);
            S.setAutoCollide(true);
            Sprite S2 = (Sprite) Sprites.get((Integer) O[4]);
            S.setParameter("body", new TypeInteger(S2.getSpriteID()));
          }

          if (ip.equals(MyHacker.getIP())) {
            if (S.getScriptID() == SPRITE_SCRIPT) {
              playerSprite = S;
            }
            playerID = S.getSpriteID();
            System.out.println(
                "We are setting the player to equal : "
                    + S.getSpriteID()
                    + " This Is Sprite ID: "
                    + O[0]);
            HacktendoLinker.addGlobal("player", new TypeInteger(S.getSpriteID()));
          }
        }
      }
    }
  }
コード例 #21
0
ファイル: CliTest.java プロジェクト: raceimaztion/sphereority
  public static void main(String[] args) {
    try {
      System.out.println("CliTest.java");
      // create TCP socket channel
      SocketChannel channel = SocketChannel.open();
      System.out.println("CliTest.java: channel created");
      channel.connect(new InetSocketAddress("localhost", PORT));
      System.out.println("CliTest.java: channel socket connected");
      System.out.println();

      // create  & send a login message
      byte[] bytes = LoginMessage.getLoginMessage("user1", "password1");
      System.out.println("CliTest.java: login message created");
      System.out.println(LoginMessage.getMessageString(bytes));
      System.out.printf("CliTest.java: login message length in bytes: %d\n", bytes.length);
      ByteBuffer buf = ByteBuffer.allocate(4096);
      buf.put(bytes);
      buf.flip();
      // System.out.printf("CliTest.java: buf.remaining before channel.write(): %d\n",
      // buf.remaining());
      int numwritten = channel.write(buf);
      System.out.printf(
          "CliTest.java: login mesage written: number of bytes written: %d\n", numwritten);

      // read reply message
      buf.clear();
      int numread = channel.read(buf);
      bytes = new byte[numread];
      buf.flip();
      buf.get(bytes);
      if (LoginMessage.isLoginSuccessMessage(bytes)) {
        System.out.printf(
            "CliTest.java: first message read: Success Message: number of bytes read: %d\n",
            numread);
        // get remote port number from success message
        int port = LoginMessage.getPort(bytes);
        System.out.printf("Port Number: %d\n", port);
        byte playerid = LoginMessage.getPlayerId(bytes);
        System.out.printf("Player id: %d\n", playerid);
        String mcastString = LoginMessage.getMulticastAddress(bytes);
        System.out.printf("Multicast Address: %s\n", mcastString);
        // create datagram channel & connect to rem port
        DatagramChannel dchannel = DatagramChannel.open();
        dchannel.socket().bind(new InetSocketAddress(0));
        dchannel.socket().connect(new InetSocketAddress(channel.socket().getInetAddress(), port));
        // get localport of datagram socket
        int localport = dchannel.socket().getLocalPort();
        System.out.printf("UDP local port: %d\n", localport);
        // send success message to send port number to server
        bytes = LoginMessage.getLoginSuccessMessage(playerid, null, localport);
        buf.clear();
        buf.put(bytes);
        buf.flip();
        channel.write(buf);

        DeathMessage dm = new DeathMessage((byte) 1, (byte) 1);
        bytes = dm.getByteMessage();
        buf.clear();
        buf.put(bytes);
        buf.flip();
        channel.write(buf);
      } else {
        System.out.printf(
            "CliTest.java: first message read: NOT Success Message: number of bytes read: %d\n",
            numread);
      }
      channel.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #22
0
  /**
   * コンストラクタ ここでファイルからデータを読み込んでいる
   *
   * @param in_gl OpenGLコマンド群をカプセル化したクラス
   * @param in_texPool テクスチャ管理クラス
   * @param i_provider ファイルデータプロバイダ
   * @param mqoFile 読み込みファイル
   * @param scale モデルの倍率
   * @param isUseVBO 頂点配列バッファを使用するかどうか
   */
  protected KGLMetaseq(
      GL10 gl, KGLTextures in_texPool, AssetManager am, String msqname, float scale) {
    super(in_texPool, am, scale);
    //	targetMQO = in_moq;
    material mats[] = null;
    InputStream fis = null;
    // InputStreamReader isr = null ;
    // BufferedReader br = null;
    multiInput br = null;
    String chankName[] = null;
    GLObject glo = null;
    ArrayList<GLObject> globjs = new ArrayList<GLObject>();
    try {
      fis = am.open(msqname);
      // isr = new InputStreamReader(fis) ;
      // br = new BufferedReader(isr);
      br = new multiInput(fis);
      while ((chankName = Chank(br, false)) != null) {
        /*
         * for( int i = 0 ; i < chankName.length ; i++ ) {
         * System.out.print(chankName[i]+" ") ; } System.out.println() ;
         */
        if (chankName[0].trim().toUpperCase().equals("MATERIAL")) {
          try {
            mats = new material[Integer.parseInt(chankName[1])];
            for (int m = 0; m < mats.length; m++) {
              mats[m] = new material();
              mats[m].set(br.readLine().trim());
              // Log.i("KGLMetaseq", "Material(" + m+") :" + mats[m].toString());
            }
          } catch (Exception mat_e) {
            Log.e("KGLMetaseq", "MQOファイル Materialチャンク読み込み例外発生 " + mat_e.getMessage());
            throw new KGLException(mat_e);
          }
        }
        try {
          if (chankName[0].trim().toUpperCase().equals("OBJECT")) {
            objects object = new objects();
            object.set(chankName[1], br, scale);

            // System.out.println(object.toString()) ;
            if (object.face == null) {
              continue; // 面情報のないオブジェクトは飛ばす
            }
            glo = makeObjs(gl, mats, object);
            if (glo != null) {
              globjs.add(glo);
            }
          }
        } catch (Exception obj_e) {
          Log.e(
              "KGLMetaseq", "MQOファイル Object[" + chankName[1] + "]チャンク読み込み例外発生 " + obj_e.toString());
          throw new KGLException(obj_e);
        }
      }
      br.close(); // 読み込み終了
      br = null;
      glObj = globjs.toArray(new GLObject[0]);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      try {
        if (br != null) br.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
コード例 #23
0
 /**
  * faceチャンクの読み込み
  *
  * @param br 読み込みストリーム
  * @return 面配列
  * @throws Exception
  */
 private Face[] readFace(multiInput br) throws Exception {
   ArrayList<Face> qf;
   String line = null;
   String[] s;
   Integer Mn;
   Face[] wface = null;
   int p;
   int pe;
   qf = new ArrayList<Face>();
   try {
     while ((line = br.readLine()) != null) {
       if (line.length() <= 0) continue;
       line = line.trim();
       if (line.equals("}")) break;
       wface = null;
       Mn = null;
       p = line.indexOf("M(");
       if (p != -1) {
         pe = line.indexOf(")", p);
         Mn = Integer.parseInt(line.substring(p + 2, pe));
       }
       p = line.indexOf("V(");
       if (p == -1) continue;
       pe = line.indexOf(")", p);
       s = line.substring(p + 2, pe).split(" ");
       if (s.length == 3) {
         wface = new Face[1];
         wface[0] = new Face();
         wface[0].V = new Integer[3];
         wface[0].V[0] = Integer.parseInt(s[0]);
         wface[0].V[1] = Integer.parseInt(s[1]);
         wface[0].V[2] = Integer.parseInt(s[2]);
         wface[0].M = Mn;
         p = line.indexOf("UV(");
         if (p != -1) {
           pe = line.indexOf(")", p);
           s = line.substring(p + 3, pe).split(" ");
           if (s.length != 2 * 3) throw new Exception("UVの数が不正");
           wface[0].UV = new Float[2 * 3];
           for (int i = 0; i < s.length; i++) {
             wface[0].UV[i] = Float.parseFloat(s[i]);
           }
         }
         p = line.indexOf("COL(");
         if (p != -1) {
           pe = line.indexOf(")", p);
           s = line.substring(p + 4, pe).split(" ");
           if (s.length != 3) throw new Exception("COLの数が不正");
           wface[0].COL = new Float[4 * 3];
           long wl;
           float wf;
           for (int i = 0; i < s.length; i++) {
             wl = Long.parseLong(s[i]);
             wf = (wl >>> 0) & 0x000000ff;
             wface[0].COL[i * 4 + 0] = wf / 255f;
             wf = (wl >>> 8) & 0x000000ff;
             wface[0].COL[i * 4 + 1] = wf / 255f;
             wf = (wl >>> 16) & 0x000000ff;
             wface[0].COL[i * 4 + 2] = wf / 255f;
             wf = (wl >>> 24) & 0x000000ff;
             wface[0].COL[i * 4 + 3] = wf / 255f;
           }
         }
       }
       // 頂点配列はすべて三角にするので、四角は三角x2に分割
       // 0 3 0 0 3
       // □ → △ ▽
       // 1 2 1 2 2
       if (s.length == 4) {
         wface = new Face[2];
         wface[0] = new Face();
         wface[1] = new Face();
         wface[0].V = new Integer[3];
         wface[0].V[0] = Integer.parseInt(s[0]);
         wface[0].V[1] = Integer.parseInt(s[1]);
         wface[0].V[2] = Integer.parseInt(s[2]);
         wface[0].M = Mn;
         wface[1].V = new Integer[3];
         wface[1].V[0] = Integer.parseInt(s[0]);
         wface[1].V[1] = Integer.parseInt(s[2]);
         wface[1].V[2] = Integer.parseInt(s[3]);
         wface[1].M = Mn;
         p = line.indexOf("UV(");
         if (p != -1) {
           int uv_p;
           pe = line.indexOf(")", p);
           s = line.substring(p + 3, pe).split(" ");
           if (s.length != 2 * 4) throw new Exception("UVの数が不正");
           wface[0].UV = new Float[2 * 3];
           wface[1].UV = new Float[2 * 3];
           for (int i = 0; i < 2; i++) {
             uv_p = 0;
             for (int j = 0; j < 4; j++) {
               if (i == 0 && j == 3) continue;
               if (i == 1 && j == 1) continue;
               wface[i].UV[uv_p++] = Float.parseFloat(s[j * 2 + 0]);
               wface[i].UV[uv_p++] = Float.parseFloat(s[j * 2 + 1]);
             }
           }
         }
         p = line.indexOf("COL(");
         if (p != -1) {
           pe = line.indexOf(")", p);
           s = line.substring(p + 4, pe).split(" ");
           if (s.length != 4) throw new Exception("COLの数が不正");
           wface[0].COL = new Float[4 * 3];
           wface[1].COL = new Float[4 * 3];
           long wl;
           float wf;
           int col_p;
           for (int i = 0; i < 2; i++) {
             col_p = 0;
             for (int j = 0; j < s.length; j++) {
               if (i == 0 && j == 3) continue;
               if (i == 1 && j == 1) continue;
               wl = Long.parseLong(s[j]);
               wf = (wl >>> 0) & 0x000000ff;
               wface[i].COL[col_p * 4 + 0] = wf / 255f;
               wf = (wl >>> 8) & 0x000000ff;
               wface[i].COL[col_p * 4 + 1] = wf / 255f;
               wf = (wl >>> 16) & 0x000000ff;
               wface[i].COL[col_p * 4 + 2] = wf / 255f;
               wf = (wl >>> 24) & 0x000000ff;
               wface[i].COL[col_p * 4 + 3] = wf / 255f;
               col_p++;
             }
           }
         }
       }
       if (wface != null) {
         for (int i = 0; i < wface.length; i++) {
           qf.add(wface[i]);
         }
       }
     }
   } catch (Exception e) {
     Log.e("KGLMetaseq", "MQOファイル フォーマットエラー(Object>face)" + e.getMessage() + "[" + line + "]");
     throw e;
   }
   if (qf.size() == 0) return null;
   return qf.toArray(new Face[0]);
 }
コード例 #24
0
  @Override
  public void paint(Graphics g) {
    try {
      Graphics2D g2d = (Graphics2D) g;
      if (numPaletteEntries > 50) {
        g2d.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      }
      if (paletteFile != null
          && (paletteFile.toLowerCase().contains("qual")
              || paletteFile.toLowerCase().contains("categorical"))) {
        g2d.setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
      }
      int width = getWidth();
      int height = getHeight();

      Image image = null;
      int numDisplayedPaletteEntries = 0;
      if (!categorical) {
        numDisplayedPaletteEntries = paletteData.length;
      } else {
        numDisplayedPaletteEntries =
            (int)
                (Math.floor((maxValue - minValue + 1) / numPaletteEntries)
                    + (maxValue - minValue + 1) % numPaletteEntries);
      }
      int[] imageData = new int[numDisplayedPaletteEntries];
      int i, j;
      int numPaletteEntriesLessOne = numPaletteEntries - 1;
      if (!isReversed && orientation == VERTICAL_ORIENTATION) {
        if (!categorical) {
          for (i = 0; i < numPaletteEntries; i++) {
            j =
                (int)
                    ((Math.pow((1 - ((double) (i) / numPaletteEntriesLessOne)), gamma))
                        * numPaletteEntriesLessOne);
            imageData[i] = paletteData[j];
          }
        } else { // it is categorical
          for (i = 0; i < numDisplayedPaletteEntries; i++) {
            j = (int) (i % numPaletteEntries);
            imageData[numDisplayedPaletteEntries - 1 - i] = paletteData[j];
          }
        }
        image = createImage(new MemoryImageSource(1, numDisplayedPaletteEntries, imageData, 0, 1));
      } else if (!isReversed && orientation == HORIZONTAL_ORIENTATION) {
        for (i = 0; i < numPaletteEntries; i++) {
          j =
              (int)
                  ((Math.pow(((double) (i) / numPaletteEntriesLessOne), gamma))
                      * numPaletteEntriesLessOne);
          imageData[i] = paletteData[j];
        }
        image = createImage(new MemoryImageSource(numPaletteEntries, 1, imageData, 0, 1));
      } else if (isReversed && orientation == VERTICAL_ORIENTATION) {
        if (!categorical) {
          for (i = 0; i < numPaletteEntries; i++) {
            j =
                (int)
                    ((Math.pow(((double) (i) / numPaletteEntriesLessOne), gamma))
                        * numPaletteEntriesLessOne);
            imageData[i] = paletteData[j];
          }
        } else { // it is categorical
          for (i = 0; i < numDisplayedPaletteEntries; i++) {
            j = (int) (numPaletteEntries - i % numPaletteEntries - 1);
            imageData[numDisplayedPaletteEntries - 1 - i] = paletteData[j];
          }
        }
        image = createImage(new MemoryImageSource(1, numDisplayedPaletteEntries, imageData, 0, 1));
      } else if (isReversed && orientation == HORIZONTAL_ORIENTATION) {
        for (i = 0; i < numPaletteEntries; i++) {
          j =
              (int)
                  ((Math.pow((1 - ((double) (i) / numPaletteEntriesLessOne)), gamma))
                      * numPaletteEntriesLessOne);
          imageData[i] = paletteData[j];
        }
        image = createImage(new MemoryImageSource(imageData.length, 1, imageData, 0, 1));
      }

      g.drawImage(image, 0, 0, width, height, this);
      if (!isSelected) {
        g.setColor(Color.black);
        g.drawRect(0, 0, width - 1, height - 1);
      } else {
        g.setColor(Color.white);
        g.drawRect(1, 1, width - 3, height - 3);
        g.setColor(Color.red);
        g.drawRect(0, 0, width - 1, height - 1);
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }