At 11:36 PM 11/26/99 +0100, Ranieri Argentini
<[EMAIL PROTECTED]> wrote:
>Ok, you lost me here ... my java.io.* or java.lang.* don't seem to have an
>ArrayInputStream class. I'm a using an old version of the JDK or something?
>If so, which one should i get?
ByteArrayInputStream and ByteArrayOutputStream have been around a while,
since Java 1.0.x. I'm sure you don't need a new JDK.
If you have a byte array and want to read it as if it were an input stream,
you create a ByteArrayInputStream, something like this:
byte[] buf;
InputStream is = new ByteArrayInputStream( buf );
If you find some component that sends its data to an output stream and you
really want a byte array, you create a ByteArrayOutputStream and use it to
catch the output. After all the data is written, you can get a byte array,
something like this:
ByteArrayOutputStream os = new ByteArrayOutputStream();
:
byte[] buf = os.getByteArray();
The ByteArrayOutputStream uses a byte array to store its data. When it
fills up its buffer, it creates a bigger array. The old array is garbage
collected eventually. The idiom is something like this:
public void write( byte b ) {
try {
buf[ size ] = b;
size++;
}
catch( ArrayIndexOutOfBoundsException e ) {
byte[] temp = new byte[ size + STEP ];
System.arraycopy( buf, 0, temp, 0, size );
buf = temp;
buf[ size ] = b;
size++;
}
}
_______________________________________________
Kernel maillist - [EMAIL PROTECTED]
http://jos.org/mailman/listinfo/kernel