ArchiverTar

public class ArchiverTar extends ArchiverNULL
Author:Patrick Yip

Fields

TAR_ENTRY_SIZE

public static int TAR_ENTRY_SIZE

Methods

compress

public boolean compress(List<File> src, File dest, boolean includeItself)

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. The src file sets will be archived to TAR format which is comes from Apache Ant Tools Tar. For more details, read Apache Ant Tool Tar

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.

See also: hk.hku.cecid.edi.sfrm.archive.Archiver.compress(File,File,boolean)

compress

public boolean compress(FileSystem src, File dest)

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. The algorithm of guessing the tar size as follow: For each of file Each header size is TAR_ENTRY_SIZE bytes, and for the data content block. It use TAR_ENTRY_SIZE as a block of data. If for last block of data is not TAR_ENTRY_SIZE, then the rest will padding with the empty bytes. Such that the final guessed size is ceil((file_length/TAR_ENTRY_SIZE)+1)*TAR_ENTRY_SIZE. More details of tar file format can found from this.

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.
Returns:

guessed file size in byte

guessCompressedSize

public long guessCompressedSize(FileSystem src)

isSupportArchive

public boolean isSupportArchive(File archive)

listAsFile

public List listAsFile(File archive)

List the files inside the archive. This operation is quite slow and pending to optimize.

Parameters:
  • archive – The archive to be listed.
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.
Returns:

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