Database Management and Java

By Art Sulger

Dr. Dobb's Journal May 1997

ByteArrayOutputStream bo = new ByteArrayOutputStream(4);
DataOutputStream d1 = new DataOutputStream(bo); 
d1.writeInt(inInt);
// write integer on byte array 
ByteArrayInputStream bi = new
   ByteArrayInputStream(bo.toByteArray()); 
byte[]b=new byte[4];
bi.read(b,0,4); // read the byte array 
byte[]newB=new byte[4]; // new array for transposing 
newB[0]=b[3];   
newB[1]=b[2]; 
newB[2]=b[1];
newB[3]=b[0]; 
ByteArrayInputStream newBi = new
   ByteArrayInputStream(newB); 
DataInputStream di = new
   DataInputStream(newBi);//array to int return di.readInt();

Example 6: Moving the bytes of an integer.

Back to Article


Copyright © 1997, Dr. Dobb's Journal