FileDocCategorySizeDatePackage
Transfer2.javaAPI DocExample3308Thu Jun 27 17:06:32 BST 2002tuning.nio

Transfer2

public class Transfer2 extends Object

Fields Summary
static int
BYTE_SIZE
static float[]
FloatArray
static byte[]
ByteArray
static MyByteArrayOutputStream
Buff
Constructors Summary
Methods Summary
public static voidcreateFloats()

     
  
    for (int i =0; i < FloatArray.length; i++)
      FloatArray[i] = ((float) i)/3.2567F;
  
public static voidmain(java.lang.String[] args)

    createFloats();
    niotest();
    oldtest();
    oldtest2();
    niotest();
    oldtest();
    oldtest2();
    niotest();
    oldtest();
    oldtest2();
    niotest();
    oldtest();
    oldtest2();
  
public static voidniotest()

  
public static voidoldtest()

     
     
  
    System.out.println("Testing iterative write");
    MyByteArrayOutputStream buf = Buff;
    buf.reset();

    long time = System.currentTimeMillis();
    DataOutputStream wrtr = new DataOutputStream(buf);
    wrtr.writeInt(FloatArray.length);
    for (int i = 0; i < FloatArray.length ; i++)
      wrtr.writeFloat(FloatArray[i]);
    wrtr.flush();
    wrtr.close();
    time = System.currentTimeMillis() - time;
    System.out.println("Writing of objects to buffer: " + time);

    InputStream istream = new ByteArrayInputStream(buf.getBuffer());
    System.out.println(" buffer size: " + buf.getBuffer().length);

    time = System.currentTimeMillis();
    DataInputStream rdr = new DataInputStream(istream);
    int len = rdr.readInt();
    float[] allFloats = new float[len];
    for (int i = 0; i < len ; i++)
    {
      allFloats[i] = rdr.readFloat();
    }
    rdr.close();
    time = System.currentTimeMillis() - time;
    System.out.println("Reading of objects from buffer: " + time);
    System.out.println("Reading idx 17: " + allFloats [17]);

    buf = null;
    wrtr = null;
    istream = null;
    rdr = null;
    allFloats = null;
    System.gc();
  
public static voidoldtest2()

    System.out.println("Testing object write");
    MyByteArrayOutputStream buf = Buff;
    buf.reset();

    long time = System.currentTimeMillis();
    ObjectOutputStream wrtr = new ObjectOutputStream(buf);
    wrtr.writeObject(FloatArray);
    wrtr.flush();
    wrtr.close();
    time = System.currentTimeMillis() - time;
    System.out.println("Writing of objects to buffer: " + time);

    InputStream istream = new ByteArrayInputStream(buf.getBuffer());
    System.out.println(" buffer size: " + buf.getBuffer().length);

    time = System.currentTimeMillis();
    ObjectInputStream rdr = new ObjectInputStream(istream);
    float[] allFloats = (float[]) rdr.readObject();
    rdr.close();
    time = System.currentTimeMillis() - time;
    System.out.println("Reading of objects from buffer: " + time);
    System.out.println("Reading idx 17: " + allFloats [17]);

    buf = null;
    wrtr = null;
    istream = null;
    rdr = null;
    allFloats = null;
    System.gc();