⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bluetoothclient.java

📁 Java编写的蓝牙手机遥控器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    catch (IOException localIOException1)
    {
    }
    try
    {
      this.conn.close();
    }
    catch (IOException localIOException2)
    {
    }
    this.state = 0;
  }

  private String readRecord()
  {
    String str1 = "";
    try
    {
      byte[] arrayOfByte;
      this.db = RecordStore.openRecordStore("BluetoothRemoteControl", true);
      try
      {
        if (this.db.getNumRecords() > 0)
        {
          arrayOfByte = this.db.getRecord(1);
        }
        else
        {
          this.db.closeRecordStore();
          String str2 = str1;
          return str2;
        }
      }
      catch (InvalidRecordIDException localInvalidRecordIDException)
      {
        BluetoothRemoteControl.debugError("Please connect to a device...");
        this.db.closeRecordStore();
        localObject1 = str1;
        return localObject1;
      }
      ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(arrayOfByte);
      Object localObject1 = new DataInputStream(localByteArrayInputStream);
      str1 = ((DataInputStream)localObject1).readUTF();
      this.db.closeRecordStore();
    }
    catch (Exception localException)
    {
      BluetoothRemoteControl.debugError("Exception recordstore...");
    }
    return ((String)str1);
  }

  private void storeRecord(String paramString)
  {
    try
    {
      try
      {
        RecordStore.deleteRecordStore("BluetoothRemoteControl");
      }
      catch (Exception localException1)
      {
      }
      this.db = RecordStore.openRecordStore("BluetoothRemoteControl", true);
      ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
      DataOutputStream localDataOutputStream = new DataOutputStream(localByteArrayOutputStream);
      localDataOutputStream.writeUTF(paramString);
      byte[] arrayOfByte = localByteArrayOutputStream.toByteArray();
      this.db.addRecord(arrayOfByte, 0, arrayOfByte.length);
      this.db.closeRecordStore();
    }
    catch (Exception localException2)
    {
      BluetoothRemoteControl.debugError("Exception recordstore...");
    }
  }

  public void deleteRecord()
  {
    try
    {
      try
      {
        RecordStore.deleteRecordStore("BluetoothRemoteControl");
      }
      catch (Exception localException)
      {
      }
    }
  }

  public byte readConnectMethod()
  {
    int i = 0;
    try
    {
      byte[] arrayOfByte;
      this.db = RecordStore.openRecordStore("BluetoothRemoteControlSettings", true);
      try
      {
        if (this.db.getNumRecords() > 0)
        {
          arrayOfByte = this.db.getRecord(1);
        }
        else
        {
          this.db.closeRecordStore();
          int j = i;
          return j;
        }
      }
      catch (InvalidRecordIDException localInvalidRecordIDException)
      {
        this.db.closeRecordStore();
        int k = i;
        return k;
      }
      i = arrayOfByte[0];
      this.db.closeRecordStore();
    }
    catch (Exception localException)
    {
      BluetoothRemoteControl.debugError("Exception readSettingRecord...");
    }
    return i;
  }

  public void storeConnectMethod(byte paramByte)
  {
    try
    {
      try
      {
        RecordStore.deleteRecordStore("BluetoothRemoteControlSettings");
      }
      catch (Exception localException1)
      {
      }
      this.db = RecordStore.openRecordStore("BluetoothRemoteControlSettings", true);
      byte[] arrayOfByte = { 0 };
      arrayOfByte[0] = paramByte;
      this.db.addRecord(arrayOfByte, 0, 1);
      this.db.closeRecordStore();
    }
    catch (Exception localException2)
    {
      BluetoothRemoteControl.debugError("Exception storeSettingRecord...");
    }
  }

  static StreamConnection access$000(BluetoothClient paramBluetoothClient)
  {
    return paramBluetoothClient.conn;
  }

  static BluetoothRemoteControl access$100(BluetoothClient paramBluetoothClient)
  {
    return paramBluetoothClient.own;
  }

  static void access$200(BluetoothClient paramBluetoothClient)
  {
    paramBluetoothClient.disconnectedByRemote();
  }

  public class BluetoothServer
    implements Runnable
  {
    private boolean alive;
    private InputStream in;
    private Thread serverProcessorThread;
    private int state;
    private final int STATE_FIRST;
    private final int STATE_CONTINUE;
    private final int MAX_PACKET_SIZE;
    private final BluetoothClient this$0;

    public BluetoothServer()
    {
      this.this$0 = paramBluetoothClient;
      this.in = null;
      this.STATE_FIRST = 0;
      this.STATE_CONTINUE = 1;
      this.MAX_PACKET_SIZE = 50000;
      this.serverProcessorThread = new Thread(this);
      this.serverProcessorThread.start();
    }

    public void run()
    {
      mainLoop();
    }

    public void mainLoop()
    {
      int i = 0;
      try
      {
        this.in = BluetoothClient.access$000(this.this$0).openInputStream();
      }
      catch (Exception localException1)
      {
        BluetoothClient.access$100(this.this$0).informInformation("Please restart! Exception connection failed no input stream!");
        return;
      }
      catch (Error localError1)
      {
        BluetoothClient.access$100(this.this$0).informInformation("Please restart! Exception connection failed no input stream!");
        return;
      }
      this.alive = true;
      byte[] arrayOfByte = new byte[50000];
      this.state = 0;
      int j = 0;
      int k = 0;
      int i1 = 0;
      int l = 0;
      if (this.alive)
      {
        try
        {
          i = this.in.read((byte[])arrayOfByte, k, 50000 - k - 500);
        }
        catch (IOException localIOException)
        {
          kill();
          i = -1;
        }
        catch (Exception localException2)
        {
          BluetoothClient.access$100(this.this$0).informInformation("Please restart! Exception Receive 1: " + localException2.toString());
          return;
        }
        catch (Error localError2)
        {
          kill();
          i = -1;
        }
        try
        {
          if (i > 0)
            if (k + i < 4)
            {
              k += i;
            }
            else
            {
              int i2 = 1;
              while (true)
              {
                while (true)
                {
                  do
                  {
                    if ((i2 == 0) || (k + i < 4))
                      break label393;
                    j = GUIGeneral.getLengthAtPos(arrayOfByte, 2);
                    switch (this.state)
                    {
                    case 0:
                      if (j > k + i - 4)
                      {
                        this.state = 1;
                        k += i;
                        i2 = 0;
                      }
                      else
                      {
                        l = 1;
                      }
                      break;
                    case 1:
                      if (j > k + i - 4)
                      {
                        k += i;
                        i2 = 0;
                      }
                      else
                      {
                        l = 1;
                      }
                    }
                  }
                  while ((this.alive != true) || (l != 1));
                  BluetoothClient.access$100(this.this$0).receive(arrayOfByte, j + 4);
                  this.state = 0;
                  l = 0;
                  if (k + i <= j + 4)
                    break;
                  i1 = k + i - j + 4;
                  restoreMem(arrayOfByte, 0, j + 4, i1);
                  k = i1;
                  i = 0;
                }
                k = 0;
                i = 0;
                i2 = 0;
              }
            }
        }
        catch (Exception localException3)
        {
          BluetoothClient.access$100(this.this$0).informError("Please restart! Receive Exception 2: " + localException3.toString());
          return;
        }
        catch (Error localError3)
        {
          label393: BluetoothClient.access$100(this.this$0).informInformation("Please restart! Receive Error 2: " + localError3.toString());
          return;
        }
      }
    }

    private void kill()
    {
      this.alive = false;
      try
      {
        this.in.close();
      }
      catch (IOException localIOException)
      {
      }
      BluetoothClient.access$200(this.this$0);
    }

    private void restoreMem(, int paramInt1, int paramInt2, int paramInt3)
    {
      for (int i = 0; i < paramInt3; ++i)
        paramArrayOfByte[(paramInt1 + i)] = paramArrayOfByte[(paramInt2 + i)];
    }

    public void destroy()
    {
      this.alive = false;
      try
      {
        this.in.close();
      }
      catch (IOException localIOException)
      {
      }
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -