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.InputStream
Base 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 int
BUFFER_LENGTH
Number of bytes kept in buffer.private java.io.ByteArrayOutputStream
bufferedOutputStream
Base for outputStream.private java.io.ByteArrayInputStream
bufferInputStream
Stream to the buffer.private java.io.InputStream
currentNodeStream
Stream of currently processed Node.private ArchivePath
currentPath
Currently processed archive path - for displaying exception.private java.util.Iterator<Node>
nodesIterator
Iterator over nodes contained in base archive.protected T
outputStream
Created by abstract method.private boolean
outputStreamClosed
If 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 void
closeEntry(T outputStream)
Closes the current entry context for the specifiedOutputStream
.protected abstract T
createOutputStream(java.io.OutputStream outputStream)
Creates the realOutputStream
to which we'll write, wrapping the provided target.private void
doCopy()
Performs copy operation between currentNodeStream and outputStream using buffer length.private void
endAsset()
Close entry in stream.protected abstract void
putNextEntry(T outputStream, java.lang.String context, Asset asset)
Writes the next entry (demarcates a new file/folder is to be written).int
read()
private void
startAsset(java.lang.String path, Asset asset)
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:
read
in classjava.io.InputStream
- Throws:
java.io.IOException
-
doCopy
private void doCopy() throws java.io.IOException
Performs copy operation between currentNodeStream and outputStream using buffer length.- Throws:
java.io.IOException
-
startAsset
private void startAsset(java.lang.String path, Asset asset) throws java.io.IOException
Start entry in stream.- Parameters:
path
-- Throws:
java.io.IOException
-
endAsset
private void endAsset() throws java.io.IOException
Close entry in stream.- Throws:
java.io.IOException
-
createOutputStream
protected abstract T createOutputStream(java.io.OutputStream outputStream) throws java.io.IOException
Creates the realOutputStream
to 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, Asset asset) 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
-
-