ComposantsComponents › Fichier › SortieFile › Output
Écrit dans un fichier la valeur de l'unique colonne content, telle quelle : un texte avec l'encodage choisi, un tableau d'octets ou un flux d'entrée Java sans aucune conversion, sans séparateur ni fin de ligne. Chaque ligne reçue remplace le fichier. À choisir pour écrire un document entier contenu dans une seule valeur : une page, une réponse d'un service, une image, un fichier binaire.
Writes to a file the value of the single content column, as is: a text with the chosen encoding, a byte array or a Java input stream without any conversion, without separator or line end. Each row received replaces the file. Choose it to write a whole document held in a single value: a page, a service response, an image, a binary file.
EntréeInput
Main un flux, obligatoire, avec une colonne contentone flow, required, with a content column
SortieOutput
Main un flux, facultatif : les lignes repartent telles quellesone flow, optional: the rows go on unchanged
Déclencheurs en sortieOutput triggers
On Component Ok On Component Error Run if
Le tMap range la valeur à écrire (texte de la réponse, octets d'une pièce jointe) dans la colonne content, de type Object.
The tMap puts the value to write (response text, bytes of an attachment) into the content column, of type Object.
Le nom de fichier n'est calculé qu'une fois, au démarrage du composant : pour un fichier par ligne, il faut une itération par ligne, chacune avec son nom (voir les conseils). The file name is computed only once, when the component starts: for one file per row, one iteration per row is needed, each one with its name (see the tips).
content : c'est elle que le composant lit, par son nom.
Connect to it a flow that has a content column: it is the one the component reads, by its name.
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 |
|---|---|---|---|
| SchémaSchemaSCHEMA | content (Object) |
ToujoursAlways |
Fixe : une seule colonne, content, de type Object, en lecture seule. Le composant lit la colonne de ce nom dans le lien entrant.
Fixed: a single column, content, of type Object, read only. The component reads the column with this name in the incoming link.
|
| Nom de fichierFilenameFILENAME | chemin par défaut + /out.txtdefault path + /out.txt |
ToujoursAlways | Le fichier écrit, en expression Java, calculée une fois au démarrage du composant. Ses dossiers sont créés au besoin, toujours. Il est remplacé à chaque ligne reçue : il ne garde que la dernière (voir l'exemple). The written file, as a Java expression, computed once when the component starts. Its folders are created if needed, always. It is replaced at each row received: it keeps only the last one (see the example). |
| EncodageEncodingENCODING | "ISO-8859-15" |
ToujoursAlways | L'encodage d'un texte écrit. Sans effet sur un tableau d'octets ou un flux, écrits tels quels. The encoding of a written text. No effect on a byte array or a stream, written as is. |
| Arrêter en cas d'erreurDie on errorDIE_ON_ERROR | NonNo | ToujoursAlways | Décochée, une erreur d'écriture est seulement affichée sur la sortie d'erreur, et le job continue. Cochée, elle arrête le job. Voir les erreurs. Unchecked, a write error is only printed on the error output, and the job goes on. Checked, it stops the job. See the errors. |
toString()), avec l'Encodage.
Other object (Integer, Date…): its Java text (toString()), with the Encoding.
Aucune fin de ligne n'est ajoutée. No line end is added.
((String) globalMap.get("tFileOutputRaw_1_FILENAME_PATH"))
((String) globalMap.get("tFileOutputRaw_1_ERROR_MESSAGE"))
Dans chaque exemple, un tFixedFlowInput en mode tableau, de schéma content (Object), envoie la valeur au tFileOutputRaw ; la valeur est une expression Java. Les chemins sont écrits à partir de la variable de contexte folder, raccourcie ici en C:/data ; le dossier raw n'existait pas. Un tJava relié par On Subjob Ok affiche les fichiers ; les sorties sont celles de la console, copiées depuis une exécution du job.
In each example, a tFixedFlowInput in table mode, with a content (Object) schema, sends the value to the tFileOutputRaw; the value is a Java expression. Paths are written from the folder context variable, shortened here to C:/data; the raw folder did not exist. A tJava connected with On Subjob Ok prints the files; the outputs are the console ones, copied from a run of the job.
content vaut "Café 10 €", nom context.folder + "/out/raw/text.txt".
tFileOutputRaw_1: content is "Café 10 €", name context.folder + "/out/raw/text.txt".
content vaut "Café 10 €".getBytes(java.nio.charset.StandardCharsets.UTF_8), nom context.folder + "/out/raw/bytes.bin".
tFileOutputRaw_2: content is "Café 10 €".getBytes(java.nio.charset.StandardCharsets.UTF_8), name context.folder + "/out/raw/bytes.bin".
ISO-8859-15) pour les deux.
Default encoding (ISO-8859-15) for both.
Le tJava_1 affiche les octets des deux fichiers en hexadécimal, puis FILENAME_PATH : tJava_1 prints the bytes of both files in hexadecimal, then FILENAME_PATH:
for (String f : new String[] {"/out/raw/text.txt", "/out/raw/bytes.bin"}) {
StringBuilder sb = new StringBuilder();
for (byte b : java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(context.folder + f))) {
sb.append(String.format("%02X ", b));
}
System.out.println(f.substring(f.lastIndexOf('/') + 1) + ": " + sb.toString().trim());
}
System.out.println("FILENAME_PATH: " + globalMap.get("tFileOutputRaw_1_FILENAME_PATH"));
text.txt: 43 61 66 E9 20 31 30 20 A4 bytes.bin: 43 61 66 C3 A9 20 31 30 20 E2 82 AC FILENAME_PATH: C:/data/out/raw/text.txt
Le texte est écrit en ISO-8859-15 (é = E9, € = A4) ; les octets UTF-8 sont écrits tels quels, l'encodage du composant ne les touche pas. Aucun des deux fichiers ne finit par une fin de ligne, et le dossier raw a été créé.
The text is written in ISO-8859-15 (é = E9, € = A4); the UTF-8 bytes are written as is, the component encoding does not touch them. Neither file ends with a line end, and the raw folder was created.
Trois lignes, "first", "second", "third", vers context.folder + "/out/raw/rows.txt". Le tLogRow affiche les lignes qui repartent, puis le tJava affiche le fichier :
Three rows, "first", "second", "third", to context.folder + "/out/raw/rows.txt". The tLogRow prints the rows that go on, then the tJava prints the file:
System.out.println(new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(context.folder + "/out/raw/rows.txt"))));
first second third third
Les trois lignes passent au tLogRow, mais chacune a remplacé le fichier : il ne contient que third.
The three rows go on to the tLogRow, but each one replaced the file: it only holds third.
Trois sous-jobs, un fichier chacun. stream.bin : new java.io.ByteArrayInputStream(new byte[] {72, 105, 33}). number.txt : Integer.valueOf(42). null.txt : null.
Three subjobs, one file each. stream.bin: new java.io.ByteArrayInputStream(new byte[] {72, 105, 33}). number.txt: Integer.valueOf(42). null.txt: null.
for (String name : new String[] {"stream.bin", "number.txt", "null.txt"}) {
java.nio.file.Path path = java.nio.file.Paths.get(context.folder + "/out/raw/" + name);
System.out.println(name + ": " + (java.nio.file.Files.exists(path) ? new String(java.nio.file.Files.readAllBytes(path)) : "absent"));
}
stream.bin: Hi! number.txt: 42 null.txt: absent
Le flux est recopié octet par octet (72 105 33 = Hi!), le nombre écrit en texte ; la valeur nulle ne crée pas de fichier.
The stream is copied byte by byte (72 105 33 = Hi!), the number written as text; the null value creates no file.
Le nom de fichier désigne un dossier qui existe, context.folder + "/out/raw/dir". Le nom du job est remplacé par MyJob, le dossier de travail par C:\data ; la trace d'exception est abrégée.
The file name points to a folder that exists, context.folder + "/out/raw/dir". The job name is replaced with MyJob, the working folder with C:\data; the exception trace is shortened.
Un tJava relié par On Subjob Ok affiche ensuite ERROR_MESSAGE : A tJava connected with On Subjob Ok then prints ERROR_MESSAGE:
System.out.println("ERROR_MESSAGE: " + globalMap.get("tFileOutputRaw_1_ERROR_MESSAGE"));
java.io.IOException: File 'C:\data\out\raw\dir' exists but is a directory ERROR_MESSAGE: File 'C:\data\out\raw\dir' exists but is a directory
La première ligne est sur la sortie d'erreur ; rien n'a été écrit, et pourtant le sous-job est réussi et le job se termine avec le code 0. Testez ERROR_MESSAGE, ou cochez la case, si l'écriture doit être garantie. The first line is on the error output; nothing was written, yet the subjob succeeds and the job ends with exit code 0. Test ERROR_MESSAGE, or check the box, if the write must be guaranteed.
Même job : il s'arrête (code 1) et le tJava ne s'exécute pas. Same job: it stops (exit code 1) and the tJava does not run.
Exception in component tFileOutputRaw_1 (MyJob) java.io.IOException: File 'C:\data\out\raw\dir' exists but is a directory at org.apache.commons.io.FileUtils.openOutputStream(FileUtils.java:2427) …
Toutes les lignes d'un flux vont dans le même fichier, et chacune remplace la précédente. Pour un fichier par ligne, passez par une itération (tFlowToIterate, tLoop…) et mettez une variable de l'itération dans le nom du fichier : il est recalculé à chaque itération (essayé avec "loop_" + ((Integer) globalMap.get("tLoop_1_CURRENT_VALUE")) + ".txt"). Pour une ligne de fichier par ligne du flux, prenez tFileOutputDelimited.
All the rows of a flow go to the same file, and each one replaces the previous one. For one file per row, go through an iteration (tFlowToIterate, tLoop…) and put a variable of the iteration in the file name: it is computed again at each iteration (tried with "loop_" + ((Integer) globalMap.get("tLoop_1_CURRENT_VALUE")) + ".txt"). For one file line per flow row, take tFileOutputDelimited.
Avec Arrêter en cas d'erreur décoché, un fichier impossible à écrire ne fait pas échouer le job : seule une ligne sur la sortie d'erreur le signale. Cochez la case dans un job planifié. With Die on error unchecked, a file that cannot be written does not make the job fail: only a line on the error output reports it. Check the box in a scheduled job.
Pour une image, un PDF ou une archive, donnez à content un byte[] ou un InputStream : ils sont écrits sans conversion. Un texte lu depuis des octets puis réécrit passerait par l'encodage, et pourrait changer.
For an image, a PDF or an archive, give content a byte[] or an InputStream: they are written without conversion. A text read from bytes then written again would go through the encoding, and could change.
Le défaut est ISO-8859-15, et un caractère qu'il ne connaît pas devient ?. Pour un document JSON ou XML, choisissez "UTF-8".
The default is ISO-8859-15, and a character it does not know becomes ?. For a JSON or XML document, choose "UTF-8".
tFileOutputDelimited · une ligne de fichier par ligne du fluxone file line per flow rowtFileOutputJSON · tFileOutputXML · construire un document à partir des lignesbuild a document from the rowstFileOutputPositional · fichier à positions fixesfixed-width filetFileExist · vérifier que le fichier a été écritcheck that the file was writtentFileArchive · archiver les fichiers écritsarchive the written filestChangeFileEncoding · changer l'encodage d'un fichier textechange the encoding of a text file