package org.josast.SIDS.app;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.josast.SIDS.SIDSData;
import org.josast.SIDS.Station;

public class SendFile {

	  SIDSData sids = new SIDSData();
	 BufferedReader lecteurAvecBuffer = null;
	 String ligne;
	 
	public void initSIDS ()
	{

		sids.setStation(new Station());
		sids.setNoradID(99990);
	}
	
	public void OpenFile(String file)
	{
		try
	      {
		lecteurAvecBuffer = new BufferedReader(new FileReader(file));
	      }
	    catch(FileNotFoundException exc)
	      {
		System.out.println("Erreur d'ouverture");
	      }
	}
	
	
	public void  readFile ()  
	{
		boolean first = false;
		Date dateref=null;
		try {
			while ((ligne = lecteurAvecBuffer.readLine()) != null)
			{
			//      System.out.println(ligne);
			String[] result1=ligne.split("=");
			String[] date = result1[1].split("]");
			String[] trame = result1[2].split("]");

			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("E MMM dd hh:mm:ss z yyyy",Locale.ENGLISH);

			System.out.println("date : "+date[0]+" - Trame "+trame[0]);
			Date date2 = simpleDateFormat.parse(date[0]);
			if (first==false)
			{
				dateref=date2;
				first = true;
			}
			else 
			{
				System.out.println((date2.getTime() - dateref.getTime())/1000);
			}
				
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		  }

	public void closeFile()
	{
	    try {
			lecteurAvecBuffer.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	 public static void main(String[] argv) throws IOException
	  {
	   
		 SendFile sf = new SendFile();
		 sf.OpenFile(argv[0]);
		 sf.initSIDS();
		 sf.readFile();
		 sf.closeFile();
		 
		 
		 
	  }
	    
	    
	
	
}
