本文整理匯總了Java中org.apache.commons.compress.archivers.ArchiveInputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java ArchiveInputStream.close方法的具體用法?Java ArchiveInputStream.close怎麽用?Java ArchiveInputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.compress.archivers.ArchiveInputStream
的用法示例。
在下文中一共展示了ArchiveInputStream.close方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeOnlyUnZip
import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
public static void makeOnlyUnZip() throws ArchiveException, IOException{
final InputStream is = new FileInputStream("D:/中文名字.zip");
ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
ZipArchiveEntry entry = entry = (ZipArchiveEntry) in.getNextEntry();
String dir = "D:/cnname";
File filedir = new File(dir);
if(!filedir.exists()){
filedir.mkdir();
}
// OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
OutputStream out = new FileOutputStream(new File(filedir, entry.getName()));
IOUtils.copy(in, out);
out.close();
in.close();
}
示例2: testApache
import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
public void testApache() throws IOException, ArchiveException {
log.debug("testApache()");
File zip = File.createTempFile("apache_", ".zip");
// Create zip
FileOutputStream fos = new FileOutputStream(zip);
ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream("zip", fos);
aos.putArchiveEntry(new ZipArchiveEntry("coñeta"));
aos.closeArchiveEntry();
aos.close();
// Read zip
FileInputStream fis = new FileInputStream(zip);
ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream("zip", fis);
ZipArchiveEntry zae = (ZipArchiveEntry) ais.getNextEntry();
assertEquals(zae.getName(), "coñeta");
ais.close();
}
示例3: unarchive
import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
private static List<File> unarchive(File inputFile, File outputDir)
throws Throwable {
InputStream is = new BufferedInputStream(new FileInputStream(inputFile));
ArchiveInputStream ais = null;
List<File> ofs = new ArrayList<File>();
try {
ais = new ArchiveStreamFactory().createArchiveInputStream(is);
ArchiveEntry ae = ais.getNextEntry();
while (ae != null) {
if (!ae.isDirectory()) {
File of = new File(outputDir, ae.getName());
OutputStream os = new FileOutputStream(of);
try {
IOUtils.copy(ais, os);
} finally {
os.close();
}
ofs.add(of);
}
ae = ais.getNextEntry();
}
} catch (Throwable e) {
// failed to extract
} finally {
is.close();
if (ais != null) {
ais.close();
}
}
if (ofs.isEmpty()) {
return null;
} else {
return ofs;
}
}
示例4: extract
import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
/**
* Extract the file and create directories accordingly.
*
* @param is pass the stream, because the stream is different for various file types
* @param targetDir target directory
* @throws IOException
*/
private static void extract(ArchiveInputStream is, File targetDir) throws IOException {
try {
if (targetDir.exists()) {
FileUtils.forceDelete(targetDir);
}
createDirectory(targetDir);
ArchiveEntry entry = is.getNextEntry();
while (entry != null) {
String name = entry.getName();
name = name.substring(name.indexOf("/") + 1);
File file = new File(targetDir, name);
if (entry.isDirectory()) {
createDirectory(file);
} else {
createDirectory(file.getParentFile());
OutputStream os = new FileOutputStream(file);
try {
IOUtils.copy(is, os);
} finally {
IOUtils.closeQuietly(os);
}
}
entry = is.getNextEntry();
}
} finally {
try {
is.close();
} catch (IOException e) {
logger.warn("Error occurred while closing the stream", e);
}
}
}
示例5: read_rpm
import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
private List<JavaClass> read_rpm(File rpm) throws IOException,
InterruptedException {
ArchiveInputStream rpm_is = new RpmArchiveInputStream(rpm);
ArchiveEntry rpm_ent;
List<JavaClass> list = new ArrayList<JavaClass>();
while ((rpm_ent = rpm_is.getNextEntry()) != null) {
if (rpm_ent.isDirectory() || !rpm_ent.getName().endsWith(".jar"))
continue;
list.addAll(read_jar(rpm_is));
}
rpm_is.close();
return list;
}
示例6: extract
import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
private void extract(ArchiveInputStream is, File targetDir) throws IOException {
try {
if (targetDir.exists()) {
FileUtils.forceDelete(targetDir);
}
targetDir.mkdirs();
ArchiveEntry entry = is.getNextEntry();
while (entry != null) {
String name = entry.getName();
name = name.substring(name.indexOf("/") + 1);
File file = new File(targetDir, name);
if (entry.isDirectory()) {
file.mkdirs();
} else {
file.getParentFile().mkdirs();
OutputStream os = new FileOutputStream(file);
try {
IOUtils.copy(is, os);
} finally {
IOUtils.closeQuietly(os);
}
}
entry = is.getNextEntry();
}
} finally {
is.close();
}
}
示例7: unCompress
import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
public static void unCompress (String zip_file, String output_folder)
throws IOException, CompressorException, ArchiveException
{
ArchiveInputStream ais = null;
ArchiveStreamFactory asf = new ArchiveStreamFactory ();
FileInputStream fis = new FileInputStream (new File (zip_file));
if (zip_file.toLowerCase ().endsWith (".tar"))
{
ais = asf.createArchiveInputStream (
ArchiveStreamFactory.TAR, fis);
}
else if (zip_file.toLowerCase ().endsWith (".zip"))
{
ais = asf.createArchiveInputStream (
ArchiveStreamFactory.ZIP, fis);
}
else if (zip_file.toLowerCase ().endsWith (".tgz") ||
zip_file.toLowerCase ().endsWith (".tar.gz"))
{
CompressorInputStream cis = new CompressorStreamFactory ().
createCompressorInputStream (CompressorStreamFactory.GZIP, fis);
ais = asf.createArchiveInputStream (new BufferedInputStream (cis));
}
else
{
try
{
fis.close ();
}
catch (IOException e)
{
LOGGER.warn ("Cannot close FileInputStream:", e);
}
throw new IllegalArgumentException (
"Format not supported: " + zip_file);
}
File output_file = new File (output_folder);
if (!output_file.exists ()) output_file.mkdirs ();
// copy the existing entries
ArchiveEntry nextEntry;
while ((nextEntry = ais.getNextEntry ()) != null)
{
File ftemp = new File (output_folder, nextEntry.getName ());
if (nextEntry.isDirectory ())
{
ftemp.mkdir ();
}
else
{
FileOutputStream fos = FileUtils.openOutputStream (ftemp);
IOUtils.copy (ais, fos);
fos.close ();
}
}
ais.close ();
fis.close ();
}
示例8: decompress
import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
static void decompress(File inputFile, File outputDir) throws IOException {
log.log(LogLevel.DEBUG, "Decompressing '" + inputFile + "' into '" + outputDir + "'");
ArchiveInputStream ais = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(inputFile)));
decompress(ais, outputDir);
ais.close();
}
示例9: extract
import org.apache.commons.compress.archivers.ArchiveInputStream; //導入方法依賴的package包/類
protected void extract(ArchiveInputStream arcInStream) throws IOException {
ArchiveEntry entry = null;
/** Read the tar entries using the getNextEntry method **/
while ((entry = (ArchiveEntry) arcInStream.getNextEntry()) != null) {
System.out.println("Extracting: " + entry.getName());
/** If the entry is a directory, create the directory. **/
if (entry.isDirectory()) {
File f = new File(getDestDirectory()
+ SystemUtils.FILE_SEPARATOR + entry.getName());
f.mkdirs();
}
/**
* If the entry is a file,write the decompressed file to the disk
* and close destination stream.
**/
else {
int count;
byte data[] = new byte[BUFFER];
FileOutputStream fos = new FileOutputStream(getDestDirectory()
+ SystemUtils.FILE_SEPARATOR + entry.getName());
BufferedOutputStream dest = new BufferedOutputStream(fos,
BUFFER);
while ((count = arcInStream.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count);
}
dest.close();
}
}
/** Close the input stream **/
arcInStream.close();
System.out.println("untar completed successfully!!");
}