Definition at line 14 of file DBBlob2Array.java.
Static Public Member Functions | |
Vector< Integer > | getInteger (Blob blob) throws SQLException |
byte[] | byteMe (Vector< Integer > intArray) |
byte[] | byteMe (Object obj) |
Object | convert (Blob blob, Class cl) throws SQLException |
|
Returns a byte array from any object. Only implemented Vector<Integer> at the moment Definition at line 88 of file DBBlob2Array.java. 00088 { 00089 return(byteMe( (Vector<Integer>)obj )); 00090 }
|
|
Returns a byte array from a vector of integers Definition at line 64 of file DBBlob2Array.java. 00064 { 00065 00066 byte byteArray[] = new byte[intArray.size()*4]; 00067 00068 int kk=0; 00069 00070 for(int ii=0; ii!= intArray.size(); ++ii){ 00071 int anInt = intArray.get(ii); 00072 for(int jj=0; jj!=4; ++jj){ 00073 byteArray[kk] = (new Integer(anInt)).byteValue(); 00074 anInt>>=8; 00075 ++kk; 00076 } 00077 } 00078 00079 return(byteArray); 00080 }
|
|
Convert a blob into an object of the given class. only implemented Vector<Integer> at present
Definition at line 102 of file DBBlob2Array.java. 00103 { 00104 00105 if(cl.equals(Vector.class)){ 00106 return(getInteger(blob)); 00107 }else if (cl.equals(Blob.class)){ 00108 return(blob); 00109 }else{ 00110 00111 System.out.println("Can only convert Blobs to vectors and blobs"); 00112 System.out.println("you attempted to convert a blob to a "+ 00113 cl.getName()); 00114 00115 return(null); 00116 } 00117 }
|
|
Returns a vector of Integers from a blob Definition at line 19 of file DBBlob2Array.java. 00020 { 00021 00022 Vector<Integer> column = null; 00023 00024 if(blob==null)return column; 00025 00026 byte theBytes[] = blob.getBytes((long)1, (int)blob.length()); 00027 00028 column = new Vector<Integer>(); 00029 00030 //check that we have a multiple of 4 bytes for turning into Ints 00031 //If not, discard the leftover bytes. 00032 00033 int numInts = theBytes.length / 4; 00034 numInts *=4; 00035 for(int ii=0; ii< numInts; ii+=4){ 00036 int anInt = 0; 00037 for(int jj=0; jj!=4; ++jj){ 00038 00039 int piece = (int)theBytes[ii+jj]; 00040 00041 //System.out.println(piece); 00042 00043 //casting thinks it should be a signed int 00044 if(piece<0&&jj!=3) { 00045 piece+=256; 00046 } 00047 00048 piece<<=8*jj; 00049 00050 //System.out.println(piece); 00051 00052 anInt+=piece; 00053 } 00054 column.add(anInt); 00055 } 00056 00057 return(column); 00058 }
|
Generated Wed Jan 17 09:14:27 GMT 2007