@Override
 public int FromByteArrayV1(byte[] BA, int Idx) throws IOException {
   Idx = super.FromByteArrayV1(BA, Idx);
   // .
   Idx = N0.FromByteArray(BA, Idx);
   Idx = N1.FromByteArray(BA, Idx);
   Idx = N2.FromByteArray(BA, Idx);
   Idx = N3.FromByteArray(BA, Idx);
   // .
   Width = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   Height = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   // .
   int DataSize = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   int LC = DataSize / TLevelParams.Size;
   Levels = new TLevelParams[LC];
   for (int I = 0; I < LC; I++) {
     Levels[I] = new TLevelParams();
     Idx = Levels[I].FromByteArray(BA, Idx);
   }
   // .
   return Idx;
 }
Пример #2
0
  @Override
  public int ParseFromByteArrayAndProcess(byte[] BA, int Idx, int Size) throws Exception {
    short Descriptor = TDataConverter.ConvertLEByteArrayToInt16(BA, Idx);
    Idx += DescriptorSize;
    switch (Descriptor) {
      case TimestampTag:
        double Timestamp = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
        Idx += 8; // . SizeOf(Double)
        if (OnTimestampHandler != null) OnTimestampHandler.DoOnValue(Timestamp);
        break; // . >

      case TemperatureTag:
        double Temperature = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
        Idx += 8; // . SizeOf(Double)
        if (OnTemperatureHandler != null) OnTemperatureHandler.DoOnValue(Temperature);
        break; // . >

      case PressureTag:
        double Pressure = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
        Idx += 8; // . SizeOf(Double)
        if (OnPressureHandler != null) OnPressureHandler.DoOnValue(Pressure);
        break; // . >

      case HumidityTag:
        double Humidity = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
        Idx += 8; // . SizeOf(Double)
        if (OnHumidityHandler != null) OnHumidityHandler.DoOnValue(Humidity);
        break; // . >
    }
    return Idx;
  }
Пример #3
0
 public synchronized void ReviseItemsInReflectionWindow(
     TReflectionWindowStruc RW, byte[] ExistingItemsBA, TCanceller Canceller)
     throws IOException, CancelException {
   TSpaceHint LastItem = null;
   TSpaceHint Item = Items;
   while (Item != null) {
     boolean flRemove = false;
     if (RW.Container_IsNodeVisible(Item.BindingPointX, Item.BindingPointY)) {
       flRemove = true;
       int Idx = 0;
       int _ItemsCount = TDataConverter.ConvertLEByteArrayToInt32(ExistingItemsBA, Idx);
       Idx += 4;
       for (int I = 0; I < _ItemsCount; I++) {
         int ItemID = TDataConverter.ConvertLEByteArrayToInt32(ExistingItemsBA, Idx);
         Idx += 8; // . Int64
         if (ItemID == Item.ID) {
           flRemove = false;
           break; // . >
         }
         Idx = Item.ByteArraySkip(ExistingItemsBA, Idx);
       }
     }
     if (flRemove) {
       if (LastItem != null) LastItem.Next = Item.Next;
       else Items = Item.Next;
       ItemsTable.remove(Item.ID);
       ItemsCount--;
     } else LastItem = Item;
     // .
     if (Canceller != null) Canceller.Check();
     // .
     Item = Item.Next;
   }
 }
Пример #4
0
 public synchronized void FromByteArray(byte[] BA, TCanceller Canceller)
     throws IOException, CancelException {
   RemoveOldItems();
   // .
   int Idx = 0;
   int _ItemsCount = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   for (int I = 0; I < _ItemsCount; I++) {
     int ItemID = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
     Idx += 8; // . Int64
     TSpaceHint Item = ItemsTable.get(ItemID);
     if (Item == null) {
       Item = new TSpaceHint(ItemID, Reflector.metrics);
       // .
       Item.Next = Items;
       Items = Item;
       ItemsCount++;
       // .
       ItemsTable.put(ItemID, Item);
     }
     Idx = Item.FromByteArray(BA, Idx);
     // .
     if (Canceller != null) Canceller.Check();
   }
 }
 public byte[] ToByteArrayV1() throws IOException {
   ByteArrayOutputStream BOS = new ByteArrayOutputStream(1024);
   try {
     BOS.write(super.ToByteArrayV1());
     // .
     BOS.write(N0.ToByteArray());
     BOS.write(N1.ToByteArray());
     BOS.write(N2.ToByteArray());
     BOS.write(N3.ToByteArray());
     // .
     byte[] BA = TDataConverter.ConvertInt32ToLEByteArray(Width);
     BOS.write(BA);
     BA = TDataConverter.ConvertInt32ToLEByteArray(Height);
     BOS.write(BA);
     // .
     int DataSize = 0;
     if (Levels != null) DataSize = Levels.length * TLevelParams.Size;
     BA = TDataConverter.ConvertInt32ToLEByteArray(DataSize);
     BOS.write(BA);
     if (DataSize > 0) for (int I = 0; I < Levels.length; I++) BOS.write(Levels[I].ToByteArray());
     // .
     return BOS.toByteArray(); // . ->
   } finally {
     BOS.close();
   }
 }
Пример #6
0
 public byte[] ToByteArray() throws IOException {
   byte[] BA;
   byte[] B1A = new byte[1];
   byte[] Int64Space = new byte[4];
   ByteArrayOutputStream BOS = new ByteArrayOutputStream(1024);
   try {
     BA = TDataConverter.ConvertInt32ToLEByteArray(ID);
     BOS.write(BA);
     BOS.write(Int64Space);
     // .
     BA = TDataConverter.ConvertInt16ToLEByteArray(Level);
     BOS.write(BA);
     // .
     BA = TDataConverter.ConvertInt16ToLEByteArray(InfoComponent_Type);
     BOS.write(BA);
     // .
     BA = TDataConverter.ConvertInt32ToLEByteArray(InfoComponent_ID);
     BOS.write(BA);
     BOS.write(Int64Space);
     // .
     BA = TDataConverter.ConvertDoubleToLEByteArray(BindingPointX);
     BOS.write(BA);
     // .
     BA = TDataConverter.ConvertDoubleToLEByteArray(BindingPointY);
     BOS.write(BA);
     // .
     BA = TDataConverter.ConvertDoubleToLEByteArray(BaseSquare);
     BOS.write(BA);
     // .
     BA = TDataConverter.ConvertInt32ToLEByteArray(InfoImageDATAFileID);
     BOS.write(BA);
     BOS.write(Int64Space);
     // .
     B1A[0] = (byte) InfoString.length();
     BOS.write(B1A);
     if (B1A[0] > 0) BOS.write(InfoString.getBytes("windows-1251"));
     // .
     BA = TDataConverter.ConvertInt32ToLEByteArray(InfoStringFontColor);
     BOS.write(BA);
     // .
     B1A[0] = InfoStringFontSize;
     BOS.write(B1A);
     // .
     B1A[0] = (byte) InfoStringFontName.length();
     BOS.write(B1A);
     if (B1A[0] > 0) BOS.write(InfoStringFontName.getBytes("windows-1251"));
     // .
     return BOS.toByteArray();
   } finally {
     BOS.close();
   }
 }
 public byte[] ToByteArray() throws IOException {
   byte[] Result = new byte[Size];
   int Idx = 0;
   // .
   byte[] BA = TDataConverter.ConvertInt32ToLEByteArray(id);
   System.arraycopy(BA, 0, Result, Idx, BA.length);
   Idx += BA.length;
   BA = TDataConverter.ConvertInt32ToLEByteArray(DivX);
   System.arraycopy(BA, 0, Result, Idx, BA.length);
   Idx += BA.length;
   BA = TDataConverter.ConvertInt32ToLEByteArray(DivY);
   System.arraycopy(BA, 0, Result, Idx, BA.length);
   Idx += BA.length;
   BA = TDataConverter.ConvertDoubleToLEByteArray(SegmentWidth);
   System.arraycopy(BA, 0, Result, Idx, BA.length);
   Idx += BA.length;
   BA = TDataConverter.ConvertDoubleToLEByteArray(SegmentHeight);
   System.arraycopy(BA, 0, Result, Idx, BA.length);
   Idx += BA.length;
   BA = TDataConverter.ConvertDoubleToLEByteArray(VisibleMinScale);
   System.arraycopy(BA, 0, Result, Idx, BA.length);
   Idx += BA.length;
   BA = TDataConverter.ConvertDoubleToLEByteArray(VisibleMaxScale);
   System.arraycopy(BA, 0, Result, Idx, BA.length);
   Idx += BA.length;
   // .
   return Result;
 }
Пример #8
0
  public void Load() throws IOException {
    File F = new File(ElectedPlaceFileName);
    Items.clear();
    if (F.exists()) {
      long FileSize = F.length();
      FileInputStream FIS = new FileInputStream(ElectedPlaceFileName);
      try {
        byte[] BA = new byte[(int) FileSize];
        FIS.read(BA);
        int Idx = 0;
        int Version = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
        Idx += 4;
        switch (Version) {
          case 0:
          case 1:
            int ItemsCount = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
            Idx += 4;
            for (int I = 0; I < ItemsCount; I++) {
              TLocation Item = new TLocation();
              Idx = Item.FromByteArray(BA, Idx);
              // .
              Items.add(Item);
            }
            break; // . >

          case 3:
            ItemsCount = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
            Idx += 4;
            for (int I = 0; I < ItemsCount; I++) {
              TLocation Item = new TLocation();
              Idx = Item.FromByteArrayV2(BA, Idx);
              // .
              Items.add(Item);
            }
            break; // . >

            /*///- default:
            throw new IOException("неизвестная версия данных, версия: "+Integer.toString(Version)); //. =>*/
        }
      } finally {
        FIS.close();
      }
    }
  }
Пример #9
0
 public synchronized void SaveItems() throws IOException {
   FileOutputStream FOS = new FileOutputStream(HintsFileName);
   try {
     byte[] ItemsCountBA = TDataConverter.ConvertInt32ToLEByteArray(ItemsCount);
     FOS.write(ItemsCountBA);
     TSpaceHint Item = Items;
     while (Item != null) {
       byte[] BA = Item.ToByteArray();
       short ItemDataSize = (short) BA.length;
       byte[] ItemDataSizeBA = TDataConverter.ConvertInt16ToLEByteArray(ItemDataSize);
       FOS.write(ItemDataSizeBA);
       FOS.write(BA);
       // .
       Item = Item.Next;
     }
   } finally {
     FOS.close();
   }
 }
Пример #10
0
 public void Save() throws IOException {
   if (Items != null) {
     FileOutputStream FOS = new FileOutputStream(ElectedPlaceFileName);
     try {
       byte[] BA = TDataConverter.ConvertInt32ToLEByteArray(ElectedPlaceFileVersion);
       FOS.write(BA);
       int ItemsCount = Items.size();
       BA = TDataConverter.ConvertInt32ToLEByteArray(ItemsCount);
       FOS.write(BA);
       for (int I = 0; I < ItemsCount; I++) {
         BA = Items.get(I).ToByteArray();
         FOS.write(BA);
       }
     } finally {
       FOS.close();
     }
   } else {
     File F = new File(ElectedPlaceFileName);
     F.delete();
   }
 }
Пример #11
0
 public synchronized void LoadItems() throws IOException {
   Items = null;
   ItemsCount = 0;
   TSpaceHint LastItem = null;
   // .
   File F = new File(HintsFileName);
   if (F.exists()) {
     FileInputStream FIS = new FileInputStream(HintsFileName);
     try {
       byte[] ItemsCountBA = new byte[4];
       FIS.read(ItemsCountBA);
       int _ItemsCount = TDataConverter.ConvertLEByteArrayToInt32(ItemsCountBA, 0);
       // .
       byte[] ItemData = new byte[1024]; // . max item data size
       for (int I = 0; I < _ItemsCount; I++) {
         byte[] ItemDataSizeBA = new byte[2];
         FIS.read(ItemDataSizeBA);
         short ItemDataSize = TDataConverter.ConvertLEByteArrayToInt16(ItemDataSizeBA, 0);
         FIS.read(ItemData, 0, ItemDataSize);
         // .
         int Idx = 0;
         int ItemID = TDataConverter.ConvertLEByteArrayToInt32(ItemData, Idx);
         Idx += 8; // . Int64
         TSpaceHint NewItem = new TSpaceHint(ItemID, Reflector.metrics);
         NewItem.FromByteArray(ItemData, Idx);
         if (ItemsTable.get(ItemID) == null) {
           // . insert into queue
           if (LastItem != null) LastItem.Next = NewItem;
           else Items = NewItem;
           ItemsTable.put(ItemID, NewItem);
           ItemsCount++;
           // .
           LastItem = NewItem;
         }
       }
     } finally {
       FIS.close();
     }
   }
 }
Пример #12
0
 private synchronized void ItemsImageDataFiles_FromByteArray(byte[] BA, TCanceller Canceller)
     throws IOException, CancelException {
   RemoveOldItems();
   // .
   int Idx = 0;
   int _ItemsCount = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   for (int I = 0; I < _ItemsCount; I++) {
     int HintID = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
     Idx += 8; // . Int64
     int ImageDataFileID = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
     Idx += 8; // . Int64
     TSpaceHintImageDataFile ItemsImageDataFiles_Item =
         ItemsImageDataFiles.GetItem(ImageDataFileID);
     Idx = ItemsImageDataFiles_Item.FromByteArray(BA, Idx);
     // .
     TSpaceHint Hint = ItemsTable.get(HintID);
     if (Hint != null) Hint.InfoImageDATAFileID = ImageDataFileID;
     // .
     if (Canceller != null) Canceller.Check();
   }
 }
Пример #13
0
 public int FromByteArray(byte[] BA, int Idx) throws IOException {
   Level = TDataConverter.ConvertLEByteArrayToInt16(BA, Idx);
   Idx += 2;
   // .
   InfoComponent_Type = TDataConverter.ConvertLEByteArrayToInt16(BA, Idx);
   Idx += 2;
   InfoComponent_ID = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 8; // . Int64
   // .
   BindingPointX = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
   Idx += 8;
   BindingPointY = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
   Idx += 8;
   BaseSquare = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
   Idx += 8;
   // .
   InfoImageDATAFileID = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 8; // . Int64
   byte SS = BA[Idx];
   Idx++;
   if (SS > 0) {
     InfoString = new String(BA, Idx, SS, "windows-1251");
     Idx += SS;
   } else InfoString = "";
   InfoStringFontColor = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   InfoStringFontSize = BA[Idx];
   Idx++;
   SS = BA[Idx];
   Idx++;
   if (SS > 0) {
     InfoStringFontName = new String(BA, Idx, SS, "windows-1251");
     Idx += SS;
   } else InfoStringFontName = "";
   // .
   Typeface tf = Typeface.create(InfoStringFontName, Typeface.NORMAL);
   paint.setTypeface(tf);
   paint.setAntiAlias(true);
   paint.setTextSize(InfoStringFontSize * metrics.density * 2.0F);
   byte R = (byte) (InfoStringFontColor & 255);
   byte G = (byte) ((InfoStringFontColor >> 8) & 255);
   byte B = (byte) ((InfoStringFontColor >> 16) & 255);
   paint.setColor(Color.argb(255, R, G, B));
   // .
   return Idx;
 }
 public int FromByteArray(byte[] BA, int Idx) throws IOException {
   id = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   DivX = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   DivY = TDataConverter.ConvertLEByteArrayToInt32(BA, Idx);
   Idx += 4;
   SegmentWidth = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
   Idx += 8;
   SegmentHeight = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
   Idx += 8;
   VisibleMinScale = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
   Idx += 8;
   VisibleMaxScale = TDataConverter.ConvertLEByteArrayToDouble(BA, Idx);
   Idx += 8;
   return Idx;
 }
Пример #15
0
 @SuppressWarnings({"null", "unused"})
 public void GetHintsFromServer(TReflectionWindow ReflectionWindow, TCanceller Canceller)
     throws Exception {
   if (Reflector.flOffline) return; // . ->
   TReflectionWindowStruc RW = ReflectionWindow.GetWindow();
   TReflectorSpaceLays Lays = ReflectionWindow.getLays();
   TReflectionWindowActualityInterval ActualityInterval = ReflectionWindow.GetActualityInterval();
   // .
   String URL1 = Reflector.Server.Address;
   // . add command path
   URL1 =
       "http://"
           + URL1
           + "/"
           + "Space"
           + "/"
           + "2" /*URLProtocolVersion*/
           + "/"
           + Long.toString(Reflector.User.UserID);
   String URL2 = "SpaceWindow.png";
   // . add command parameters
   URL2 =
       URL2
           + "?"
           + "5" /*command version*/
           + ","
           + Double.toString(RW.X0)
           + ","
           + Double.toString(RW.Y0)
           + ","
           + Double.toString(RW.X1)
           + ","
           + Double.toString(RW.Y1)
           + ","
           + Double.toString(RW.X2)
           + ","
           + Double.toString(RW.Y2)
           + ","
           + Double.toString(RW.X3)
           + ","
           + Double.toString(RW.Y3)
           + ",";
   short[] InvisibleLays = Lays.GetDisabledLaysIndexes();
   short InvisibleLaysCount;
   if (InvisibleLays != null) InvisibleLaysCount = (short) InvisibleLays.length;
   else InvisibleLaysCount = 0;
   URL2 = URL2 + Integer.toString(InvisibleLaysCount) + ",";
   for (int I = 0; I < InvisibleLaysCount; I++)
     URL2 = URL2 + Integer.toString(InvisibleLays[I]) + ',';
   URL2 = URL2 + Integer.toString(Reflector.VisibleFactor) + ",";
   URL2 = URL2 + "1" /*Dynamic hint data version*/ + ",";
   // . Visualization UserData
   int TSVUserDataSize = 0;
   byte[] TSVUserData = null;
   if (TSVUserData != null) TSVUserDataSize = TSVUserData.length;
   int Idx = 0;
   byte[] UserData = new byte[4 /*SizeOf(TSVUserDataSize)*/ + TSVUserDataSize];
   byte[] BA = TDataConverter.ConvertInt32ToLEByteArray(TSVUserDataSize);
   System.arraycopy(BA, 0, UserData, Idx, BA.length);
   Idx += BA.length;
   if (TSVUserDataSize > 0) {
     System.arraycopy(TSVUserData, 0, UserData, Idx, TSVUserData.length);
     Idx += TSVUserData.length;
   }
   String UserDataString;
   ByteArrayOutputStream BOS = new ByteArrayOutputStream();
   try {
     Base64OutputStream B64S = new Base64OutputStream(BOS, Base64.URL_SAFE);
     try {
       B64S.write(UserData);
     } finally {
       B64S.close();
     }
     UserDataString = new String(BOS.toByteArray());
   } finally {
     BOS.close();
   }
   URL2 = URL2 + UserDataString + ",";
   // .
   URL2 =
       URL2
           + Double.toString(ActualityInterval.GetBeginTimestamp())
           + ","
           + Double.toString(ActualityInterval.EndTimestamp)
           + ",";
   // .
   URL2 =
       URL2
           + Integer.toString(RW.Xmn)
           + ","
           + Integer.toString(RW.Ymn)
           + ","
           + Integer.toString(RW.Xmx)
           + ","
           + Integer.toString(RW.Ymx);
   boolean flUpdateProxySpace = false;
   if (flUpdateProxySpace) URL2 = URL2 + "," + "1" /*flUpdateProxySpace = true*/;
   // .
   byte[] URL2_Buffer;
   try {
     URL2_Buffer = URL2.getBytes("windows-1251");
   } catch (Exception E) {
     URL2_Buffer = null;
   }
   byte[] URL2_EncryptedBuffer = Reflector.User.EncryptBufferV2(URL2_Buffer);
   // . encode string
   StringBuffer sb = new StringBuffer();
   for (int I = 0; I < URL2_EncryptedBuffer.length; I++) {
     String h = Integer.toHexString(0xFF & URL2_EncryptedBuffer[I]);
     while (h.length() < 2) h = "0" + h;
     sb.append(h);
   }
   URL2 = sb.toString();
   // .
   String URL = URL1 + "/" + URL2 + ".png";
   // .
   HttpURLConnection Connection = Reflector.Server.OpenConnection(URL);
   try {
     InputStream in = Connection.getInputStream();
     try {
       if (Canceller != null) Canceller.Check();
       // .
       byte[] HintDataSizeBA = new byte[4];
       TNetworkConnection.InputStream_ReadData(
           in, HintDataSizeBA, HintDataSizeBA.length, Canceller, Reflector.context);
       int HintDataSize = TDataConverter.ConvertLEByteArrayToInt32(HintDataSizeBA, 0);
       byte[] HintData = new byte[HintDataSize];
       TNetworkConnection.InputStream_ReadData(
           in, HintData, HintDataSize, Canceller, Reflector.context);
       HintData = UnPackByteArray(HintData);
       ReviseItemsInReflectionWindow(RW, HintData, Canceller);
       FromByteArray(HintData, Canceller);
     } finally {
       in.close();
     }
   } finally {
     Connection.disconnect();
   }
 }