Archiver

public interface Archiver

An Archiver is the interface that provide the basic archive operations like:

  • Compress operations
  • Extract operations
  • List operations

Creation Date: 13/11/2006

Author:Twinsen Tsang

Methods

compress

public boolean compress(File src, File dest, boolean includeItself)

Compress the src to dest in the archive form. If the src is a file, then the resulting archive contains only that file. If the src is a directory, then the resulting archive contains all files (recursively) in the src. If the flag includeItself is true , then the src will also include in the archive as the root.

Parameters:
  • src – The source of the file(s) to be archive.
  • dest – The destination of the arhived file.
  • includeItself – the source directory includes in the archive if it is true, vice versa.
Throws:
  • IOException – if any kind of I/O Erros
Returns:

true if the operations run successfully.

compress

public boolean compress(FileSystem src, File dest)

Compress the src to dest in the archive form.

Parameters:
  • src – The source of the file(s) to be archive.
  • dest – The destination of the arhived file.
  • includeItself – the source directory includes in the archive if it is true, vice versa.
Throws:
  • IOException – if any kind of I/O Errors.
Returns:

true if the operations run successfully.

extract

public boolean extract(File archive, File dest)

Extract the archive to the dest directory.

Parameters:
  • archive – The archive to be extract.
  • dest – The destination directory extract to.
Throws:
Returns:

true if the operations run successfully.

extract

public boolean extract(File archive, FileSystem dest)

Extract the archive to the dest directory.

Parameters:
  • archive – The archive to be extract.
  • dest – The destination directory extract to.
Throws:
  • IOException – Any kind of I/O Errors.
Returns:

true if the operations run successfully.

guessCompressedSize

public long guessCompressedSize(File src)

Guess how big is the compressed file without compressing actually.

Parameters:
  • src – The source of the file(s) to be archive.
Throws:
  • NullPointerException – if the src is null.
  • IOException – if one of the file in the folders does not exist in some reason.

guessCompressedSize

public long guessCompressedSize(FileSystem src)

Guess how big is the compressed file without compressing actually.

Parameters:
  • src – The source of the file(s) to be archive.
Throws:
  • NullPointerException – if the src is null.
  • IOException – if one of the file in the folders does not exist in some reason.

isSupportArchive

public boolean isSupportArchive(File archive)

Check whether the archive is supported by this type of archiver. The execution time of this method solely depends on how the archiver structure look like. For example, ArchiverZIP return immediately because it checks only with the extension of the archive file, without the actual content.

Parameters:
  • archive – The archive to be tested.
Returns:

true if the archiver support this archive.

listAsFile

public List listAsFile(File archive)

List the files inside the archive.

Parameters:
  • archive – The archive to be listed.
Throws:
  • IOException – if any kind of I/O Errors.
Returns:

A list of java.io.File object that represents each entry in the archive.

listAsFilename

public List listAsFilename(File archive)

List the files inside the archive.

Parameters:
  • archive – The archive to be listed.
Throws:
  • IOException – Any kind of I/O Errors.
Returns:

A list of String objects that represents the filename of each entry in the archive.