Java: defer to bytes []

How can I read java.sql.Clob in bytes []?

+3
source share
3 answers

with commons-io

byte[] data = IOUtils.toByteArray(clob.getAsciiStream());
+5
source
int length = clob.getLength();         
 byte[] array = new byte[length];       
 InputStream in = clob.getAsciiStream();       
 int offset = 0;        
 int n;        
 do      
    n = in.read(array, offset, length - offset);        
 while (n != -1);

Try the code snippet above to read the clob into a byte array.

+2
source

Get the ASCII stream, and then read from the stream into an array of bytes. http://download.oracle.com/javase/1.4.2/docs/api/java/sql/Clob.html#getAsciiStream ()

+1
source

Source: https://habr.com/ru/post/1794433/


All Articles