Skip to content
Snippets Groups Projects
Commit c6c9da6e authored by ella's avatar ella
Browse files

envoi de fichier par java nio

parent 7a8f5408
No related branches found
No related tags found
No related merge requests found
Pipeline #6493 passed with stages
in 1 minute and 5 seconds
......@@ -66,6 +66,14 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.kie.commons</groupId>
<artifactId>kie-nio2-api</artifactId>
<version>6.0.0.Beta3</version>
</dependency>
</dependencies>
......
package fr.cines.pacit.transfer.impl;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.dataformat.zipfile.ZipSplitter;
public class TransferCamelImpl extends RouteBuilder {
public class TransferCamelImpl {
String url ;
String localPath ;
String fileName = "vitam-data-test-master";
public void configure() throws IOException {
public void downloadFile(String url, String fileName) throws IOException
{
from("direct:start")
.to(url)
// on dezippe le fichier
.split(new ZipSplitter()).streaming()
.process(new UnzipEntryProcessor())
.to(localPath).end();
URL ulr = new URL(url);
FileOutputStream fileOutputStream = new FileOutputStream(fileName);
FileChannel fileChannel = fileOutputStream.getChannel();
ReadableByteChannel readableByteChannel = Channels.newChannel(ulr.openStream());
fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
}
}
public TransferCamelImpl(String url, String localPath) {
this.url = url ;
this.localPath = localPath ;
}
......
......@@ -50,17 +50,16 @@ public class TransferImpl implements Transfer{
@Override
public List<Path> getTestFiles() {
Main main = new Main();
main.configure().addRoutesBuilder(new TransferCamelImpl(url,localPath));
try {
main.run();
TransferCamelImpl p = new TransferCamelImpl(url, localPath) ;
try {
p.downloadFile(url, localPath);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print("fin telechargement du fichier ..........");
} catch (Exception e) {
e.printStackTrace();
}
return listFile(new File(localPath));
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment