ComposantsComponents › Fichier › GestionFile › Management
Crée un fichier vide au nom unique dans un dossier, et donne son chemin dans la variable globale FILEPATH. Par défaut, le fichier est supprimé quand le job s'arrête, même sur une erreur. C'est la place d'un fichier de travail : écrit par un composant du job, relu par un autre, sans rien laisser derrière.
Creates an empty file with a unique name in a folder, and gives its path in the FILEPATH global variable. By default, the file is deleted when the job stops, even on an error. It is the place for a work file: written by one component of the job, read by another, leaving nothing behind.
EntréeInput
Aucune : il peut commencer un sous-job. Sinon un lien Iterate (un fichier par itération). None: it can start a subjob. Otherwise one Iterate link (one file per iteration).
SortieOutput
aucunenone pas de flux : le chemin du fichier est dans FILEPATH.no flow: the path of the file is in FILEPATH.
Déclencheurs en sortieOutput triggers
On Subjob Ok On Subjob Error On Component Ok On Component Error Run if
On Subjob : seulement quand il commence son sous-job. On Subjob: only when it starts its subjob.
Le tFileOutputDelimited écrit dans ((String) globalMap.get("tCreateTemporaryFile_1_FILEPATH")), un composant suivant relit le fichier ; il disparaît à la fin du job. Attention à l'option du tFileOutputDelimited qui refuse un fichier existant : voir l'exemple.
The tFileOutputDelimited writes to ((String) globalMap.get("tCreateTemporaryFile_1_FILEPATH")), a following component reads the file again; it disappears at the end of the job. Beware of the tFileOutputDelimited option that refuses an existing file: see the example.
"orders_", "csv".
Choose the Directory of the file, or check Use default temporary system directory. Keep Prefix and Suffix, or adapt them: "orders_", "csv".
FILEPATH.
Connect it to the subjob that uses the file with On Subjob Ok, and give its components the FILEPATH path.
Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Le composant n'a pas de paramètres avancés propres. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. The component has no advanced settings of its own.
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Effacer les fichiers lorsque l'exécution est terminéeRemove file when execution is overREMOVE | OuiYes | ToujoursAlways | Supprime le fichier quand la machine Java du job s'arrête, que le job réussisse ou échoue. Pas à la fin du sous-job : tous les sous-jobs suivants peuvent s'en servir. Décoché, le fichier reste. Deletes the file when the Java machine of the job stops, whether the job succeeds or fails. Not at the end of the subjob: all the following subjobs can use it. Unchecked, the file stays. |
| Utiliser le répertoire temporaire système par défautUse default temporary system directoryUSE_DEFAULT_DIR | NonNo | ToujoursAlways |
Crée le fichier dans le dossier temporaire de Java (java.io.tmpdir) ; sous Windows, celui de l'utilisateur, C:\Users\…\AppData\Local\Temp\.
Creates the file in the Java temporary folder (java.io.tmpdir); on Windows, the one of the user, C:\Users\…\AppData\Local\Temp\.
|
| RépertoireDirectoryDIRECTORY | chemin par défaut des composantscomponent default path | Répertoire temporaire système décochéDefault temporary directory unchecked | Le dossier du fichier, en expression Java. Il est créé s'il n'existe pas, et n'est pas supprimé avec le fichier. The folder of the file, as a Java expression. It is created if it does not exist, and is not deleted with the file. |
| Utiliser le préfixeUse PrefixUSE_PREFIX | OuiYes | ToujoursAlways |
Coché : le nom est le Préfixe, un grand nombre tiré au hasard, puis le Suffixe (talend_2525663917502522978.tmp). Décoché : le nom vient du Modèle ; une note de l'onglet le dit déprécié.
Checked: the name is the Prefix, a large random number, then the Suffix (talend_2525663917502522978.tmp). Unchecked: the name comes from the Template; a note in the tab says it is deprecated.
|
| ModèleTemplateTEMPLATE | "talend_XXXX" |
Utiliser le préfixe décochéUse Prefix unchecked |
Le nom sans extension. XXXX est remplacé par quatre lettres ou chiffres majuscules tirés au hasard (orders_UM15) ; plusieurs XXXX reçoivent les mêmes. Sans XXXX, le nom est fixe : voir les pièges.
The name without extension. XXXX is replaced with four random upper-case letters or digits (orders_UM15); several XXXX get the same ones. Without XXXX, the name is fixed: see the pitfalls.
|
| PréfixePrefixPREFIX | "talend_" |
Utiliser le préfixe cochéUse Prefix checked | Le début du nom : au moins trois caractères, sinon le job s'arrête. The start of the name: at least three characters, otherwise the job stops. |
| SuffixeSuffixSUFFIX | "tmp" |
ToujoursAlways |
L'extension, sans le point. Les points écrits sont retirés : ".tar.gz" donne .targz. Vide : .tmp.
The extension, without the dot. The dots written are removed: ".tar.gz" gives .targz. Empty: .tmp.
|
\.Full path of the created file, available after the component; on Windows with \.((String) globalMap.get("tCreateTemporaryFile_1_FILEPATH"))
Sauf mention contraire, Répertoire : context.folder + "/tmp", avec la variable de contexte folder raccourcie ici en C:/work, comme dans les sorties. Un tJava relié par On Subjob Ok affiche le fichier. Les sorties sont celles de la console, copiées depuis une exécution du job sous Windows ; les nombres et lettres tirés au hasard changent à chaque fois.
Unless stated otherwise, Directory: context.folder + "/tmp", with the folder context variable shortened here to C:/work, as in the outputs. A tJava connected with On Subjob Ok prints the file. The outputs are the console ones, copied from a run of the job on Windows; the random numbers and letters change every time.
String path = (String) globalMap.get("tCreateTemporaryFile_1_FILEPATH");
java.io.File f = new java.io.File(path);
System.out.println("FILEPATH: " + path);
System.out.println("Exists: " + f.exists() + ", " + f.length() + " bytes");
Le dossier tmp n'existe pas encore.
The tmp folder does not exist yet.
FILEPATH: C:\work\tmp\talend_2525663917502522978.tmp Exists: true, 0 bytes
Après le job, tmp existe et il est vide. Avec Effacer les fichiers… décoché, le fichier y reste.
After the job, tmp exists and is empty. With Remove file… unchecked, the file stays in it.
Utiliser le répertoire temporaire système par défaut coché. Le tJava affiche en plus System.getProperty("java.io.tmpdir").
Use default temporary system directory checked. The tJava also prints System.getProperty("java.io.tmpdir").
FILEPATH: C:\Users\User\AppData\Local\Temp\talend_15786460422076783585.tmp Exists: true, 0 bytes java.io.tmpdir: C:\Users\User\AppData\Local\Temp\
Le fichier n'existe plus après le job. The file no longer exists after the job.
Quatre tCreateTemporaryFile enchaînés : 1, suffixe "" ; 2, suffixe ".tar.gz" ; 3, Utiliser le préfixe décoché, modèle "report_XXXX", suffixe "" ; 4, modèle "orders_XXXXXXXX", suffixe "csv".
Four chained tCreateTemporaryFile: 1, suffix ""; 2, suffix ".tar.gz"; 3, Use Prefix unchecked, template "report_XXXX", suffix ""; 4, template "orders_XXXXXXXX", suffix "csv".
for (int i = 1; i <= 4; i++) {
String path = (String) globalMap.get("tCreateTemporaryFile_" + i + "_FILEPATH");
System.out.println("tCreateTemporaryFile_" + i + ": " + new java.io.File(path).getName());
}
tCreateTemporaryFile_1: talend_14321540864488665396.tmp tCreateTemporaryFile_2: talend_1208886972137487584.targz tCreateTemporaryFile_3: report_H4EN.tmp tCreateTemporaryFile_4: orders_MMYDMMYD.csv
Le deuxième perd ses points ; le quatrième répète les mêmes quatre caractères. The second loses its dots; the fourth repeats the same four characters.
tLoop de 1 à 3 ; modèle "part_XXXX", suffixe "csv".
tLoop from 1 to 3; template "part_XXXX", suffix "csv".
System.out.println(globalMap.get("tLoop_1_CURRENT_VALUE") + ": " + new java.io.File(
(String) globalMap.get("tCreateTemporaryFile_1_FILEPATH")).getName());
1: part_OBHH.csv 2: part_JAD7.csv 3: part_VJR4.csv
Deux lignes (id, amount). tFileOutputDelimited : nom de fichier ((String) globalMap.get("tCreateTemporaryFile_1_FILEPATH")), séparateur ";". tJava_1 relit le fichier :
Two rows (id, amount). tFileOutputDelimited: file name ((String) globalMap.get("tCreateTemporaryFile_1_FILEPATH")), separator ";". tJava_1 reads the file again:
String path = (String) globalMap.get("tCreateTemporaryFile_1_FILEPATH");
for (String line : java.nio.file.Files.readAllLines(java.nio.file.Paths.get(path))) {
System.out.println(line);
}
Avec les réglages par défaut du tFileOutputDelimited, le job s'arrête (code 1) : le fichier existe déjà, puisque le tCreateTemporaryFile l'a créé. Le nom du job est remplacé par MyJob, la trace abrégée :
With the default settings of the tFileOutputDelimited, the job stops (code 1): the file already exists, since the tCreateTemporaryFile created it. The job name is replaced with MyJob, the trace shortened:
Exception in component tFileOutputDelimited_1 (MyJob) java.lang.RuntimeException: The particular file "C:\work\tmp\talend_17472556379543180334.tmp" already exist. If you want to overwrite the file, please uncheck the "Throw an error if the file already exist" option in Advanced settings. at demo.myjob_0_1.MyJob.tFixedFlowInput_1Process(MyJob.java:962) …
Avec Retourner une erreur si le fichier existe déjà décoché (paramètres avancés du tFileOutputDelimited) : With Throw an error if the file already exist unchecked (advanced settings of the tFileOutputDelimited):
1;120 2;80
Le fichier, écrit puis relu, est supprimé à la fin du job. The file, written then read, is deleted at the end of the job.
Le tJava qui suit le tCreateTemporaryFile affiche le fichier puis lève une exception (throw new RuntimeException("Stop here") dans un if). Le nom du job est remplacé par MyJob, la trace abrégée :
The tJava that follows the tCreateTemporaryFile prints the file then throws an exception (throw new RuntimeException("Stop here") inside an if). The job name is replaced with MyJob, the trace shortened:
FILEPATH: C:\work\tmp\talend_1409972780494599725.tmp Exists: true, 0 bytes Exception in component tJava_1 (MyJob) java.lang.RuntimeException: Stop here at demo.myjob_0_1.MyJob.tJava_1Process(MyJob.java:624) …
Le job s'arrête avec le code 1, et tmp est vide ensuite : le fichier a été supprimé à l'arrêt de la machine Java.
The job stops with code 1, and tmp is empty afterwards: the file was deleted when the Java machine stopped.
XXXXTemplate without XXXX
Utiliser le préfixe décoché, modèle "lock", suffixe "txt". tmp/lock.txt existe déjà et contient keep me (8 octets).
Use Prefix unchecked, template "lock", suffix "txt". tmp/lock.txt already exists and holds keep me (8 bytes).
FILEPATH: C:\work\tmp\lock.txt Exists: true, 8 bytes
Pas d'erreur : le fichier existant est repris, avec son contenu, et il n'est pas supprimé à la fin du job, même avec Effacer les fichiers… coché. Gardez XXXX dans le modèle, ou le mode préfixe.
No error: the existing file is taken, with its content, and it is not deleted at the end of the job, even with Remove file… checked. Keep XXXX in the template, or the prefix mode.
Préfixe : "ab". Le nom du job est remplacé par MyJob, la trace abrégée :
Prefix: "ab". The job name is replaced with MyJob, the trace shortened:
Exception in component tCreateTemporaryFile_1 (MyJob) java.lang.IllegalArgumentException: Prefix string "ab" too short: length must be at least 3 at java.base/java.io.File.createTempFile(File.java:2157) …
Le job s'arrête avec le code 1. La règle vient de Java (File.createTempFile) ; elle ne vaut pas pour le modèle.
The job stops with code 1. The rule comes from Java (File.createTempFile); it does not apply to the template.
La suppression utilise deleteOnExit de Java : elle a lieu quand la machine Java se termine normalement, après une réussite comme après une erreur. Un processus tué de force ne supprime rien : le fichier reste dans le dossier.
The deletion uses Java deleteOnExit: it happens when the Java machine ends normally, after a success as after an error. A process killed by force deletes nothing: the file stays in the folder.
Le dossier temporaire du système est partagé par tous les programmes. Un Répertoire réservé aux fichiers de travail du job (context.folder + "/tmp") se surveille et se nettoie plus facilement, par exemple avec un tFileDelete en début de job.
The system temporary folder is shared by all the programs. A Directory kept for the work files of the job (context.folder + "/tmp") is easier to watch and clean, for example with a tFileDelete at the start of the job.
Le composant crée le fichier, vide. Le composant qui écrit dedans doit accepter un fichier existant : pour un tFileOutputDelimited, décochez Retourner une erreur si le fichier existe déjà. The component creates the file, empty. The component that writes to it must accept an existing file: for a tFileOutputDelimited, uncheck Throw an error if the file already exist.
Pour un fichier vide à un endroit choisi, qui ne disparaît pas, prenez plutôt un tFileTouch.
For an empty file at a chosen place, which does not disappear, take a tFileTouch instead.
tFileTouch · créer un fichier vide qui restecreate an empty file that staystFileDelete · supprimer un fichier ou un dossierdelete a file or a foldertFileCopy · copier ou déplacer un fichiercopy or move a filetHashOutput · tHashInput · garder des lignes en mémoire plutôt que dans un fichierkeep rows in memory rather than in a filetLoop · boucle For ou WhileFor or While loop