JBoss Remoting 3.1.0.Beta1

org.jboss.remoting3.stream
Class Streams

java.lang.Object
  extended by org.jboss.remoting3.stream.Streams

public final class Streams
extends Object

Handy utility methods for stream types.


Method Summary
static
<T> ObjectSink<T>
getCheckedObjectSink(ObjectSink<T> delegate, Class<? extends T> clazz)
          Get an object sink that checks the type of each accepted instance.
static
<C extends Collection<T>,T>
C
getCollection(C newCollection, ObjectSource<T> objectSource)
          Populate a new collection from an object source.
static
<T> ObjectSink<T>
getCollectionObjectSink(Collection<T> target)
          Get an object sink that appends to a collection.
static
<T> ObjectSource<T>
getCollectionObjectSource(Collection<T> collection)
          Get an object source which reads from a collection.
static
<T> ObjectSource<T>
getEnumerationObjectSource(Enumeration<T> enumeration)
          Get an object source that reads from an enumeration.
static
<C extends Collection<T>,T>
org.jboss.xnio.IoFuture<? extends C>
getFutureCollection(Executor executor, C newCollection, ObjectSource<T> objectSource)
          Populate a new collection from an object source asynchronously.
static
<M extends Map<K,V>,K,V>
org.jboss.xnio.IoFuture<? extends M>
getFutureMap(Executor executor, M newMap, ObjectSource<org.jboss.marshalling.Pair<K,V>> objectSource)
          Populate a new map from an object source asynchronously.
static
<T> ObjectSource<T>
getIteratorObjectSource(Iterator<T> iterator)
          Get an object source that reads from an iterator.
static
<M extends Map<K,V>,K,V>
M
getMap(M newMap, ObjectSource<org.jboss.marshalling.Pair<K,V>> objectSource)
          Populate a new map from an object source.
static
<K,V> ObjectSource<org.jboss.marshalling.Pair<K,V>>
getMapEntryIteratorObjectSource(Iterator<Map.Entry<K,V>> iterator)
          Get an object source that reads from an iterator over map entries.
static
<K,V> ObjectSink<org.jboss.marshalling.Pair<K,V>>
getMapObjectSink(Map<K,V> target)
          Get an object sink that appends to a map.
static
<K,V> ObjectSource<org.jboss.marshalling.Pair<K,V>>
getMapObjectSource(Map<K,V> map)
          Get an object source that reads from a map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCollectionObjectSink

public static <T> ObjectSink<T> getCollectionObjectSink(Collection<T> target)
Get an object sink that appends to a collection.

Type Parameters:
T - the collection object type
Parameters:
target - the target collection
Returns:
an object sink

getIteratorObjectSource

public static <T> ObjectSource<T> getIteratorObjectSource(Iterator<T> iterator)
Get an object source that reads from an iterator.

Type Parameters:
T - the iterator object type
Parameters:
iterator - the iterater to read from
Returns:
an object source

getCollectionObjectSource

public static <T> ObjectSource<T> getCollectionObjectSource(Collection<T> collection)
Get an object source which reads from a collection.

Type Parameters:
T - the collection member type
Parameters:
collection - the collection to read from
Returns:
an object source

getMapObjectSink

public static <K,V> ObjectSink<org.jboss.marshalling.Pair<K,V>> getMapObjectSink(Map<K,V> target)
Get an object sink that appends to a map.

Type Parameters:
K - the key type
V - the value type
Parameters:
target - the target map
Returns:
an object sink

getCheckedObjectSink

public static <T> ObjectSink<T> getCheckedObjectSink(ObjectSink<T> delegate,
                                                     Class<? extends T> clazz)
Get an object sink that checks the type of each accepted instance.

Parameters:
delegate - the object sink to delegate to
clazz - the class to check for
Returns:
a checking object sink

getMapEntryIteratorObjectSource

public static <K,V> ObjectSource<org.jboss.marshalling.Pair<K,V>> getMapEntryIteratorObjectSource(Iterator<Map.Entry<K,V>> iterator)
Get an object source that reads from an iterator over map entries.

Type Parameters:
K - the key type
V - the value type
Parameters:
iterator - the iterator object type
Returns:
an object source

getMapObjectSource

public static <K,V> ObjectSource<org.jboss.marshalling.Pair<K,V>> getMapObjectSource(Map<K,V> map)
Get an object source that reads from a map.

Type Parameters:
K - the key type
V - the value type
Parameters:
map - the map
Returns:
an object source

getCollection

public static <C extends Collection<T>,T> C getCollection(C newCollection,
                                                          ObjectSource<T> objectSource)
                                             throws IOException
Populate a new collection from an object source. Since the collection may be only partially populated on error, it is recommended that the instance be discarded if an exception is thrown.

An example usage which meets this requirement would be:

 final List<Foo> fooList = getCollection(new ArrayList<Foo>(), fooSource);
 

Type Parameters:
C - the collection type
T - the collection value type
Parameters:
newCollection - the new collection to populate
objectSource - the object source to fill the collection from
Returns:
the new collection, populated
Throws:
IOException - if an error occurs

getMap

public static <M extends Map<K,V>,K,V> M getMap(M newMap,
                                                ObjectSource<org.jboss.marshalling.Pair<K,V>> objectSource)
                                 throws IOException
Populate a new map from an object source. Since the map may be only partially populated on error, it is recommended that the instance be discarded if an exception is thrown.

An example usage which meets this requirement would be:

 final Map<Foo, Bar> fooBarMap = getMap(new HashMap<Foo, Bar>(), fooBarSource);
 

Type Parameters:
M - the map type
K - the map key type
V - the map value type
Parameters:
newMap - the new map to populate
objectSource - the object source to fill the map from
Returns:
the new map, populated
Throws:
IOException - if an error occurs

getFutureCollection

public static <C extends Collection<T>,T> org.jboss.xnio.IoFuture<? extends C> getFutureCollection(Executor executor,
                                                                                                   C newCollection,
                                                                                                   ObjectSource<T> objectSource)
Populate a new collection from an object source asynchronously. Since the collection may be only partially populated on error, it is recommended that the instance be discarded if an exception is thrown.

An example usage which meets this requirement would be:

 final IoFuture<? extends List<Foo>> futureFooList = getFutureCollection(executor, new ArrayList<Foo>(), fooSource);
 

Type Parameters:
C - the collection type
T - the collection value type
Parameters:
executor - the executor in which to run asynchronous tasks
newCollection - the new collection to populate
objectSource - the object source to fill the collection from
Returns:
the new future collection, populated
Throws:
IOException - if an error occurs

getFutureMap

public static <M extends Map<K,V>,K,V> org.jboss.xnio.IoFuture<? extends M> getFutureMap(Executor executor,
                                                                                         M newMap,
                                                                                         ObjectSource<org.jboss.marshalling.Pair<K,V>> objectSource)
Populate a new map from an object source asynchronously. Since the map may be only partially populated on error, it is recommended that the instance be discarded if an exception is thrown.

An example usage which meets this requirement would be:

 final IoFuture<? extends Map<Foo, Bar>> futureFooBarMap = getFutureMap(executor, new HashMap<Foo, Bar>(), fooBarSource);
 

Type Parameters:
M - the map type
K - the map key type
V - the map value type
Parameters:
newMap - the new map to populate
objectSource - the object source to fill the map from
Returns:
the new map, populated

getEnumerationObjectSource

public static <T> ObjectSource<T> getEnumerationObjectSource(Enumeration<T> enumeration)
Get an object source that reads from an enumeration.

Type Parameters:
T - the enumeration object type
Parameters:
enumeration - the enumeration to read from
Returns:
an object source

JBoss Remoting 3.1.0.Beta1

Copyright © 2010 JBoss, a division of Red Hat, Inc.