Here you can find the source of getInputStream(File tarFile)
Parameter | Description |
---|---|
IllegalArgumentException | if tarFile has an unrecognized extension |
IOException | if an I/O problem occurs |
private static InputStream getInputStream(File tarFile) throws IllegalArgumentException, IOException
//package com.java2s; /*/*from w w w . ja v a 2 s. c o m*/ Copyright ? 2008 Brent Boyer This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public License for more details. You should have received a copy of the Lesser GNU General Public License along with this program (see the license directory in this project). If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.zip.GZIPInputStream; public class Main { /** * If tarFile's extension is simply tar, then returns a new FileInputStream. * Else if tarFile's extension is tar.gz or tgz, then returns a new GZIPnputStream wrapping a new FileInputStream. * <p> * Note: the result is never buffered, since the TarArchiveInputStream which will use the result always has an internal buffer. * <p> * @throws IllegalArgumentException if tarFile has an unrecognized extension * @throws IOException if an I/O problem occurs * @see <a href="http://www.gzip.org/">gzip home page</a> * @see <a href="http://www.brouhaha.com/~eric/tgz.html">.tar.gz file format FAQ</a> */ private static InputStream getInputStream(File tarFile) throws IllegalArgumentException, IOException { String name = tarFile.getName().toLowerCase(); if (name.endsWith(".tar")) { return new FileInputStream(tarFile); } else if (name.endsWith(".tar.gz") || name.endsWith(".tgz")) { return new GZIPInputStream(new FileInputStream(tarFile)); } else { throw new IllegalArgumentException( "tarFile = " + tarFile.getPath() + " has an invalid extension for a tar or tar/gzip file"); } } }