コード例 #1
0
ファイル: TENVCChannel.java プロジェクト: yjfcool/geo-log
 @Override
 public void DoStreaming(
     Socket Connection,
     InputStream pInputStream,
     int pInputStreamSize,
     OutputStream pOutputStream,
     TOnProgressHandler OnProgressHandler,
     int StreamingTimeout,
     int IdleTimeoutCounter,
     TOnIdleHandler OnIdleHandler,
     TCanceller Canceller)
     throws Exception {
   byte[] TransferBuffer = new byte[DescriptorSize];
   short Size;
   int BytesRead, BytesRead1;
   int IdleTimeoutCount = 0;
   int _StreamingTimeout = StreamingTimeout * IdleTimeoutCounter;
   while (!Canceller.flCancel) {
     try {
       if (Connection != null) Connection.setSoTimeout(StreamingTimeout);
       BytesRead =
           TNetworkConnection.InputStream_ReadData(pInputStream, TransferBuffer, DescriptorSize);
       if (BytesRead <= 0) break; // . >
       IdleTimeoutCount = 0;
     } catch (SocketTimeoutException E) {
       IdleTimeoutCount++;
       if (IdleTimeoutCount >= IdleTimeoutCounter) {
         IdleTimeoutCount = 0;
         OnIdleHandler.DoOnIdle(Canceller);
       }
       // .
       continue; // . ^
     }
     if (BytesRead != DescriptorSize) throw new IOException("wrong data descriptor"); // . =>
     // .
     BytesRead1 = 0;
     Size = (short) (((TransferBuffer[1] & 0xFF) << 8) + (TransferBuffer[0] & 0xFF));
     if (Size > 0) {
       if (Size > TransferBuffer.length) TransferBuffer = new byte[Size];
       if (Connection != null) Connection.setSoTimeout(_StreamingTimeout);
       BytesRead1 = TNetworkConnection.InputStream_ReadData(pInputStream, TransferBuffer, Size);
       if (BytesRead1 <= 0) break; // . >
       // . parse and process
       ParseFromByteArrayAndProcess(TransferBuffer, 0, Size);
       // .
       OnProgressHandler.DoOnProgress(BytesRead1, Canceller);
     }
     // .
     if (pInputStreamSize > 0) {
       pInputStreamSize -= (BytesRead + BytesRead1);
       if (pInputStreamSize <= 0) break; // . >
     }
   }
 }
コード例 #2
0
 @Override
 protected TComponentData Server_GetData() throws Exception {
   String URL1 = Server.Address;
   // . add command path
   URL1 =
       "http://"
           + URL1
           + "/"
           + "Space"
           + "/"
           + "2" /* URLProtocolVersion */
           + "/"
           + Long.toString(Server.User.UserID);
   String URL2 =
       "TypesSystem"
           + "/"
           + Integer.toString(TypeFunctionality.idType)
           + "/"
           + "Co"
           + "/"
           + Long.toString(idComponent)
           + "/"
           + "Data.dat";
   // . add command parameters
   URL2 = URL2 + "?" + "0" /* command */ + "," + "1" /* version of data*/;
   // .
   byte[] URL2_Buffer;
   try {
     URL2_Buffer = URL2.getBytes("windows-1251");
   } catch (Exception E) {
     URL2_Buffer = null;
   }
   byte[] URL2_EncryptedBuffer = Server.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 + ".dat";
   // .
   try {
     HttpURLConnection Connection = Server.OpenConnection(URL);
     try {
       InputStream in = Connection.getInputStream();
       try {
         byte[] Data = new byte[Connection.getContentLength()];
         int Size = TNetworkConnection.InputStream_ReadData(in, Data, Data.length);
         if (Size != Data.length)
           throw new IOException(
               Server.context.getString(R.string.SErrorOfPositionGetting)); // . =>
         // .
         TGeoCrdSystemData Result = new TGeoCrdSystemData();
         Result.FromByteArrayV1(Data, 0);
         // .
         return Result; // . ->
       } finally {
         in.close();
       }
     } finally {
       Connection.disconnect();
     }
   } catch (IOException E) {
     throw new Exception(E.getMessage()); // . =>
   }
 }
コード例 #3
0
ファイル: TSpaceHints.java プロジェクト: yjfcool/geo-log
 @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();
   }
 }