com.izforge.izpack.installer.unpacker
Class FileUnpacker

java.lang.Object
  extended by com.izforge.izpack.installer.unpacker.FileUnpacker
Direct Known Subclasses:
CompressedFileUnpacker, DefaultFileUnpacker, LooseFileUnpacker, MultiVolumeFileUnpacker

public abstract class FileUnpacker
extends Object

Unpacks a file from a pack.

This manages queueing files that are blocked.

Author:
Tim Anderson

Constructor Summary
FileUnpacker(Cancellable cancellable, FileQueue queue)
          Constructs a FileUnpacker.
 
Method Summary
protected  long copy(PackFile file, byte[] buffer, InputStream in, OutputStream out, long bytesCopied)
          Copies from the input stream to the output stream.
protected  long copy(PackFile file, InputStream in, File target)
          Copies an input stream to a target, setting its timestamp to that of the pack file.
protected  OutputStream getTarget(PackFile file, File target)
          Returns a stream to the target file.
 boolean isQueued()
          Determines if the file was queued.
protected  void postCopy(PackFile file)
          Invoked after copying is complete to set the last modified timestamp, and queue blockable files.
protected  int read(byte[] buffer, InputStream in, int maxBytes)
          Reads up to maxBytes bytes to the specified buffer.
protected  void setLastModified(PackFile file)
          Sets the last-modified timestamp of a file from the pack-file meta-data.
abstract  void unpack(PackFile file, InputStream packInputStream, File target)
          Unpacks a pack file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUnpacker

public FileUnpacker(Cancellable cancellable,
                    FileQueue queue)
Constructs a FileUnpacker.

Parameters:
cancellable - determines if unpacking should be cancelled
queue - the file queue. May be null
Method Detail

unpack

public abstract void unpack(PackFile file,
                            InputStream packInputStream,
                            File target)
                     throws IOException,
                            InstallerException
Unpacks a pack file.

Parameters:
file - the pack file meta-data
packInputStream - the pack input stream
target - the target
Throws:
IOException - for any I/O error
InstallerException - for any installer exception

isQueued

public boolean isQueued()
Determines if the file was queued.

Returns:
true if the file was queued

copy

protected long copy(PackFile file,
                    InputStream in,
                    File target)
             throws IOException
Copies an input stream to a target, setting its timestamp to that of the pack file.

If the target is a blockable file, then a temporary file will be created, and the file queued.

Parameters:
file - the pack file
in - the pack file stream
target - the file to write to
Returns:
the number of bytes actually copied
Throws:
InterruptedIOException - if the copy operation is cancelled
IOException - for any I/O error

postCopy

protected void postCopy(PackFile file)
Invoked after copying is complete to set the last modified timestamp, and queue blockable files.

Parameters:
file - the pack file meta-data

copy

protected long copy(PackFile file,
                    byte[] buffer,
                    InputStream in,
                    OutputStream out,
                    long bytesCopied)
             throws IOException
Copies from the input stream to the output stream.

Parameters:
file - the pack file
buffer - the buffer to use
in - the stream to read from
out - the stream to write to
bytesCopied - the current no. of bytes copied
Returns:
the number of bytes actually copied
Throws:
IOException - for any I/O error

read

protected int read(byte[] buffer,
                   InputStream in,
                   int maxBytes)
            throws IOException
Reads up to maxBytes bytes to the specified buffer.

Parameters:
buffer - the buffer
in - the input stream
maxBytes - the maximum no. of bytes to read
Returns:
the no. of bytes read
Throws:
IOException - for any I/O error

getTarget

protected OutputStream getTarget(PackFile file,
                                 File target)
                          throws IOException
Returns a stream to the target file.

If the target file is blockable, then a temporary file will be created, and a stream to this returned instead.

Parameters:
file - the pack file meta-data
target - the requested target
Returns:
a stream to the actual target
Throws:
IOException - an I/O error occurred

setLastModified

protected void setLastModified(PackFile file)
Sets the last-modified timestamp of a file from the pack-file meta-data.

Parameters:
file - the pack file meta-data


Copyright © 2018. All rights reserved.