Re: Zipping multiple BLOBs
cdef wrote:
and correct me if I'm wrong, is that each time the Java procedure is
called I should be able to determine the array count of the
destination BLOB and pick up at the end and append more zip entries. I
have tried to do exactly this with something like "int z_length =
dstBlob.length();" or "int z_length = getLength(dstBlob);". My problem
is that I don't know 1) which one returns the array count vs the BLOB
size 2) how to use the z_length value once I've obtained it. If I try
"dstBlob[z_length].setBinaryStream(0);" I get a
java.lang.ArrayIndexOutOfBoundsException exception.
Before getting to your question, let me suggest strongly that you please do
not use TABs to indent Usenet listings. Using a maximum of four space
characters per indent level to keep your listings readable.
Now to your question. First, why do you use 'oracle.sql.BLOB' and not a
standard type?
public static void zipBlob(
oracle.sql.BLOB srcBlob, oracle.sql.BLOB dstBlob[], String name )
Second, don't give code examples as "something like ...". Give copied and
pasted *exact* code that you tried, as an SSCCE.
<http://sscce.com/>
Third, the "something like ..." code you describe won't compile. Arrays in
Java do not have a 'length()' method, and you don't show the 'getLength( BLOB
)' method to which you refer, so I can't speak to that. Arrays in Java have a
'length' attribute, thus 'someArray.length'. This is very basic Java.
Fourth, the "something like ..." code you describe will throw an
'ArrayIndexOutOfBoundsException' once you fix the compilation problems, as
you've seen. Assuming you set 'z_length' (a name that violates the Java
coding conventions, which call for camel case and no underscores in
non-constant variable names) from the array 'length' attribute, it cannot be
used as an array index for the same array. Arrays in Java do not change size,
and the maximum index of an array is one less than its length. Trying to
reference array element 'zLength' (to correct your name) uses an index that is
out of bounds.
Fifth, if you want to add to an array, you need to create a longer array and
copy the 'zLength' elements of the old array into the first 'zLength' elements
of the new array. Make sure the new array is long enough to handle all the
new elements you want to add (maximum index "length minus one").
For a self-growing array-like structure use a 'java.util.List' instead of an
array. The 'java.util.ArrayList' is closest to a regular array and simplest
of the 'List' implementations.
Have you read the Java tutorials on java.sun.com? If not, you must. They
contain answers to some of the questions you asked.
--
Lew