modif DataCsv.java et repertoir test
This commit is contained in:
parent
4dc4794500
commit
7cca3b7522
4 changed files with 68 additions and 10 deletions
|
|
@ -1,8 +1,13 @@
|
||||||
package fr.myny.data;
|
package fr.myny.data;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
public class DataCsv {
|
public class DataCsv {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Le constructeur de DataCsv
|
* Le constructeur de DataCsv
|
||||||
*/
|
*/
|
||||||
|
|
@ -13,7 +18,51 @@ public class DataCsv {
|
||||||
/**
|
/**
|
||||||
* La methode de recuperation dun fichier csv
|
* La methode de recuperation dun fichier csv
|
||||||
*/
|
*/
|
||||||
public void getCsv(){
|
public void getCsv() throws IOException{
|
||||||
|
String fileZip = "src/main/java/resources/loto_201911.zip";
|
||||||
|
File desDir = new File("src/main/java/resources/");
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
ZipInputStream zis = new ZipInputStream(new FileInputStream(fileZip));
|
||||||
|
ZipEntry zipEntry = zis.getNextEntry();
|
||||||
|
while (zipEntry != null){
|
||||||
|
File newFile = newFile(desDir, zipEntry);
|
||||||
|
if (zipEntry.isDirectory()){
|
||||||
|
if (!newFile.isDirectory() && !newFile.mkdirs()){
|
||||||
|
throw new IOException("Failed to create directory " + newFile);
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
File parent = newFile.getParentFile();
|
||||||
|
if (!parent.isDirectory() && !parent.mkdirs()) {
|
||||||
|
throw new IOException("Failed to create directory " + parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileOutputStream fos = new FileOutputStream(newFile);
|
||||||
|
int len;
|
||||||
|
while ((len = zis.read(buffer)) > 0){
|
||||||
|
fos.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
zipEntry = zis.getNextEntry();
|
||||||
|
}
|
||||||
|
zis.closeEntry();
|
||||||
|
zis.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Methode d'extraction de fichier zip
|
||||||
|
*/
|
||||||
|
public File newFile(File destinationDir, ZipEntry zipEntry) throws IOException{
|
||||||
|
File destFile = new File(destinationDir, zipEntry.getName());
|
||||||
|
|
||||||
|
String destDirPath = destinationDir.getCanonicalPath();
|
||||||
|
String destFilePath = destFile.getCanonicalPath();
|
||||||
|
|
||||||
|
if (!destFilePath.startsWith(destDirPath + File.separator)){
|
||||||
|
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return destFile;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,8 @@ public class ImportData {
|
||||||
*/
|
*/
|
||||||
public void getUrl(){
|
public void getUrl(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unzip() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
public class test{
|
|
||||||
public static void main(String[] args){
|
|
||||||
System.out.println("Il n'y a rien a voir !");
|
|
||||||
System.out.println("nico fait un test");
|
|
||||||
System.out.println("Il Je test les branchs");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
12
src/test/java/fr/myny/data/DataCsvTest.java
Normal file
12
src/test/java/fr/myny/data/DataCsvTest.java
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
package fr.myny.data;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
class DataCsvTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getCsv() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in a new issue