<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: [resolved] tLoop with java.util.zip.ZipEntry in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294498#M67367</link>
    <description>Hello 
&lt;BR /&gt;The tLoop componnent use the java logic: for loop or while loop. In you case, it is better to create a routine to exract the files from a zip file and write them into a folder, then use a tFileList to iterate each file, process them, finally, use a tFileDelete to delete the files.
&lt;BR /&gt;Here I create a routine which can be used extract files from a zip file to a folder.
&lt;BR /&gt;
&lt;PRE&gt;package routines;&lt;BR /&gt;import java.io.*;&lt;BR /&gt;import java.util.zip.*;&lt;BR /&gt;public class forum7756 {&lt;BR /&gt;	static final int size = 4096;&lt;BR /&gt;	public static void extractingFileFromZip(String outputFolder) {&lt;BR /&gt;		String path = outputFolder;&lt;BR /&gt;		try {&lt;BR /&gt;			BufferedOutputStream dest = null;&lt;BR /&gt;			FileInputStream fis = new FileInputStream("D:/ttt.zip");&lt;BR /&gt;			ZipInputStream zis = new ZipInputStream(&lt;BR /&gt;					new BufferedInputStream(fis));&lt;BR /&gt;			ZipEntry entry;&lt;BR /&gt;			while ((entry = zis.getNextEntry()) != null) {&lt;BR /&gt;				System.out.println("Extracting: " + entry);&lt;BR /&gt;				int count;&lt;BR /&gt;				byte buffer[] = new byte;&lt;BR /&gt;				// write the files to the disk&lt;BR /&gt;				String filePath = path + entry.getName();&lt;BR /&gt;				File outFile = new File(filePath);&lt;BR /&gt;				if (!outFile.exists()) {&lt;BR /&gt;					outFile.getParentFile().mkdirs();&lt;BR /&gt;				}&lt;BR /&gt;				FileOutputStream fos = new FileOutputStream(outFile);&lt;BR /&gt;				dest = new BufferedOutputStream(fos);&lt;BR /&gt;				while ((count = zis.read(buffer)) != -1) {&lt;BR /&gt;					dest.write(buffer);&lt;BR /&gt;				}&lt;BR /&gt;				dest.flush();&lt;BR /&gt;				dest.close();&lt;BR /&gt;			}&lt;BR /&gt;			zis.close();&lt;BR /&gt;		} catch (Exception e) {&lt;BR /&gt;			e.printStackTrace();&lt;BR /&gt;		}&lt;BR /&gt;	}&lt;BR /&gt;}&lt;/PRE&gt;
&lt;BR /&gt;After creating a routine, you can call it on tJava like this:
&lt;BR /&gt;forum7756.extractingFileFromZip("d:/myFolderPath/");
&lt;BR /&gt;Best regards
&lt;BR /&gt; 
&lt;BR /&gt; shong</description>
    <pubDate>Thu, 13 Aug 2009 06:35:04 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2009-08-13T06:35:04Z</dc:date>
    <item>
      <title>[resolved] tLoop with java.util.zip.ZipEntry</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294497#M67366</link>
      <description>Hi, 
&lt;BR /&gt;I am trying to process zip files "on the fly" which means that I want to get the files in the zip file one by one and process them without unziping the full archive. This means that I need to loop trough the zip file. 
&lt;BR /&gt;I used the tLoop component and set us the following values: 
&lt;BR /&gt;1.Declaration:"java.util.zip.ZipInputStream z = new java.util.zip.ZipInputStream(new java.io.BufferedInputStream(new java.io.FileInputStream("D:/myfile.zip"))); java.util.zip.ZipEntry e = z.getNextEntry()" 
&lt;BR /&gt;2.Condition:"e!=null" 
&lt;BR /&gt;3.Iteration:"e = z.getNextEntry()" 
&lt;BR /&gt;The loop seems to be working fine because when I print in a tJavaFlex component ((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")) it loops exactly as the number of files in the zip file. 
&lt;BR /&gt;My problem is now how to get the ZipEntry value e and process it further (create temporary file, process that file and thzen delete it before moving to the next entry in the zip file). 
&lt;BR /&gt;The tLoop component provides another out value ((Integer)globalMap.get("tLoop_1_CURRENT_VALUE")), but it is of type Integer and I need to get a ZipEntry as an output. 
&lt;BR /&gt;Can someone please help me with some ideas? 
&lt;BR /&gt;Thanks 
&lt;BR /&gt;Magi</description>
      <pubDate>Sat, 16 Nov 2024 13:49:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294497#M67366</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-16T13:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] tLoop with java.util.zip.ZipEntry</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294498#M67367</link>
      <description>Hello 
&lt;BR /&gt;The tLoop componnent use the java logic: for loop or while loop. In you case, it is better to create a routine to exract the files from a zip file and write them into a folder, then use a tFileList to iterate each file, process them, finally, use a tFileDelete to delete the files.
&lt;BR /&gt;Here I create a routine which can be used extract files from a zip file to a folder.
&lt;BR /&gt;
&lt;PRE&gt;package routines;&lt;BR /&gt;import java.io.*;&lt;BR /&gt;import java.util.zip.*;&lt;BR /&gt;public class forum7756 {&lt;BR /&gt;	static final int size = 4096;&lt;BR /&gt;	public static void extractingFileFromZip(String outputFolder) {&lt;BR /&gt;		String path = outputFolder;&lt;BR /&gt;		try {&lt;BR /&gt;			BufferedOutputStream dest = null;&lt;BR /&gt;			FileInputStream fis = new FileInputStream("D:/ttt.zip");&lt;BR /&gt;			ZipInputStream zis = new ZipInputStream(&lt;BR /&gt;					new BufferedInputStream(fis));&lt;BR /&gt;			ZipEntry entry;&lt;BR /&gt;			while ((entry = zis.getNextEntry()) != null) {&lt;BR /&gt;				System.out.println("Extracting: " + entry);&lt;BR /&gt;				int count;&lt;BR /&gt;				byte buffer[] = new byte;&lt;BR /&gt;				// write the files to the disk&lt;BR /&gt;				String filePath = path + entry.getName();&lt;BR /&gt;				File outFile = new File(filePath);&lt;BR /&gt;				if (!outFile.exists()) {&lt;BR /&gt;					outFile.getParentFile().mkdirs();&lt;BR /&gt;				}&lt;BR /&gt;				FileOutputStream fos = new FileOutputStream(outFile);&lt;BR /&gt;				dest = new BufferedOutputStream(fos);&lt;BR /&gt;				while ((count = zis.read(buffer)) != -1) {&lt;BR /&gt;					dest.write(buffer);&lt;BR /&gt;				}&lt;BR /&gt;				dest.flush();&lt;BR /&gt;				dest.close();&lt;BR /&gt;			}&lt;BR /&gt;			zis.close();&lt;BR /&gt;		} catch (Exception e) {&lt;BR /&gt;			e.printStackTrace();&lt;BR /&gt;		}&lt;BR /&gt;	}&lt;BR /&gt;}&lt;/PRE&gt;
&lt;BR /&gt;After creating a routine, you can call it on tJava like this:
&lt;BR /&gt;forum7756.extractingFileFromZip("d:/myFolderPath/");
&lt;BR /&gt;Best regards
&lt;BR /&gt; 
&lt;BR /&gt; shong</description>
      <pubDate>Thu, 13 Aug 2009 06:35:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294498#M67367</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-08-13T06:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] tLoop with java.util.zip.ZipEntry</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294499#M67368</link>
      <description>Thank you. This is exactly what I wanted to avoid (it is may old solution). I cannot aford to extract all the files because of the nature of the project (too many files, too often and there is not enough space to extract and then process). 
&lt;BR /&gt;Isn't there a way to just get the content of the ZipEntry from the loop?
&lt;BR /&gt;Thanks
&lt;BR /&gt;Magi</description>
      <pubDate>Thu, 13 Aug 2009 07:00:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294499#M67368</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-08-13T07:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] tLoop with java.util.zip.ZipEntry</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294500#M67369</link>
      <description>Hello 
&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;
 &lt;TABLE border="1"&gt;
  &lt;TBODY&gt;
   &lt;TR&gt;
    &lt;TD&gt;Isn't there a way to just get the content of the ZipEntry from the loop?&lt;/TD&gt;
   &lt;/TR&gt;
  &lt;/TBODY&gt;
 &lt;/TABLE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;BR /&gt;the current value or the current iterate of tLoop are Integer. So, it is not the correct way to do that with tLoop component.
&lt;BR /&gt;If you just want to return a ZipEntry object, we can return it in routine.
&lt;BR /&gt;Best regards
&lt;BR /&gt; shong</description>
      <pubDate>Thu, 13 Aug 2009 07:06:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294500#M67369</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-08-13T07:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: [resolved] tLoop with java.util.zip.ZipEntry</title>
      <link>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294501#M67370</link>
      <description>Actually, I made it work with tSetGlobalVariable, tJava, tLoop, tFixedFlowInput, tJavaRow ...
&lt;BR /&gt;So, it is possible to unzip on the fly. Just set 1 global ZipFile, 1 global ZipEntry array and a counter and it works.</description>
      <pubDate>Thu, 13 Aug 2009 13:07:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/resolved-tLoop-with-java-util-zip-ZipEntry/m-p/2294501#M67370</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-08-13T13:07:32Z</dc:date>
    </item>
  </channel>
</rss>

