lyngsat网站卫星数据解析

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

 package com.wh.sattp;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.OutputStreamWriter;
public class Dealhtml {
 
 private static String filepath="";
 private static String filepath_common="";
 private static String filepath_android="";
 
 /*处理的文件夹。在D:/satdeal/下根据地区创建文件夹,每个文件夹 下面 分为 txt common android 三个子文件夹
  txt中的数据为网站的源代码保存的txt文本数据。common为解析出的通用数据*/
 //private static String FilePath="D:/satdeal/atlantic/";
 //private static String FilePath="D:/satdeal/europe/";
 //private static String FilePath="D:/satdeal/asia/";
 private static String FilePath="D:/satdeal/test/";
 
 public static void main(String[] args) {
  //列出当前文件夹里面的内容,删除掉common和android里面的文件
  File file=new File(FilePath+"txt");
  File files[]=file.listFiles();
  int size=files.length;
  filepath_common=FilePath+"/common/";
  filepath_android=FilePath+"/android/";
  System.out.println(System.currentTimeMillis());
  fileinit();
  for(int i=0;i 里面包含卫星名及经度,
  * 2.确定common 和android下面的文件名
  * */
 private static void dealfile(String path) {
  File file = new File(path);
  FileInputStream ins;
  
  try {
   ins = new FileInputStream(file);
   int readsize;
   byte b[] = new byte[1024000];
   String str=null;
   while ((readsize = ins.read(b)) >= 0) {
    System.out.println("readsize=====" + readsize);
    byte first[]=new byte[100];
    for(int g=0;g<100;g++)
    {
     first[g]=b[g];
    }
    String fis=new String(first);
    int index1=fis.indexOf("");
    int index2=fis.indexOf("");
    String filename=fis.substring(index1+7, index2).replace('\\',' ');
    filename=filename.replace('/', ' ');
    filepath_common+=filename+".txt";
    filepath_android+=filename+".xml";
    System.out.println("filename=====" + filename);
    //Thor 5 at 0.8°W - LyngSat
    str += new String(Byte_dealto_String(b,readsize));
    //System.out.println("str=====" + str);
   }
   dealstr(str); 
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 
 
 /*
  * 处理传入的byte数组
  * 规则:1.先取出所有的 HVRL字符;
  *     2.原样过滤掉前五个和最后五个数据    实际传入的数据是要<1024000的
  *     3.判断连续的四个数字或者五个数字(频率和符号率都是4位或者5位的)
  *    freq的两种格式:  >123456&   和> 1234&
  *    symb的两种格式: >12345-    和>1234-
  *   取出用count标示:
  *      小于4时跳过相同个数
  *      count==10 4位freq
  *      count==11 4位symb
  *      count==20 5位freq
  *      count==21 5位symb
  *   4.freq 用<>包裹起来   symb 用* #并转行包裹  返回有效byte数组
  * 
  * */
 private static byte[] Byte_dealto_String(byte[] b,int size) {
  byte c[] = new byte[10240];
  int j = 0;
  //int size = b.length;
  //System.out.println("size===="+size);
  for (int i = 0; i < size; i++) {
   int count=1;
   if((b[i]=='H'||b[i]=='V')||(b[i]=='R'||b[i]=='L'))
   {
    if(i-2>=0&&b[i-1]==';'&&b[i-2]=='p'&&b[i+1]=='<')
    {
    c[j] = b[i];
    j++;
    }
   }
   if (i < 5 || i > size-5) {
    
    if (b[i] >= '0' && b[i] <= '9') {
     c[j] = b[i];
     j++;
    }
   } else {
    if (b[i] >= '0' && b[i] <= '9') {
     count=1;
     if (b[i + 1] >= '0' && b[i + 1] <= '9') {
      count=2;
      if (b[i + 2] >= '0' && b[i + 2] <= '9') {
       count=3;
       if (b[i + 3] >= '0' && b[i + 3] <= '9') {
        count=4;
        if(b[i-1]=='>'||(b[i-2]=='>'&&b[i-1]==' '))
        {
         if(b[i + 4] >= '0' && b[i + 4] <= '9')
         { 
         
          count=5;
          if(b[i + 5] == '&')
          {
           count=20; 
          }else if(b[i + 5] == '-')
          {
           count=21; 
          }
         }else if(b[i + 4] == '&')
         {
          count=10;
         }else if(b[i + 4]=='-')
         {
          count=11;
         }
        } 
       }
      }
     }
    }
   }
   
   
   if(count<4)
   {
    i+=count-1;
   }else
   {
    if(count>5&&count<20)
    {
     //freq
    if(count==10)
    {
     c[j]='<';
     j++;
    }else if(count==11)
    {
     c[j]='*';
     j++;
    }
       c[j]=b[i];
    j++;
    i++;
    c[j]=b[i];
    j++;
    i++;
    c[j]=b[i];
    j++;
    i++;
    c[j]=b[i];
    j++;
    i++;
     if(count==10)
     {
      c[j]='>';
      j++;
     }else if(count==11)
     {
      c[j]='#';
      j++;
      c[j]='\n';
      j++;
     }
    }
    
    if(count>12)
    {
     //freq
    if(count==20)
    {
     c[j]='<';
     j++;
    }else if(count==21)
    {
     c[j]='*';
     j++;
    }
       c[j]=b[i];
    j++;
    i++;
    c[j]=b[i];
    j++;
    i++;
    c[j]=b[i];
    j++;
    i++;
    c[j]=b[i];
    j++;
    i++;
    c[j]=b[i];
    j++;
    i++;
     if(count==20)
     {
      c[j]='>';
      j++;
     }else if(count==21)
     {
      c[j]='#';
      j++;
      c[j]='\n';
      j++;
     }
    }
    
   }
   
  }
  
  c[j]=' ';
  j++;
  c[j]=' ';
  byte d[] = new byte[j];
  int dsize=d.length;
  
  for(int k=0;kV*67890#
  *   解析数组 先找到 VHRL*的组合定位 < #的位置
  *   规则 : 1.已VHRL为起始 前6和前7 定位<  后6后7定位#
  *    2.按照定位切割有用数据 保存为 <12345>V*67890
  *      判断检测切割的数据  
  *         1.检测 >  位置应该大于等于5且小于等于6  
  *         2.判断<>中的数字 应该在3000-13000之间
  *      
  *      
  *    解析完毕 开始存储数据到指定文件夹    
  * */
 private static void dealstr(String str)
 {
  String all[]=str.split("\n"); 
  //System.out.println("str===" + all.length);
  int size=all.length;
  int count=0;
  String strnew[]=new String[200];
  for(int i=0;i=0&&bstr[j-7]=='<')
     {
      first=j-7;
     }
     if(j-6>=0&&bstr[j-6]=='<')
     {
      first=j-6;
     }
     if(j+7');
     
     if(freqindex<=4)
     {
      System.out.println(" Error**** freqindex=" + freqindex+"  str_us="+str_us);
      continue;
     }
     String strfreq=str_us.substring(1, freqindex);
     
     int freq=Integer.valueOf(strfreq);
     if(freq>13000||freq<3000)
     {
      System.out.println("Error****  freq==" + strfreq);
      //continue;
     }else{
     strnew[count]=all[i].substring(first, end);
     count++;
     }
     break;
    }
   }
  }
  
  try {
   FileWriter fw = new FileWriter(filepath_common,true);    
   String allstr="";
   for(int i=0;i15)
    {
     System.out.println("Error:****"+filepath_common+"****"+strnew[i]);
    }else{
    fw.write(strnew[i]+"\n",0,lens+1);
    }  
   }
   fw.flush(); 
  }catch(Exception e)
  {
   System.out.println(e.toString());
  }
  String_toandroid_file(strnew,count);
 }
 
 /*
  * 将数据保存为需要的android  xml数据
  * 数据原样为<12345>V*67890
  *   1.先替换<> 数据变为    
  * 
  * */
 private static void String_toandroid_file(String allstr[],int count)
 {
  int size=allstr.length;
  
  for(int i=0;iH*1550
  String str=allstr[i];
  str=str.replaceAll( "<","","000\" symbol_rate=\"");
  String strw[]=new String[2];
  
  int index=str.indexOf('*');
  strw[0]=str.substring(0, index);
  strw[1]=str.substring(index+1, str.length());
  
  int length=strw[0].length();
  
  String strq=strw[0].substring(length-1, length);
  String stra=strw[0].substring(0,length-1);
  stra+=""+strw[1]+"000\"";
  if(strq.equals("H")||strq.equals("L"))
  {
  stra+= " polarisation=\"H\"/>";
  }else
  {
  stra+= " polarisation=\"V\"/>";
  }
  stra+="\n";
  allstr[i]=stra;
  }
  
  try {
   FileWriter fw = new FileWriter(filepath_android,true);    
   //String allstr="";
   for(int i=0;i

转载于:https://my.oschina.net/u/865093/blog/372272

你可能感兴趣的:(lyngsat网站卫星数据解析)