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= ""; The folder that the /* handles. Under d:/satdeal/, create folders based on region, each folder below divided into txt common android three sub-folders The data in TXT is the TXT text data saved for the source code of the website. Common for the parsed general data */ //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) { //lists the contents of the current folder, Remove common and Android files 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<size;i++) { filepath=files[i]. GetAbsolutePath (); filepath_common=filepath+ "/common/"; filepath_android=filepath+ "/ Android/"; //system.out.println (" str== " + filepath); dealfile (filepath); } system.out.println (System.currenttimemillis ()); } /* * Delete folder files * */ private static void fileinit () { file file=new file (Filepath_common); file files[]=file.listfiles (); int csize=files.length; for (int i=0;i<csize;i++) { files[i].delete (); } file=new File (filepath_android); files=file.listfiles (); csize=files.length; for (int i=0;i<csize;i++) { files[i].delete (); } } /* * Get the specified txt text start parsing data * 1. Parse <title> contains satellite name and longitude, * 2. Determine the file name * */ private static void dealfile (String) under common and Android 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 ("<title>"); int index2=fis.indexof ("</title>"); string filename=fis.substring (index1+7 , &NBSP;INDEX2). replace (' \ \ ', ' '); filename=filename.replace ('/', ' '); filepath_common+=filename+ ". txt"; filepath_android+=filename+ ". XML "; system.out.println (" filename===== " + filename); <title>Thor 5 at 0.8°w - lyngsat</title> 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 () ; } } /* * processing incoming byte array * rule: 1. First Remove all HVRL characters; * 2. Filter out the first five and last five data the actual incoming data is to < 1024000 * 3. Determine the consecutive four digits or five digits (both the frequency and the sign rate are 4-bit or 5-bit) * Two formats for freq: >123456& and > 1234& * Two formats for &NBSP;&NBSP;&NBSP;SYMB: >12345- and >1234- * Check out with the count indicator: &NBSP;&NBSP;*&NBSp; less than 4 o'clock skip the same number * count==10 4-bit freq * count==11 4 bit symb * count==20 5 bit freq * count==21 5 bit SYMB * 4.freq <> wrap up symb with * #并转行包裹 Returns a valid byte array * * */ 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++; &nBSP;} 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;k<j;k++) { d[k]=c[k]; } return d; } /* * process the resulting data. * cut out string array according to \n valid data is now <12345>V*67890# * Parse array First find vhrl* 's combined positioning < #的位置 * rule : 1. Vhrl for start Top 6 and pre 7 < after 6 7 position # * 2. Cut useful data by location Save As <12345>V*67890 * determine the data * for the inspection and cutting 1. Detection > position should be greater than or equal to 5 and less than or equal to 6 * 2. Judging the number in <> should be in 3Between 000-13000 * * * Parse complete Start storing data to specified folder * */ Private static void dealstr (STRING&NBSP;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<size;i++) { byte bstr[]=all[i].getbytes (); int Len= bstr.length; for (int j=0;j<len;j++) { if ((bstr[j]== ' R ' | | bstr[j]== ' L ' | | bstr[j]== ' H ' | | bstr[j]== ' V ') &&bstr[j+1]== ' * ') { int first=0; int end=0; &nbSp; if (j-7>=0&&bstr[j-7]== ' < ') { first=j-7; } if (j-6>=0&&bstr[j-6]== ' < ') { first=j-6; } if (j+7<len&&bstr[j+7]== ' # ') { end=j+7; } if (j+ 6<len&&bstr[j+6]== ' # ') { end=j+6; } String Str_us=all[i].substring (First, end); //system.out.println ("str_us==" + str_us) int freqindex=str_us.indexof (' > '); &nBsp; 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;i< count;i++) { int lens=strnew[i].length (); if (lens<11| | LENS>15) { 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); } /* * Save the data as needed android XML data * data is <12345>v*67890 * 1. Replace <> data into & NBsp; <transponder frequency= "12345000" symbol_rate= "v*67890 * 2. In the string cut to <transponder frequency= "12345000" symbol_rate= "V 67890 * 3. In cut to <transponder frequency= "12345000" symbol_rate= " v * 4. Patchwork <transponder Frequency= "12345000" symbol_rate= "67890000" * 5. Last <transponder Frequency= "12345000" symbol_rate= "67890000" polarisation= "V"/> * * */ private static void string_toandroid_file (String allstr[],int count) { int size=allstr.length; for (int i=0;i<count;i++) { //<10962>h*1550 string str=allstr[i]; str=str.replaceall ( "<", "<transponder freqUency=\ "") 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<count;i++) { Fw.write (Allstr[i],0,allstr[i].length ()); } fw.flush (); }catch (exception e) { system.out.println (e.toString ()); } }}
Analysis of satellite data of LyngSat website