title: Read the content of CSV files inside a tar.gz archive
body: <p>I want to save the contents of a <strong>tar.gz</strong> archive inside a database table.</p>
  
  <p>The archive contains txt files in <strong>CSV</strong> format. </p>
  
  <p>The idea is to insert a new line in the database for each line in the txt files. </p>
  
  <p>The problem is that I can't read the contents of a file separately then move on to the next file.</p>
  
  <p>Below <em>EntryTable</em> and <em>EntryTableLine</em> are Hibernate entities.</p>
  
  <p><em>EntryTable</em> is in a <em>OneToMany</em> relationship with <em>EntryTableLine</em> (a file -EntryTable- can have many lines -EntryTableLine-).</p>
  
  <pre><code>public static final int TAB = 9;
  
  FileInputStream fileInputStream = new FileInputStream(fileLocation);
  GZIPInputStream gzipInputStream = new GZIPInputStream(fileInputStream);
  TarArchiveInputStream tar = new TarArchiveInputStream(gzipInputStream);
  
  BufferedReader reader = new BufferedReader(new InputStreamReader(tar));
  // Columns are delimited with TAB
  CSVFormat csvFormat = CSVFormat.TDF.withHeader().withDelimeter((char) TAB);
  CSVParser parser = new CSVParser(reader, csvFormat);
  
  TarArchiveEntry tarEntry = tar.getNextTarEntry();
  
  while(tarEntry != null){
    EntryTable entryTable = new EntryTable();
    entryTable.setFilename(tarEntry.getName());
  
    if(reader != null){
  
       // Here is the problem
       for(CSVRecord record : parser){
          //this could have been a StringBuffer
          String line;
          int i = 1;
          for(String val : record){
             line = "&lt;column" + i + "&gt;" + val + "&lt;/column" + i + "&gt;";
          }
  
          EntryTableLine entryTableLine = new EntryTableLine();
          entryTableLine.setContent(line);
          entryDao.saveLine(entryTableLine);
        }
    }
    tarEntry = tar.getNextTarEntry();
  }
  </code></pre>
  
  <p>I tried converting <em>tarEntry.getFile()</em> to <em>InputStream</em>, but <em>tarEntry.getFile()</em> is null unfortunately.</p>
  
  <p>Let's say I have 4 files in the archive. Each file has 3 lines inside. However, in the database, some entries have 5 lines while others have none.</p>
  
  <p>Thank you !</p>