TrueZIP Kernel 7.0-rc1

de.schlichtherle.truezip.socket
Class InputSocket<E extends Entry>

java.lang.Object
  extended by de.schlichtherle.truezip.socket.IOSocket<E,Entry>
      extended by de.schlichtherle.truezip.socket.InputSocket<E>
Type Parameters:
E - the type of the local target for I/O operations.
Direct Known Subclasses:
ByteArrayIOEntry.ByteArrayInputSocket, DecoratingInputSocket, FsArchiveController.Input, IOCache.CacheInputSocket

@NotThreadSafe
public abstract class InputSocket<E extends Entry>
extends IOSocket<E,Entry>

An abstract factory for input streams and read only files for reading bytes from its local target.

Note that the entity relationship between input sockets and output sockets is n:1, i.e. any input socket can have at most one peer output socket, but it may be the peer of many other output sockets.

Author:
Christian Schlichtherle
See Also:
OutputSocket

Field Summary
private  OutputSocket<?> peer
           
 
Constructor Summary
InputSocket()
           
 
Method Summary
 InputSocket<E> bind(InputSocket<?> to)
          Binds the peer target of the given socket to this socket.
(package private)  InputSocket<E> connect(OutputSocket<?> newPeer)
          Connects this input socket to the given peer output socket.
 Entry getPeerTarget()
          Returns the peer target for I/O operations.
 InputStream newInputStream()
          Returns a new input stream for reading bytes from the local target.
abstract  ReadOnlyFile newReadOnlyFile()
          Optional: Returns a new read only file for reading bytes from the local target in arbitrary order.
 
Methods inherited from class de.schlichtherle.truezip.socket.IOSocket
copy, equals, getLocalTarget, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

peer

@CheckForNull
private OutputSocket<?> peer
Constructor Detail

InputSocket

public InputSocket()
Method Detail

getPeerTarget

@Nullable
public Entry getPeerTarget()
                    throws IOException
Returns the peer target for I/O operations.

The same considerations as for IOSocket.getLocalTarget() apply here, too.

The peer target is null if and only if this socket is not connect(de.schlichtherle.truezip.socket.OutputSocket)ed to another socket.

Specified by:
getPeerTarget in class IOSocket<E extends Entry,Entry>
Returns:
The peer target for I/O operations.
Throws:
IOException

bind

@NonNull
public final InputSocket<E> bind(@CheckForNull
                                         InputSocket<?> to)
Binds the peer target of the given socket to this socket. Note that this method does not change the state of the given socket and does not connect this socket to the peer socket, i.e. it does not set this socket as the peer of of the given socket.

Parameters:
to - the input socket which has a peer target to share.
Returns:
this

connect

@NonNull
final InputSocket<E> connect(@CheckForNull
                                     OutputSocket<?> newPeer)
Connects this input socket to the given peer output socket. Note that this method changes the peer input socket of the given peer output socket to this instance.

Parameters:
newPeer - the nullable peer output socket to connect to.
Returns:
This input socket.

newReadOnlyFile

@NonNull
public abstract ReadOnlyFile newReadOnlyFile()
                                      throws IOException
Optional: Returns a new read only file for reading bytes from the local target in arbitrary order.

If this method is supported, implementations must enable calling it any number of times. Furthermore, the returned read only file should not be buffered. Buffering should be addressed by client applications instead.

Returns:
A new read only file.
Throws:
UnsupportedOperationException - if this operation is not supported by the implementation.
FileNotFoundException - if the local target does not exist or is not accessible for some reason.
IOException - on any other exceptional condition.

newInputStream

@NonNull
public InputStream newInputStream()
                           throws IOException
Returns a new input stream for reading bytes from the local target.

Implementations must enable calling this method any number of times. Furthermore, the returned input stream should not be buffered. Buffering should be addressed by the caller instead - see IOSocket.copy(de.schlichtherle.truezip.socket.InputSocket, de.schlichtherle.truezip.socket.OutputSocket).

The implementation in the class InputSocket calls newReadOnlyFile() and wraps the resulting object in a new ReadOnlyFileInputStream as an adapter.

Returns:
A new input stream.
Throws:
FileNotFoundException - if the local target does not exist or is not accessible for some reason.
IOException - on any other exceptional condition.

TrueZIP Kernel 7.0-rc1

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.