modif sur les datas csv
This commit is contained in:
parent
30e127bbe8
commit
d01c4765eb
3 changed files with 34 additions and 18 deletions
|
|
@ -10,25 +10,38 @@ import java.util.zip.ZipInputStream;
|
|||
public class DataCsv {
|
||||
|
||||
protected String destination;
|
||||
private ImportData imp;
|
||||
|
||||
/**
|
||||
* Le constructeur de DataCsv
|
||||
* Constructeur par defaut
|
||||
* @throws IOException
|
||||
*/
|
||||
public DataCsv(){
|
||||
this.destination = "src/test/resources/CsvFile";
|
||||
ImportData imp = new ImportData("https://www.fdj.fr/jeux-de-tirage/loto/statistiques");
|
||||
public DataCsv() throws IOException {
|
||||
this.destination = "src/main/resources/Download";
|
||||
ImportData imp = new ImportData("https://www.fdj.fr/jeux-de-tirage/loto/statistiques", this.destination);
|
||||
|
||||
}
|
||||
|
||||
public DataCsv(String s){
|
||||
/**
|
||||
* Constructeur avec deux parametres
|
||||
* @param s repertoire de destination
|
||||
* @throws IOException
|
||||
*/
|
||||
public DataCsv(String s) throws IOException {
|
||||
this.destination = s;
|
||||
ImportData imp = new ImportData("https://www.fdj.fr/jeux-de-tirage/loto/statistiques");
|
||||
imp = new ImportData("https://www.fdj.fr/jeux-de-tirage/loto/statistiques", this.destination);
|
||||
|
||||
for (String name : imp.tabNameZip) {
|
||||
name = this.destination.concat(name);
|
||||
getCsv(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* La methode de recuperation dun fichier csv
|
||||
* @param fileZip : nom suivit du chemin du fichier zip
|
||||
*/
|
||||
public void getCsv(String fileZip) throws IOException{
|
||||
private void getCsv(String fileZip) throws IOException{
|
||||
File desDir = new File(destination);
|
||||
byte[] buffer = new byte[1024];
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
|
||||
|
|
@ -75,5 +88,4 @@ public class DataCsv {
|
|||
|
||||
return destFile;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,13 @@ package fr.myny.data;
|
|||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ImportData {
|
||||
|
||||
protected String url;
|
||||
protected String repDes;
|
||||
public ArrayList<String> tabNameZip;
|
||||
|
||||
/**
|
||||
* Le constructeur de ImportData
|
||||
|
|
@ -15,19 +17,20 @@ public class ImportData {
|
|||
*/
|
||||
ImportData(){
|
||||
this.url = "https://www.fdj.fr/jeux-de-tirage/loto/statistiques";
|
||||
this.repDes = "src/test/resources/Download/";
|
||||
this.repDes = "src/main/resources/Download/";
|
||||
tabNameZip = new ArrayList<>();
|
||||
DownloadCsvZip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Le constructeur de ImportData
|
||||
* @param url string contenant l URL dou recuperer les fichiers csv
|
||||
*/
|
||||
public ImportData(String url){
|
||||
public ImportData(String url, String des){
|
||||
this.url=url;
|
||||
}
|
||||
|
||||
public void getUrl() {
|
||||
|
||||
this.repDes = des;
|
||||
tabNameZip = new ArrayList<>();
|
||||
DownloadCsvZip();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,6 +69,7 @@ public class ImportData {
|
|||
if (urlZipLink.length() > 128) {
|
||||
if (test.equals(urlZipLink.substring(50, 55))) {
|
||||
nameZip = urlZipLink.substring(50,65);
|
||||
tabNameZip.add(nameZip);
|
||||
urlZipLink = urlZipLink.substring(13,65);
|
||||
try (BufferedInputStream bis = new BufferedInputStream(new URL(urlZipLink).openStream());
|
||||
FileOutputStream fos = new FileOutputStream(repDes + nameZip)) {
|
||||
|
|
|
|||
Reference in a new issue