dk.vajhoej.record
Class Util2

java.lang.Object
  extended by dk.vajhoej.record.Util2

public class Util2
extends java.lang.Object

Utility class to process lists and to work with files instead of byte arrays trying to work even with variable length structs.


Nested Class Summary
static interface Util2.ObjectHandler<T>
          Interface for processing objects read.
static interface Util2.Transformer<T1,T2>
          Interface for converting objects read.
 
Constructor Summary
Util2()
           
 
Method Summary
static
<T1,T2> byte[]
copyAll(java.lang.Class<T1> t1, byte[] b, java.lang.Class<T2> t2, Util2.Transformer<T1,T2> cvt, LengthProvider2 lenpvd)
          Convert array of struct in bytes into array of struct in bytes.
static
<T1,T2> void
copyAll(java.lang.Class<T1> t1, java.io.InputStream is, java.lang.Class<T2> t2, java.io.OutputStream os, Util2.Transformer<T1,T2> cvt, LengthProvider2 lenpvd)
          Convert array of struct in stream into array of struct in stream.
static
<T> java.util.List<T>
readAll(java.lang.Class<T> t, byte[] b, LengthProvider2 lenpvd)
          Read array of struct in byte array into list of objects.
static
<T> void
readAll(java.lang.Class<T> t, java.io.InputStream is, java.util.List<T> lst, LengthProvider2 lenpvd)
          Read array of struct in stream into list of objects.
static
<T> void
readAll(java.lang.Class<T> t, java.io.InputStream is, Util2.ObjectHandler<T> oh, LengthProvider2 lenpvd)
          Read array of struct in stream and processes them by handler.
static
<T> byte[]
writeAll(java.lang.Class<T> t, java.util.List<T> lst, LengthProvider2 lenpvd)
          Write list of objects into array of struct in byte array.
static
<T> void
writeAll(java.lang.Class<T> t, java.util.List<T> lst, java.io.OutputStream os, LengthProvider2 lenpvd)
          Write list of objects into array of struct in stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util2

public Util2()
Method Detail

readAll

public static <T> java.util.List<T> readAll(java.lang.Class<T> t,
                                            byte[] b,
                                            LengthProvider2 lenpvd)
                                 throws RecordException
Read array of struct in byte array into list of objects.

Parameters:
t - type
b - byte array
lenpvd - length provider
Returns:
list of objects
Throws:
RecordException - if problem with record definition

writeAll

public static <T> byte[] writeAll(java.lang.Class<T> t,
                                  java.util.List<T> lst,
                                  LengthProvider2 lenpvd)
                       throws RecordException
Write list of objects into array of struct in byte array.

Parameters:
t - type
lst - list of objects
lenpvd - length provider
Returns:
byte array
Throws:
RecordException - if problem with record definition

readAll

public static <T> void readAll(java.lang.Class<T> t,
                               java.io.InputStream is,
                               java.util.List<T> lst,
                               LengthProvider2 lenpvd)
                    throws RecordException,
                           java.io.IOException
Read array of struct in stream into list of objects.

Parameters:
t - type
is - stream
lst - list of objects
lenpvd - length provider
Throws:
RecordException - if problem with record definition
java.io.IOException - if problem with stream

writeAll

public static <T> void writeAll(java.lang.Class<T> t,
                                java.util.List<T> lst,
                                java.io.OutputStream os,
                                LengthProvider2 lenpvd)
                     throws RecordException,
                            java.io.IOException
Write list of objects into array of struct in stream.

Parameters:
t - type
lst - list of objects
os - stream
lenpvd - length provider
Throws:
RecordException - if problem with record definition
java.io.IOException - if problem with stream

readAll

public static <T> void readAll(java.lang.Class<T> t,
                               java.io.InputStream is,
                               Util2.ObjectHandler<T> oh,
                               LengthProvider2 lenpvd)
                    throws RecordException,
                           java.io.IOException
Read array of struct in stream and processes them by handler.

Parameters:
t - type
is - stream
oh - handler of objects
lenpvd - length provider
Throws:
RecordException - if problem with record definition
java.io.IOException - if problem with stream

copyAll

public static <T1,T2> byte[] copyAll(java.lang.Class<T1> t1,
                                     byte[] b,
                                     java.lang.Class<T2> t2,
                                     Util2.Transformer<T1,T2> cvt,
                                     LengthProvider2 lenpvd)
                      throws RecordException
Convert array of struct in bytes into array of struct in bytes.

Parameters:
t1 - from type
b - from byte array
t2 - to type
cvt - transformer class
lenpvd - length provider
Returns:
to byte array
Throws:
RecordException - if problem with record definitions

copyAll

public static <T1,T2> void copyAll(java.lang.Class<T1> t1,
                                   java.io.InputStream is,
                                   java.lang.Class<T2> t2,
                                   java.io.OutputStream os,
                                   Util2.Transformer<T1,T2> cvt,
                                   LengthProvider2 lenpvd)
                    throws RecordException,
                           java.io.IOException
Convert array of struct in stream into array of struct in stream.

Parameters:
t1 - from type
is - from stream
t2 - to type
os - to stream
cvt - transformer class
lenpvd - length provider
Throws:
RecordException - if problem with record definitions
java.io.IOException - if problem with streams