TrueZIP Kernel 7.0-rc1

de.schlichtherle.truezip.socket
Class IOSocket<LT,PT>

java.lang.Object
  extended by de.schlichtherle.truezip.socket.IOSocket<LT,PT>
Type Parameters:
LT - the type of the local target for I/O operations.
PT - the type of the peer target for I/O operations.
Direct Known Subclasses:
InputSocket, OutputSocket

@ThreadSafe
public abstract class IOSocket<LT,PT>
extends Object

An abstract address of a target for I/O operations which is provided by sub class implementations.

A key feature of an I/O socket is that it's targets can be resolved lazily, i.e. the local or peer target may get resolved by a method of a sub class.

Author:
Christian Schlichtherle

Constructor Summary
IOSocket()
          You cannot instantiate this class outside its package.
 
Method Summary
static void copy(InputSocket<?> input, OutputSocket<?> output)
          Copies an input stream created by the given input socket input to an output stream created by the given output socket output.
 boolean equals(Object that)
          Two sockets are considered equal if and only if they are identical.
abstract  LT getLocalTarget()
          Returns the local target for I/O operations.
abstract  PT getPeerTarget()
          Returns the peer target for I/O operations.
 int hashCode()
          Returns a hash code which is consistent with equals(java.lang.Object).
 String toString()
          Returns a string representing a connection of the local and peer targets.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IOSocket

IOSocket()
You cannot instantiate this class outside its package.

Method Detail

getLocalTarget

@NonNull
public abstract LT getLocalTarget()
                           throws IOException
Returns the local target for I/O operations.

Note that this interface contract does not state any other terms or conditions for the returned object. In particular, clients need to consider that multiple invocations of this method could return different objects (e.g. defensive copies) which may even fail the Object.equals(java.lang.Object) test. On the other hand, implementations need to consider that clients could attempt to change the state of the returned object in arbitrary manner. Consequently, the result of doing so is undefined, too. In particular, a subsequent I/O operation may not reflect the change or may even fail. Sub-interfaces or implementations may add additional terms and conditions in order to resolve these potential issues.

Returns:
The local target for I/O operations.
Throws:
IOException

getPeerTarget

@CheckForNull
public abstract PT getPeerTarget()
                          throws IOException
Returns the peer target for I/O operations.

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

Returns:
The peer target for I/O operations.
Throws:
IOException

copy

public static void copy(@NonNull
                        InputSocket<?> input,
                        @NonNull
                        OutputSocket<?> output)
                 throws IOException
Copies an input stream created by the given input socket input to an output stream created by the given output socket output.

Parameters:
input - an input socket for the input target.
output - an output socket for the output target.
Throws:
InputException - if copying the data fails because of an IOException thrown by the input stream.
IOException - if copying the data fails because of an IOException thrown by the output stream.
NullPointerException - if any parameter is null.

toString

@NonNull
public String toString()
Returns a string representing a connection of the local and peer targets.

Overrides:
toString in class Object

equals

public final boolean equals(@CheckForNull
                            Object that)
Two sockets are considered equal if and only if they are identical. This can't get overriden.

Overrides:
equals in class Object

hashCode

public final int hashCode()
Returns a hash code which is consistent with equals(java.lang.Object). This can't get overriden.

Overrides:
hashCode in class Object

TrueZIP Kernel 7.0-rc1

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