1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| public class test {
public static void main(String[] args)
{
// TODO Auto-generated method stub
try {
BasicSignerOptions Infiletest = new BasicSignerOptions(); // On appelle la classe basicsigneroptions
Path chemin = Paths.get(Chemin1); //on prend le chemin complet du fichier infile
Path cheminout = Paths.get(Chemin2); // on prend le chemin complet du fichier outfile qui viens d'être signer manuellement
// Le futur but sera de tout d'abord signer un document "manuellement" avec l'appli pour avoir un répertoire d'entrée et de sortie à utiliser
final Path dir = chemin.getParent(); // on prend le répertoire du fichier infile
Path dirout = cheminout.getParent(); // on prend le répertoire du fichier outfile
WatchService watcher = FileSystems.getDefault().newWatchService();
WatchKey key = dir.register(watcher,
StandardWatchEventKinds.ENTRY_CREATE);
for (;;) {
try {
key = watcher.take();
} catch (InterruptedException x) {
return;
}
for (WatchEvent<?> event: key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
WatchEvent<Path> ev = (WatchEvent<Path>)event;
Path filename = ev.context();
String type = Files.probeContentType(filename);
try {
Path child = dir.resolve(filename);
if (!Files.probeContentType(child).equals("application/pdf")) {
System.err.format("New file '%s'" +
" is not a pdf application file.%n", filename);
continue;
}
} catch (IOException x) {
System.err.println(x);
continue;
}
System.out.println("Le fichier est : " + dir+ "\\" + filename ); //Le fichier est : C:\Users\avidegrain\Desktop\repertoire_1\test.pdf
Path FileOut = Paths.get(dirout+ "\\" + filename);
System.out.println("Le fichier Out est : " + FileOut); //Le fichier Out est : C:\Users\avidegrain\Desktop\repertoire_2\test.pdf
Path FileIn = Paths.get(dir+ "\\" + filename);
System.out.println("Le fichier In est : " + FileIn); //Le fichier In est : C:\Users\avidegrain\Desktop\repertoire_1\test.pdf
BasicSignerOptions options = new BasicSignerOptions();
options.setInFile(FileIn.toString()); //BasicSignerOptions.InFile=C:\Users\avidegrain\Desktop\repertoire_1\test.pdf
options.setOutFile(FileOut.toString()); // BasicSignerOptions.OutFile= C:\Users\avidegrain\Desktop\repertoire_2\test.pdf
SignerLogic sl = new SignerLogic(options);
sl.signFile(); //On signe => ECHEC.
//Les print me permettent de vérifier les chemins lors du lancement de l'appli
}
boolean valid = key.reset();
if (!valid) {
break;
}
}
} catch (IOException x) {
System.err.println(x);
}
}
public String FileOut;
public String FileIn;
public int eventest; // Ici on rend les variables public pour les utiliser dans d'autre classe
} |
Partager