Class AbstractOnDemandInputStream<T extends java.io.OutputStream>
- java.lang.Object
-
- java.io.InputStream
-
- org.jboss.shrinkwrap.impl.base.exporter.AbstractOnDemandInputStream<T>
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
TarBz2OnDemandInputStream,TarGzOnDemandInputStream,TarOnDemandInputStreamBase,ZipOnDemandInputStream
public abstract class AbstractOnDemandInputStream<T extends java.io.OutputStream> extends java.io.InputStreamBase for on-demand input streams. Encodes data on the fly, when read method is executed.
-
-
Field Summary
Fields Modifier and Type Field Description private static intBUFFER_LENGTHNumber of bytes kept in buffer.private java.io.ByteArrayOutputStreambufferedOutputStreamBase for outputStream.private java.io.ByteArrayInputStreambufferInputStreamStream to the buffer.private java.io.InputStreamcurrentNodeStreamStream of currently processed Node.private ArchivePathcurrentPathCurrently processed archive path - for displaying exception.private java.util.Iterator<Node>nodesIteratorIterator over nodes contained in base archive.protected ToutputStreamCreated by abstract method.private booleanoutputStreamClosedIf output stream was closed - we should finish.
-
Constructor Summary
Constructors Constructor Description AbstractOnDemandInputStream(Archive<?> archive)Creates stream directly from archive.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidcloseEntry(T outputStream)Closes the current entry context for the specifiedOutputStream.protected abstract TcreateOutputStream(java.io.OutputStream outputStream)Creates the realOutputStreamto which we'll write, wrapping the provided target.private voiddoCopy()Performs copy operation between currentNodeStream and outputStream using buffer length.private voidendAsset()Close entry in stream.protected abstract voidputNextEntry(T outputStream, java.lang.String context)Writes the next entry (demarcates a new file/folder is to be written).intread()private voidstartAsset(java.lang.String path)Start entry in stream.
-
-
-
Field Detail
-
BUFFER_LENGTH
private static final int BUFFER_LENGTH
Number of bytes kept in buffer.- See Also:
- Constant Field Values
-
nodesIterator
private final java.util.Iterator<Node> nodesIterator
Iterator over nodes contained in base archive.
-
outputStream
protected T extends java.io.OutputStream outputStream
Created by abstract method.
-
bufferedOutputStream
private final java.io.ByteArrayOutputStream bufferedOutputStream
Base for outputStream.
-
currentNodeStream
private java.io.InputStream currentNodeStream
Stream of currently processed Node.
-
bufferInputStream
private java.io.ByteArrayInputStream bufferInputStream
Stream to the buffer.
-
outputStreamClosed
private boolean outputStreamClosed
If output stream was closed - we should finish.
-
currentPath
private ArchivePath currentPath
Currently processed archive path - for displaying exception.
-
-
Constructor Detail
-
AbstractOnDemandInputStream
public AbstractOnDemandInputStream(Archive<?> archive)
Creates stream directly from archive.- Parameters:
archive-
-
-
Method Detail
-
read
public int read() throws java.io.IOException- Specified by:
readin classjava.io.InputStream- Throws:
java.io.IOException
-
doCopy
private void doCopy() throws java.io.IOExceptionPerforms copy operation between currentNodeStream and outputStream using buffer length.- Throws:
java.io.IOException
-
startAsset
private void startAsset(java.lang.String path) throws java.io.IOExceptionStart entry in stream.- Parameters:
path-- Throws:
java.io.IOException
-
endAsset
private void endAsset() throws java.io.IOExceptionClose entry in stream.- Throws:
java.io.IOException
-
createOutputStream
protected abstract T createOutputStream(java.io.OutputStream outputStream) throws java.io.IOException
Creates the realOutputStreamto which we'll write, wrapping the provided target.- Parameters:
outputStream-- Returns:
- Throws:
java.io.IOException- If an error occurred in creating the stream
-
putNextEntry
protected abstract void putNextEntry(T outputStream, java.lang.String context) throws java.io.IOException
Writes the next entry (demarcates a new file/folder is to be written).- Parameters:
outputStream-context-- Throws:
java.io.IOException- If an error occurred writing the entry
-
closeEntry
protected abstract void closeEntry(T outputStream) throws java.io.IOException
Closes the current entry context for the specifiedOutputStream.- Parameters:
outputStream-- Throws:
java.io.IOException
-
-