TrueZIP Kernel 7.0-rc2

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

java.lang.Object
  extended by de.schlichtherle.truezip.socket.IOSocket<E,Entry>
      extended by de.schlichtherle.truezip.socket.OutputSocket<E>
Type Parameters:
E - the type of the local target for I/O operations.
Direct Known Subclasses:
ByteArrayIOEntry.ByteArrayOutputSocket, DecoratingOutputSocket, FsArchiveController.Output, IOCache.CacheOutputSocket

@NotThreadSafe
@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public abstract class OutputSocket<E extends Entry>
extends IOSocket<E,Entry>

An abstract factory for output streams for writing bytes to its local target.

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

Author:
Christian Schlichtherle
See Also:
InputSocket

Field Summary
private  InputSocket<?> peer
           
 
Constructor Summary
OutputSocket()
           
 
Method Summary
 OutputSocket<E> bind(OutputSocket<?> to)
          Binds the peer target of the given socket to this socket.
(package private)  OutputSocket<E> connect(InputSocket<?> newPeer)
          Connects this output socket to the given peer input socket.
 Entry getPeerTarget()
          Returns the peer target for I/O operations.
abstract  OutputStream newOutputStream()
          Returns a new output stream for writing bytes to the local target.
 
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 InputSocket<?> peer
Constructor Detail

OutputSocket

public OutputSocket()
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.InputSocket)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

public final OutputSocket<E> bind(@CheckForNull
                                  OutputSocket<?> 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 output socket which has a peer target to share.
Returns:
this

connect

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

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

newOutputStream

public abstract OutputStream newOutputStream()
                                      throws IOException
Returns a new output stream for writing bytes to the local target.

Implementations must enable calling this method any number of times. Furthermore, the returned output 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).

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

TrueZIP Kernel 7.0-rc2

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