Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bin;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.util.Calendar;
- import java.util.Scanner;
- public class AdressMode {
- private String name1="",name2="";
- private String line1,line2,tempLine;
- private Scanner input;
- private byte mode=-1;
- private int year;
- private URL dirURLFile=null;
- private int counter=0;
- private BufferedReader dirFile=null;
- public String getLink1(){
- name1="http://www.nbp.pl/kursy/xml/"+line1+".xml";
- return name1;
- }
- public String getLink2(){
- name2="http://www.nbp.pl/kursy/xml/"+line2+".xml";
- return name2;
- }
- public void setMode() throws Exception{
- System.out.println("test");
- input = new Scanner(System.in);
- while(mode<0 ||mode >3){
- System.out.println("Wybierz tryb programu");
- mode = input.nextByte();
- if(mode==1){
- System.out.println("Jestem w setMode = 1");
- modeNewest();
- }
- else if(mode==2){
- modeCustomDate();
- }
- else if(mode==3){
- modeCustomWrite();
- }
- }
- }
- public void AdressMode(){
- }
- private void getCurrentYear(){
- year = Calendar.getInstance().get(Calendar.YEAR);
- }
- public void openFileDir() throws Exception{
- try{
- if(mode==2){
- dirURLFile=new URL("http://www.nbp.pl/kursy/xml/dir"+year+".txt");
- }
- if(mode==1){
- dirURLFile=new URL("http://www.nbp.pl/kursy/xml/dir.txt");
- }
- dirFile = new BufferedReader(new InputStreamReader(dirURLFile.openStream()));
- findLastTablesNames();
- }
- finally{
- if(dirFile!=null){
- dirFile.close();
- }
- }
- }
- public void findLastTablesNames() throws Exception{
- tempLine=dirFile.readLine();
- //System.out.println(name1);
- while(tempLine!=null){
- if(tempLine.contains("a")){
- //System.out.println(name1+name2);
- line2=line1;
- line1=tempLine;
- //System.out.println(name1+name2);
- }
- tempLine=dirFile.readLine();
- System.out.println(line1+" test "+line2);
- }
- }
- public void findTablesByDate() throws Exception{
- openFileDir();
- tempLine=dirFile.readLine();
- }
- public void modeNewest() throws Exception{
- System.out.println("Jestem w modeNewest()");
- openFileDir();
- tempLine=dirFile.readLine();
- while(tempLine!=null){
- if(tempLine.contains(name1)&&tempLine.contains("a")){
- line1=tempLine;
- }
- if(tempLine.contains(name1)&&tempLine.contains("a")){
- line2=tempLine;
- }
- tempLine=dirFile.readLine();
- }
- }
- public void modeCustomDate(){
- input = new Scanner(System.in);
- System.out.println("Wprowadz date 1 pliku (DDMMYY");
- name1=input.nextLine();
- System.out.println("Wprowadz date 2 pliku (DDMMYY");
- name1=input.nextLine();
- }
- public void modeCustomWrite(){
- input = new Scanner(System.in);
- System.out.println("Wprowadz link do pierwszej tabeli:");
- name1=input.nextLine();
- System.out.println("Wprowadz link do drugiej tabeli:");
- name2=input.nextLine();
- }
- }
Add Comment
Please, Sign In to add comment