Example #1
0
  private boolean MoveAbs(int X, int Y) {
    try {
      String urlString =
          schema
              + serverName
              + ":"
              + port
              + "/cgi/ptdc.cgi?command=set_pos&posX="
              + X
              + "&posY="
              + Y;
      logger.warn("Url je: " + urlString);
      URL url = new URL(urlString);
      String authStr = user + ":" + pass;
      String authEncoded = Base64.encodeToString(authStr.getBytes(), false);

      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setRequestProperty("Authorization", "Basic " + authEncoded);
      connection.setRequestMethod("GET");
      connection.getResponseMessage();
    } catch (MalformedURLException e) {
      return false;
    } catch (ProtocolException e) {
      return false;
    } catch (IOException e) {
      return false;
    }
    return true;
  }
Example #2
0
  @Override
  public void run() {
    while (isActive()) {

      ByteArrayOutputStream baos = null;
      try {
        URL url =
            new URL(schema + serverName + ":" + port + "/video/mjpg.cgi?profileid=" + profile);

        String authStr = user + ":" + pass;
        String authEncoded = Base64.encodeToString(authStr.getBytes(), false);

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Authorization", "Basic " + authEncoded);

        baos = new ByteArrayOutputStream();

        InputStream webStream = (InputStream) connection.getContent();
        IPKameraStreamWrapper ipStream = null;
        try {
          ipStream = new IPKameraStreamWrapper(webStream);
          ipStream.writeNextImage(baos);

        } catch (Exception e) {
          logger.error(e);
        } finally {
          try {
            if (ipStream != null) ipStream.close();
          } catch (Exception e) {
            logger.warn("Could not close IP Cam stream: " + e.getStackTrace());
          }
        }

        byte[] imageInByte = baos.toByteArray();
        baos.close();

        StreamElement streamElement =
            new StreamElement(
                new String[] {"picture"},
                new Byte[] {DataTypes.BINARY},
                new Serializable[] {imageInByte},
                System.currentTimeMillis());
        postStreamElement(streamElement);
        Thread.sleep(rate);

      } catch (MalformedURLException e1) {
        logger.error(e1);
      } catch (IOException e) {
        logger.error(e);
      } catch (InterruptedException e) {
        logger.error(e);
      } finally {
        if (baos != null) {
          try {
            baos.close();
          } catch (IOException e) {
            logger.error(e);
          }
        }
      }
    }
  }