dk.vajhoej.record
Class Util

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

public class Util
extends java.lang.Object

Utility class to process lists and to work with files instead of byte arrays.


Nested Class Summary
static interface Util.ObjectHandler<T>
          Interface for processing objects read.
static interface Util.Transformer<T1,T2>
          Interface for converting objects read.
 
Constructor Summary
Util()
           
 
Method Summary
static
<T1,T2> byte[]
copyAll(java.lang.Class<T1> t1, byte[] b, java.lang.Class<T2> t2, Util.Transformer<T1,T2> cvt)
          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, Util.Transformer<T1,T2> cvt)
          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)
          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)
          Read array of struct in stream into list of objects.
static
<T> void
readAll(java.lang.Class<T> t, java.io.InputStream is, Util.ObjectHandler<T> oh)
          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)
          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)
          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

Util

public Util()
Method Detail

readAll

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

Parameters:
t - type
b - byte array
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)
                       throws RecordException
Write list of objects into array of struct in byte array. Note: does not work with stucts containing VARSTR fields and STRUCT fields.

Parameters:
t - type
lst - list of objects
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)
                    throws RecordException,
                           java.io.IOException
Read array of struct in stream into list of objects. Note: does not work with stucts containing VARSTR fields and STRUCT fields.

Parameters:
t - type
is - stream
lst - list of objects
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)
                     throws RecordException,
                            java.io.IOException
Write list of objects into array of struct in stream. Note: does not work with stucts containing VARSTR fields and STRUCT fields.

Parameters:
t - type
lst - list of object
os - stream
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,
                               Util.ObjectHandler<T> oh)
                    throws RecordException,
                           java.io.IOException
Read array of struct in stream and processes them by handler. Note: does not work with stucts containing VARSTR fields and STRUCT fields.

Parameters:
t - type
is - stream
oh - handler of objects
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,
                                     Util.Transformer<T1,T2> cvt)
                      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
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,
                                   Util.Transformer<T1,T2> cvt)
                    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
Throws:
RecordException - if problem with record definitions
java.io.IOException - if problem with streams